neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
56 stars 14 forks source link

Caching compilation results #51

Closed alexfikl closed 10 months ago

alexfikl commented 10 months ago

I'm trying to solve a DDE multiple times with different initial conditions (all other parameters stay the same). The code generation part seems to be taking the bulk of the runtime for this and making the whole simulation unnecessarily slow.

I there some way to cache the generated code? What would be the best way to tackle this issue with JiTCDDE?

Python version: 3.11.5 JiTCDDE version: 1.8.1

alexfikl commented 10 months ago

Well, a bit of actually reading the docs seems to have solved this: a combination of save_compiled and module_location=<...> seems to work nicely!

I'll leave this here in case there's a better way, but feel free to just close it.

mwappner commented 10 months ago

No need to save and load the compiled model each time! You can just purge_past between each initial condition and then re-initialize each time.

Assuming DDE is your integrator and ics is a list of initial conditions, it would be something like

for ic in ics:
    DDE.purge_past()
    DDE.constant_past(ic, 0)
    DDE.step_on_discontinuities()

    data = np.hstack([DDE.integrate(tt) for tt in time])

Really neat and tidy :)

alexfikl commented 10 months ago

That's even cleaner (also missed the purge_past method..). Thanks for the suggestion!