patrick-kidger / diffrax

Numerical differential equation solvers in JAX. Autodifferentiable and GPU-capable. https://docs.kidger.site/diffrax/
Apache License 2.0
1.37k stars 125 forks source link

DAE Interactive Adaptive Step-Size Solver #261

Open lmriccardo opened 1 year ago

lmriccardo commented 1 year ago

Hi, I have a DAE model with explicit algebraic equations (I would like to highlight this since I've already see the issue about DAE with implicit algebraic equations). I just implemented a simple step-by-step solver instead of using the diffeqsolve to handle algebraic equations. However, I found a paricular DAE that is not solvable using classical Dopri5 or Tsit5, unless using very small step size, hence I decided to use an adaptive stepsize controller (the PIDController) and the solver Kvaerno5.

To be more clear this is a system I would like to deal with, like any biological systems.

dx/dt = f(x(t),args,t)
args_1 = g_1(...)
args_2 = g_2(...)
...
args_N = g_N(...)

Having said that, I'm actually having trouble implementing the same step-by-step using the PIDController and the SaveAt. Are there any suggestions?

Thank you for the answer.

I'm in particular interest for this project and Equinox too, they are awesome!!

patrick-kidger commented 1 year ago

Thank you, I'm glad you like them!

I would recommend using diffeqsolve over the step-by-step interface if possible. This should handle the details of PID control and SaveAt for you.

It should be possible to use the approach discussed here: simply replace the z1 = nonlinear_sol.root line with z1 = g(...) and evaluate your constraints directly.

Does that make sense?

(Incidentally DAEs are on the roadmap for Diffrax, and something I hope to have working in a few months.)

lmriccardo commented 1 year ago

Yes! Thanks you very much. The fact is that, from what I read in the Documentation, the approach of calling step-by-step diffeqsolve (If this is what you meant) might be a bit unsophisticated, but maybe I just misunderstood the point.

I will try to go in this direction then, because the idea to modify the altready implemented loop function and creating a new Adjoint was getting me mad (I'm not yet into all the details of Diffrax).

Thanks again!