ModelingToolkit fails to precompile on Julia 1.12 (UndefVarError: ODESystem not defined in ModelingToolkit)

Hi everyone,

I’m having trouble with ModelingToolkit precompilation on Julia 1.12 on Windows, and I can’t figure out what’s triggering it.

In my project I’m just adding some libraries (including ModelingToolkit) :

using ModelingToolkit
using OrdinaryDiffEq
using Plots
using Waveforms
using Sundials
using DASSL

and I consistently get:

PkgPrecompileError: The following 1 direct dependency failed to precompile:

ModelingToolkit


Failed to precompile ModelingToolkit [961ee093-0014-501f-94e3-6117800e7a78] to "C:\\Users\\...\\.julia\\compiled\\v1.12\\ModelingToolkit\\jl_XXXX.tmp".
ERROR: LoadError: UndefVarError: `ODESystem` not defined in `ModelingToolkit`
Suggestion: define the const at top-level before running function that uses it (stricter Julia v1.12+ rule).

I tried to add a local environment and compile via:

using Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()
Pkg.precompile()

but I still get the same error.

Some extras :

Using ModelingToolkit in the REPL works, so it seems the package itself is installed, but the precompilation step keeps failing with this ODESystem error.

Has anyone seen this on Julia 1.12, or knows what can cause this issue during precompile? Any tips on how to debug which file / expression is being evaluated at that point would be very welcome.

Thanks!

Hi,
can you maybe post the Project.toml and Mainifest.toml?

Somehow I seems to work on my machine, if I just install the packages, so maybe it has to do with specific versions.

ODESystem doesn’t exist in the ModelingToolkit versions that came out in the last year, so this is at least clearly not on anything recent. What versions do you have? What in your Project.toml is keeping things back?

1 Like

I actually think we added it back (as an alias for System) so a simple package update should fix it.

The Project.toml :

[deps]
DASSL = "e993076c-0cfd-5d6b-a1ac-36489fdf7917"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
QuantizedSystemSolver = "1012ed6b-4eb4-43ec-b9f7-8dc4179649a3"
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
Waveforms = "cb13b1c6-351e-5134-b3ad-d6a530956a82"

and for Mainifest.toml :

(...)
[[deps.ModelingToolkit]]
deps = ["AbstractTrees", "ArrayInterface", "Combinatorics", "Compat", "ConstructionBase", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "DiffRules", "Distributed", "Distributions", "DocStringExtensions", "DomainSets", "DynamicQuantities", "ExprTools", "FindFirstFunctions", "ForwardDiff", "FunctionWrappersWrappers", "Graphs", "InteractiveUtils", "JuliaFormatter", "JumpProcesses", "LabelledArrays", "Latexify", "Libdl", "LinearAlgebra", "MLStyle", "NaNMath", "OrderedCollections", "OrdinaryDiffEq", "PrecompileTools", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLBase", "SciMLStructures", "Serialization", "Setfield", "SimpleNonlinearSolve", "SparseArrays", "SpecialFunctions", "StaticArrays", "SymbolicIndexingInterface", "SymbolicUtils", "Symbolics", "URIs", "UnPack", "Unitful"]
git-tree-sha1 = "81ffc7d059a10669a809a4dad2576998b196a43b"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
version = "9.15.0"

    [deps.ModelingToolkit.extensions]
    MTKBifurcationKitExt = "BifurcationKit"
    MTKDeepDiffsExt = "DeepDiffs"

    [deps.ModelingToolkit.weakdeps]
    BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
    DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"

[[deps.ModelingToolkitStandardLibrary]]
deps = ["ChainRulesCore", "DiffEqBase", "IfElse", "LinearAlgebra", "ModelingToolkit", "Symbolics"]
git-tree-sha1 = "e45ea9a9183d8d3b888a614bd5230262c443cc4f"
uuid = "16a59e39-deab-5bd0-87e4-056b12336739"
version = "2.11.0"
(...)

From what I can see, the ModelingToolkit version is 9.15.0, so I tried updating it, but I’m getting this output:

 pkg> update ModelingToolkit
    Updating registry at `C:\Users\...\.julia\registries\General.toml`
     Project No packages added to or removed from `C:\Users\myproject\Project.toml`
    Manifest No packages added to or removed from `C:\Users\myproject\Manifest.toml`
  ✗ ModelingToolkit
  ✗ ModelingToolkitStandardLibrary
Precompiling packages finished.
  0 dependencies successfully precompiled in 90 seconds. 475 already precompiled.
  2 dependencies errored.
  For a report of the errors see `julia> err`. To retry use `pkg> precompile`

and the associated error is :

ERROR: LoadError: UndefVarError: `ODESystem` not defined in `ModelingToolkit`
Suggestion: define the const at top-level before running function that uses it (stricter Julia v1.12+ rule).
Note: the binding state changed since the error occurred (was: 11, now: 0).

The ModelingToolkit version is 9.15.0, so it’s not the most recent. However, when I try to update it I get the error shown in my reply to @Fourier’s comment.

In this case I sometimes just rm Manifest.toml && ] up and it just solves the problem.

