Modeling Toolkit: mtkcompile taking forever for large systems

I recently re-coded an advection-reaction biogeochemical box model using ModelingToolkit.jl, that allows a smooth transition form papers’ equations to actual code and make it easily understandable. I build the model in a very naive way, by writing multiple .jl files, each one containing the equations and variables, and in a script I just have the different include(...).

In the native version, I have about ~500 equations, and only ~90 are actual independant ODEs (others are fluxes, or forcing set via CallBacks, temporary variables to make it look nice, …). In this case, calling mtkcompile takes around ~20 seconds (without julia compilation) which is enough in my case (and solving the ODEs takes less than a sec).

However, in a second version, where I increase the discretization of my model (i.e., the number of oceanic boxes), it takes forever (I manually killed it after 3h). In that set-up, the number of equation is about ~4400 (that’s not that huge) before structural simplification (and the number of actual independent ODEs should be around ~650).

I have quite complex-nonlinear equation, that I tried to hide behind registered functions (using @register_symbolic) but it did not help. I also had a look at JuliaSimCompiler.jl but it does not seem to be compatible with the latest versions of ModelingToolkit.jl.

It would be difficult to provide a mwe but if you have advices I would be glad to hear them.

Thanks,
L.

julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
[961ee093] ModelingToolkit v10.10.0

Open an issue on the repo with something that we can test. Specifically I’d like to test the impact of feat: add `SemilinearODEFunction` and `SemilinearODEProblem` by AayushSabharwal · Pull Request #3739 · SciML/ModelingToolkit.jl · GitHub