I am using Catalyist and DifferentialEquations to study a chemical reaction, but the startup times are somewhat annoying. I have the option, in this case, to write the ODE by hand (thus not requiring Catalyst), and I can also integrate the ODE “by hand”, and with that the complete package would be very quick to load.
Would it be possible, instead of reimplementing the ODEs and the integrator, to load only a small subset of these packages to have a reasonably fast startup time?
Or, more specifically, can I save the “reaction_network” object, at least, and then not require Catalyst anymore in the project?
Minimal working example:
module Test
using Catalyst
using DifferentialEquations
function __init__()
rn = @reaction_network begin k, A --> B; end k
ode = ODEProblem(rn,[0,0],(0,1),[0])
s = solve(ode,p=[0,0],verbose=false)
end
end
If you don’t need the SDE/DDE/etc stuff from DiffEq.jl, you can just use OrdinaryDiffEq.jl, which should reduce load times significantly. Likewise, Catalyst just constructs a ReactionSystem from ModelingToolkit.jl, which you can also construct directly.
Those are definitely good suggestions, reducing by 30s the load time.
Does it make sense to try to save the ReactionSystem object to pass it directly to the ODEProblem, without having to construct it (and require ModelingToolkit) every time?
The code to translate a ReactionSystem into an ODEProblem lives in MTK.jl, so if you’re saving & loading a ReactionSystem, you’ll have to have MTK.jl loaded to perform that translation. If you can, save the ODEProblem instead and use remake to modify parameters as needed.
That is interesting. I tried that with the code below. But it is the first call to solve that is taking most of the time. Without Catalyst the startup is 10s faster, but the call to solve is taking ~30s here. Seems something is not quite right here, given that you are trying to reduce the first call to solve from 5 to 1 second?
module Test
#using Catalyst
using DifferentialEquations
function __init__()
#rn = @reaction_network begin k, A --> B; end k
rn_sys = begin
var"##iv#258" = (@variables(t))[1]
var"##sts#259" = (collect)(@variables(A(t), B(t)))
var"##ps#260" = (collect)(@parameters(k))
var"##eqs#261" = [(Differential(t))(A) ~ (*)(-1, k, A); (Differential(t))(B) ~ (* )(k, A)]
var"##defs#262" = (Dict)()
(ODESystem)(var"##eqs#261", var"##iv#258", var"##sts#259", var"##ps#260"; defaults = var"##defs#262", name = Symbol("##ReactionSystem#257"))
end
ode = ODEProblem(rn_sys,[0,0],(0,1),[0])
s = solve(ode,p=[0,0],verbose=false)
end
end
Thanks for all that, I was just reading that. Were all these PRs merged just these days? Today I have installed everything again to try to get rid of those Catalyst warnings and my impression was that startup time was way better, not anymore being a problem (I even added Plots as a dependency today )
Yes, it was in this last week. I’ve learned a lot about the Base Julia compiler, precompile files, and how it all interacts with type inference in my free time . We will need to merge https://github.com/SciML/OrdinaryDiffEq.jl/pull/1470, and your specific case hits the issue https://github.com/SciML/DifferentialEquations.jl/issues/785 which I described in the post, so you won’t get the full benefit but you will get a chunk of it (you’ll be missing a good 20 seconds off of the compile time though…). I still need to rummage through Symbolics and ModelingToolkit as well for their first call time issues are too, which would affect Catalyst. However, we now have a plan laid out which is the important piece because it now means it can change from the effort of one to an effort of the community.
Since you are there, congratulations for the Catalyst package, it is great. By the way, I couldn’t find a paper to cite, and publications using it will come soon. (for non-computer scientists github stars are the same facebook likes , we feel great, but nobody really cares).
Cite ModelingToolkit’s paper for now, since it’s the underlying compiler, and DifferentialEquations.jl for the solvers. Catalyst is getting is own paper very soon. We need to finish it
(for non-computer scientists github stars are the same facebook likes , we feel great, but nobody really cares).
We’ve been putting them into grant applications and the like as a measurement of usage. It’s not a great measurement of usage, but having exponential growth in metrics is never bad and it’s been working for us.