3
$\begingroup$

With scipy, I have the choice of using "lsoda":

Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient implementation. It provides automatic method switching between implicit Adams method (for non-stiff problems) and a method based on backward differentiation formulas (BDF) (for stiff problems).

or "dopri5", which Wikipedia tells me is a non-stiff method that is the default choice of MATLAB's ode45.

What are some general heuristics for using "lsoda" vs. "dopri5"?

I suppose an obvious one consideration: "is your problem stiff?". Well, if the problem I am working with is stiff, then "lsoda" is struggling with "Excess work done." too...so, the BDF method doesn't seem to help too much with stiffness.

Can you share some insight?

$\endgroup$
4
$\begingroup$

What are some general heuristics for using "lsoda" vs. "dopri5"?

I suppose an obvious one consideration: "is your problem stiff?". Well, if the problem I am working with is stiff, then "lsoda" is struggling with "Excess work done." too...so, the BDF method doesn't seem to help too much with stiffness.

If forced to choose between only those two implementations, "Is your problem stiff?" is going to be the most important question, followed by more subtle discussions of work-precision tradeoffs. You really would need to construct a work-precision diagram, or you would need to say something about your application. What follows are some speculative scenarios that might explain what you would see:

  • If your problem is "moderately" or "mildly" stiff, it could still be worth using LSODE instead of DOPRI5 because you might be able to take significantly larger time steps than DOPRI5, and the cost of the linear solves required could be cheaper than the many function evaluations DOPRI5 would have to employ with shorter time steps.
  • It could also be that linear solves and Jacobian evaluations are relatively cheap for your case (maybe your Jacobian is banded, or tridiagonal), so the LSODE time steps don't have to be that much larger to see an advantage.
  • If LSODE adaptively selects increasingly high orders for your problem, for stringent error tolerances, higher order methods generally win, and LSODE implements an order 12 implicit Adams method for "nonstiff" problems
  • However, for loose error tolerances, if stiffness (i.e., stability limit) issues do not dominate, lower order methods tend to prevail, so DOPRI5 might be more advantageous.
  • Also, if Jacobian matrix evaluations or linear solves are significantly more expensive than function evaluations, and stability/stiffness is not an issue, DOPRI5 is probably more advantageous.

Unless the performance is critical, it's usually easier just to try DOPRI5, which is frequently (but not always) cheaper, and then if it doesn't work, try LSODE. If neither works with the initial settings you give them, then you have to do some diagnostic work to see where problems are occurring.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.