DifferentialEquations.jl default options for a solver

In DifferentialEquations.jl, how can I find out the default options for a specific solver? In particular, I’d like to know the default options for the ODE solver DP5. I see a description of options in the docs, but I don’t see what are the defaults.

I’m asking because I’m trying to recapitulate results that I’ve previously calculated in Matlab with the ode45 function, which I believe is the same solver as DP5. The default options in Matlab are documented here.

I find the results in DifferentialEquations.jl do not exactly match Matlab’s ode45 because different time steps are chosen. I’ve attempted to make the time steps the same by setting the same abstol and reltol parameters as in Matlab, but this does not seem sufficient as DifferentialEquation.jl still tends to use less time steps. In some problem instances, I have to set abstol and reltol to be much more sensitive at 1e-8 to more closely match the final solutions generated using only 1e-4 in Matlab, but then the running time becomes slower. I suspect that changing other options like the maximum time step (qmax) in DifferentialEquations.jl may help in equalizing the results.

I am not that familiar with DE.jl but have you tried to pass the Julia implementation the same “collection” of time steps used in MatLab?
The tstops option might be helpfull.

Could you share an example? DifferentialEquations.jl’s DP5 “exactly” (to floating point error because of muladd) matches the time stepping behavior of the classic dopri5 Fortran code. The tests for this can be found here: OrdinaryDiffEq.jl/odeinterface_regression.jl at master · SciML/OrdinaryDiffEq.jl · GitHub .

What about the MATLAB results at 1e-8? They may be different :wink:. To more accurately check the difference in behavior, I suggest constructing a work-precision diagram to directly show accuracy and time at the same time, as in done in the MATLABDiffEq.jl repository GitHub - SciML/MATLABDiffEq.jl: Common interface bindings for the MATLAB ODE solvers via MATLAB.jl for the SciML Scientific Machine Learning ecosystem.

The defaults are either mentioned there, or can always be known by directly looking at the defaults: OrdinaryDiffEq.jl/solve.jl at master · SciML/OrdinaryDiffEq.jl · GitHub

There are two things that are going on. For one, what MATLAB returns to you are not the actual steps. It lies. Well, it doesn’t lie, it is explained in the MATLAB ODE Suite paper https://www.mathworks.com/help/pdf_doc/otherdocs/ode_suite.pdf that the steps of a 5th order method are generally too large, so it would make bad plots. Therefore, a 4th order interpolation is used to fill in 2 intermediate points at 1/3 and 2/3 of the step. If you’re trying to match the stepping behavior of DiffEq to the output behavior of MATLAB, you can see why this is doomed to fail. Nonetheless, DiffEq just returns a continuous solution sol(t) instead, so :man_shrugging: it’s just an API difference here.

The second thing is that MATLAB sets dtmax to be the total time divided by 100, so you’re guaranteed 100 steps. We don’t care if you solve it in 5 steps as long as its to tolerance. So you’d need to change that to match MATLAB more closely.

As the other commenter mentioned, you could just do adaptive=false,tstops=my_times in order to exactly specify all of the dts for the integration. That said, you’ll want to only step to every 3rd timestep of MATLAB’s output of course :stuck_out_tongue:.

Moral of the story, trying to make the time stepping behavior exactly the same between a closed source code and DiffEq is going to be hard because there are a lot of variables going on. We haven’t even mentioned the PI-adaptivity going on yet which could be different, but we cannot know without breaking the license… Instead of benchmarking like this, do it fairly with a work-precision plot:

  1. Generate a reference solution with abstol=reltol=1e-14
  2. Solve both with a range of tolerances, and calculate the error according to some norm against the reference.
  3. Plot time vs error

Then the efficiency is seen by what methods get what times at the same error. When you do that, like is seen in GitHub - SciML/MATLABDiffEq.jl: Common interface bindings for the MATLAB ODE solvers via MATLAB.jl for the SciML Scientific Machine Learning ecosystem, you’ll see between a 10x-100x efficiency difference.