ODEFunctionExpr and observed variables [Modeling Toolkit]


so, I’m using MTK as a tool for modeling.

I’m using ModelingToolkitStandardLibrary in order to build my models (great tool btw).

After I build my ODESystem and run “structural_simplify” I would like to save my models into files such that I can load them in a format suitable for ODEProblem. In this way I hope to avoid building the ODESystem each time I want to use a model.

I found the possibility of building an ODEFunctionExpr or a julia function expr (using generate_function). Then I can easily save them to a julia file and load them using “include(“myfile.jl”)”.

My problem is that when I do this I’m not able to use the observed variables information anymore…which is a big problem to me. I know that If I build an ODEFunction from my ODESystem I will keep this information, but if I load from file this information is not present anymore.

I digged a bit into the source code and I noticed that in fact when calling the ODEFunctionExpr on my ODESystem the observed variables are indeed left out. Why does this happen? Is this intended? How can I keep/recover the observed variables information?

Thank you in advance!