Thanks for the reply.
I tried deleting the Manifest.toml and then running ] up, but I’m getting basically the same error :

PkgPrecompileError: The following 2 direct dependencies failed to precompile:

ModelingToolkitStandardLibrary

Failed to precompile ModelingToolkitStandardLibrary [16a59e39-deab-5bd0-87e4-056b12336739] to "C:\\Users\\jnmor\\.julia\\compiled\\v1.12\\ModelingToolkitStandardLibrary\\jl_3BA1.tmp".
ERROR: LoadError: UndefVarError: `ODESystem` not defined in `ModelingToolkit`
Suggestion: define the const at top-level before running function that uses it (stricter Julia v1.12+ rule).

ERROR: LoadError: Failed to precompile ModelingToolkit [961ee093-0014-501f-94e3-6117800e7a78] to "C:\\Users\\jnmor\\.julia\\compiled\\v1.12\\ModelingToolkit\\jl_4A33.tmp".  

Do ]add ModelingToolkit@10 and share what it gives

Thanks for the reply, @ChrisRackauckas. After doing that, I’m now getting the following error:


ERROR: Unsatisfiable requirements detected for package SymbolicUtils [d1185830]:
 SymbolicUtils [d1185830] log:
 ├─possible versions are: 0.1.0 - 4.5.1 or uninstalled
 ├─restricted by compatibility requirements with ModelingToolkit [961ee093] to versions: 3.26.1 - 3.32.0
 │ └─ModelingToolkit [961ee093] log:
 │   ├─possible versions are: 0.0.1 - 10.30.0 or uninstalled
 │   ├─restricted to versions * by project [0c44d8f1], leaving only versions: 0.0.1 - 10.30.0
 │   │ └─project [0c44d8f1] log:
 │   │   ├─possible versions are: 0.0.0 or uninstalled
 │   │   └─project [0c44d8f1] is fixed to version 0.0.0
 │   └─restricted to versions 10 by an explicit requirement, leaving only versions: 10.0.0 - 10.30.0
 └─restricted by compatibility requirements with SymEngine [123dc426] to versions: 1.4.0 - 1.7.1 or uninstalled — no versions left
   └─SymEngine [123dc426] log:
     ├─possible versions are: 0.4.1 - 0.13.0 or uninstalled
     └─restricted by compatibility requirements with QuantizedSystemSolver [1012ed6b] to versions: 0.11.0
       └─QuantizedSystemSolver [1012ed6b] log:
         ├─possible versions are: 1.0.1 - 1.0.7 or uninstalled
         └─restricted to versions * by project [0c44d8f1], leaving only versions: 1.0.1 - 1.0.7
           └─project [0c44d8f1] log: see above

Your problem is QuantizedSystemSolver is on an old version of SymEngine. I’d recommend just removing it since it seems somewhat unmaintained.

Thanks a lot, it works! :tada:
Yes, the issue was the incompatibility with QuantizedSystemSolver.