Would it be worth it to move to DifferentialEquation.jl?

Hey,

I have an application that is taking a bit long, but looking at profview i am wondering if it would be actually worth it to move it to DE.jl. Here are the specifics:

  • I have a pre-setted grid with a lot of time points (around 4000) on which I am solving the equation. I cannot change the grid.
  • at each time point, I then have to solve a non-linear equation that depends on the previous solves.
  • Most (90%) of my runtime is in solving this equation each time with Roots.find_zero(), using the previous value as a starting point.

I included a small dataset together with the code in this gist : Differential equation solving -- example · GitHub. The code itself is about 100 lines long.

Do you think DE.jl will do a much better job ? If so, how should i reformat this so that it takes it ?

It looks like you are currently using Implicit Euler. You could likely get a roughly 10x speedup by switching since it would make it trivially easy to use higher order methods (e.g. FBDF). all you need to do to port it is rewrite equation to the form equation(u, p, t) where u is a state vector, p is any time independent parameters, and t is the current time. The function should return du/dt for each u.

1 Like

so the huge dataset would go in p ? Can you point me to the part of the docs that actually shows how to use implicit euler with hand-picked time points ? My first goal would be to reproduce the results i already have before trying other methods.

Even if I am not sure other methods would be interesting, since the final du/dt is actually piecewise constant (the jump times are my time frame).

wait, if du/dt is piecwise constant, can’t you use explicit euler and skip the nonlinear solve completely?

Well it still depends on u. Hum… Maybe it is not piecewise constant then, but my approximation of it might be.

More precisely : it is a non-linear function of u that is defined piecewise.