SciML / diffeqpy

Solving differential equations in Python using DifferentialEquations.jl and the SciML Scientific Machine Learning organization
MIT License
531 stars 39 forks source link

Speed up julia loading and time to first run #114

Closed dan31 closed 11 months ago

dan31 commented 1 year ago

I am doing roughtly the following:

equations_string ="""
function f_foo(dU, U, P, t)
    dU[1] = ....
    ...
    dU[50] = ...
    return dU
"""
...
from julia.api import Julia
from diffeqpy import de
de.__name__ # trigger load
jl = Julia(compiled_modules=False)
model_julia = self.jl.eval(equations_string)
...
prob = de.ODEProblem(model_julia, X0, (0.0, 10.0), params)
sol = self.de.solve(prob, self.de.Rosenbrock23(autodiff=True))

The equations_string represents a fairly advanced ODE system. It takes considerable time both to load julia (say, 5-10 seconds) and init the equations (also 5-10 seconds from the first call to first result), whereas after this getting new solutions with other X0 values is fairly immediate.

I'm seeking for ways to optimize these times. I would like to compile the equations once and store them somewhere so that they need not be compiled every time I run. I'd also like to speed up loading times for Julia. Am I missing out something?

ChrisRackauckas commented 1 year ago

Try Julia v1.9 which now saves the JIT compiled code in binaries. That should be much better, and we're still improving it more (v1.10 is not released yet but has another major bump). After this, we are starting to look into shipping just the binaries so the solvers can be called without Julia, but that may take a bit more so for now the precompiled versions will have to do.