150 points · by one-more-minute · 9y ago · 39 comments
https://github.com/JuliaDiffEq/DiffEqDevTools.jl/blob/master...
This is the kind of thing we imagined experts being able to do when we designed Julia. Having implemented some such solvers in the past, I can safely say this stuff is easily the best out there.
But in all seriousness, the comparison was far more thorough than I expected going in. I learned quite a bit, and it's making me consider giving Julia another shot. I've been tinkering with mostly Rust lately, very happily, but this post makes me miss something with the strong scientific bend of Julia. So job well done and thanks for taking the time to write this.
[1] https://software.intel.com/en-us/articles/intel-ordinary-dif...
tic;
[t, x] = ode15s(
@(t, x) [x(2); ((1 - x(1)^2) * x(2) - x(1)) * 10^6],
[0, 160], [2; 0], odeset('RelTol', 1e-5));
toc;
x(size(x, 1), :)
MATLAB takes 7.2 seconds to output the result [1.872, -0.748].Intel's dodesol_rkm9mkn() gave me [1.877, -0.743], which is a more accurate result, in less than the blink of an eye: in 0.035 seconds.
That's more than 200x faster, by mere virtue of using a better algorithm. Apparently the algorithm is "Merson's method", which I'm completely unfamiliar with and which I'd never heard of until then.
using DifferentialEquations
van = @ode_def_noinvhes VanDerPol2 begin
dy = μ*((1-x^2)*y - x)
dx = 1*y
end μ=>1.
prob = ODEProblem(VanDerPol2(μ=1e6),[0;2.],(0.0,160.0))
solve(prob,CVODE_BDF(),reltol=1/10^5,save_everystep=false)
solve(prob,Rodas5(),reltol=1/10^5,save_everystep=false)
@time sol1 = solve(prob,CVODE_BDF(),reltol=1/10^5,save_everystep=false)
@time sol2 = solve(prob,Rodas5(),reltol=1/10^5,save_everystep=false)
sol3 = solve(prob,CVODE_BDF(),abstol=1/10^10,reltol=1/10^10)
On my laptop I'm getting ~0.1 seconds for both, with Sundials being a little less accurate and OrdinaryDiffEq.jl being a little more accurate against the 10^-10 reference solution than the reported Intel. But "spot checking" like this makes it hard to just timings without issues of more/less error involved, which is why more sophisticated benchmarks use work-precision diagrams. So the timings are in the same ballpark as Intel and I'd assume my (not so fast) laptop doesn't match what you benchmarked with, the point being that MATLAB is just slow here instead of Intel being unbelievably exceptional (though admirable). Still, maybe Intel does pull off some extra efficiency here, but then of course no method is universally good so I wouldn't expect that everywhere. In the end, it's probably a well optimized (probably in the DiffEq.jl/Sundials/FATODE range) single method without event handling or other extra features, but importantly it is abandoned. Probably would've been interesting if development kept up, but without it I think I'm just not going to try to get it installed.Thanks for pointing me to it though. It's definitely an interesting nugget of ODE history that I didn't know existed.
https://github.com/JuliaDiffEq/MATLABDiffEq.jl
So since stiff solvers have a lot more moving parts and thus tend to have even larger differences, 200x is easily explained by just language differences. One way to test this is to instead test the Intel solver against Sundials. I wouldn't be surprised if Sundials actually was faster in this case.
But there's another factor here. I explained in the blog post that multistep methods like BDF tend to do well on asymtopically large problems since they minimize the amount of user-function evaluations, but they don't tend to do well on smaller systems of ODEs. This is exactly that case: you're comparing an implicit RK (Intel) to MATLAB's BDF method, and see that the RK is more accurate and is fast. But this effect of the method choice on small (user-scale) problems is exactly why I emphasized it as a downside when solver suites only include multistep BDF methods as their stiff solvers.
That isn't to say there isn't interesting here. Intel's nonstiff method is a 4th order method that can add extra 1st order stages to boost the stability region, similar to a Runge-Kutta Chevyshev method. I honestly have no idea what this stiff solver is so I bookmarked it to read when I get to a campus where the paper is free:
http://www.sciencedirect.com/science/article/pii/00415553899...
But in general, RKC methods weren't widely adopted because usually using a full non-stiff or stiff solver ends of being better, and picking wildly different methods like this which are not widely known usually isn't a good sign in a very "crowded" field like ODE solvers where generally things are pretty figured out and it's all about the details.
Several groups are working on systems inspired by Modelica, including:
http://tshort.github.io/Sims.jl/latest/
and
https://www.modelica.org/events/modelica2017/proceedings/htm... (https://github.com/ModiaSim/Modia.jl)
> Circuit simulation programs take a text netlist describing the circuit elements (transistors, resistors, capacitors, etc.) and their connections, and translate this description into equations to be solved. The general equations produced are nonlinear differential algebraic equations
https://en.wikipedia.org/wiki/SPICE
All the way down to transistors and other basic elements
> These models are very computer intensive, involving detailed spatial and temporal solutions of coupled partial differential equations on three-dimensional grids inside the device
But then there are "full-stop PDE solvers" which choose a specific PDE and solve that. For example, MATLAB and Mathematica can numerically solve diffusion-advection systems directly. And there are many user packages for different PDEs.
So to cover this fully, I would need to go through the available tools for numerical linear algebra and spatial discretization, but on the other hand cover some full-stop PDE solvers as well. This will be a different blog post. Without knowing your background or what you want to do, FEniCS is a good Python finite element toolbox that can then be used to build the linear equation or system of ODEs, from which you use other tools like those mentioned here to complete the solving. As for full-stop PDE solvers in Python, I am not sure and need to look into it myself...
In this area of numerical computing, the important part is still the user, and the program they use is mostly a matter of what's convenient.
h = min(0.8*h*pow(tol/erinf,0.25),4*h);
That means that the timesteps are changes via Cechino's optimality theorem, the "standard" timestepping method which isn't actually used in production quality solvers. The reason is because this form of adaptivity causes solvers to change their h too rapidly, which actually decreases the stability region and increases the number of step rejections. So all of the other explicit RK solvers mentioned (except when I single it out) all use a PI-controller. And this makes a pretty big difference: I've found something like a 10x performance change by using a PI-controller on many equations, and then there's many other equations where at a "simple" tolerance like reltol=10^-3 the dopri-type method will diverge without a PI-controller on the timesteps. But it does have event handling and dense output. However, since it's lacking any solvers for stiff ODEs, I am not sure it really is a full suite.Some time ago I was trying to make a 'hpq-FEM' using rational functions as a basis, like a Padé approximation. Do you know if anyone has tried something similar?