MTK error messages, change of use?

Hi,

I’m relatively new to Julia, so maybe I don’t see the problem here. I’m currently working with ModelingToolkit. To get used to the functionalities, I created a small model last week (which worked perfectly).

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D

@mtkmodel TestModel begin
        @parameters begin
            ρ 
            kcl 
            krad
        end
        @variables begin
            C(t) 
            Crad(t) 
        end
        @equations begin
            D(C) ~ ρ * C - krad * C
            D(Crad) ~ krad * C - kcl * Crad
        end
    end

@mtkbuild test_model = TestModel()

When I now try running the same code, I encounter various error messages:

WARNING: could not import ModelingToolkit.t_nounits into Main
WARNING: could not import ModelingToolkit.D_nounits into Main

ERROR: LoadError UndefVarError: `@mtkmodel` not defined

When I avoid using @mtkmodel and @mtkbuild and create the model with @named model = ODESystem(eqs, t) , add the time as a variable @variables t and define D manually D = Differential(t), it works.

I also have problems with using ModelingToolkit functions that I used last week, e.g. ModelingToolkit.linearize_symbolic and get the same error message as above:

ERROR: UndefVarError `linearize_symbolic` not defined

I’m using ModelingToolkit version v9.30.1. Last week I was using an older version (8.x) due to some version requirements in FindSteadyStates.jl. After seeing the solution here, I updated ModelingToolkit to the latest version but it’s not working either. I also started with a clean environment and loaded the packages again but it doesn’t solve the problem.

The models from the documentation throw the same errors. Is there a change in the usage of the package that I missed?

Any help is appreciated!

Which version of ModelinsToolkit are you using?

Can you share the output of

]
st

?

I’m using ModelingToolkit v9.30.1:

[c3fe647b] AbstractAlgebra v0.42.0
[0f109fa4] BifurcationKit v0.3.6
[0c46a032] DifferentialEquations v7.13.0
[23fbe1c1] Latexify v0.16.4
[961ee093] ModelingToolkit v9.30.1
[8913a72c] NonlinearSolve v3.13.1
[91a5bcdd] Plots v1.40.5
[f27b6e38] Polynomials v4.0.11
[438e738f] PyCall v1.96.4
[9672c7b4] SteadyStateDiffEq v2.3.0
[24249f21] SymPy v2.1.1
[0c5d862f] Symbolics v5.35.1

Like I said in the original post, I’ve been using an older version before (v8.36.0) because of the requirements in FindSteadyStates.jl but updated to the latest version after seeing this post where an update solved the problem that t_nounits and D_nounits couldn’t be imported. In my case, the update didn’t solve the problems.

I tried your code on Ubuntu Linux, and it works fine:

julia> include("test.jl")
Model test_model with 2 equations
Unknowns (2):
  C(t)
  Crad(t)
Parameters (3):
  ρ
  kcl
  krad
Incidence matrix:2×4 SparseArrays.SparseMatrixCSC{Num, Int64} with 5 stored entries:
 ×  ⋅  ×  ⋅
 ×  ×  ⋅  ×

Can you share the output of:

versioninfo()

?
And are you sure you have nothing in startup.jl that messes things up?

Thank you for your replies!

It’s really weird, everything used to work until the weekend and after that it stopped although I haven’t changed anything. I also know that the model is probably not the problem since also the models copied from the documentation are not running if they contain for example the @mtkbuild , t_nounits or D_nounits. I could of course just define the model without that in the “old” way but this still doesn’t solve the problem that some of the functions like ModelingToolkit.linearize_symbolic are not found anymore.

versioninfo()

Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

I’m also sure about the startup.jl as I don’t have one. I only started using Julia recently with the main purpose of ODE-based modeling and at the moment I’m mainly getting to know the packages used in that area until I’m ready to go on to the actual project.

Can you try to create a project that contains only ModelingToolkit, like this:

mkdir test
cd test
julia --project="."

and then in Julia:

using Pkg
pkg"add ModelingToolkit"

If that doesn’t help you could try to delete the .julia folder in your home directory. Perhaps something got messed up.

@ufechner7 The last tip helped! I tried your suggestions but deleting the .julia folder finally solved the issues. Thank you for your replies!

1 Like