# MTK error messages, change of use?

**URL:** <https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [August 7, 2024, 9:56pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931 "2024-08-07T21:56:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaraSchmalenstroer](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@LaraSchmalenstroer](https://discourse.julialang.org/u/LaraSchmalenstroer)\
**Post date:** [August 7, 2024, 9:56pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/1 "2024-08-07T21:56:18Z")

</div>

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).

```julia
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:

```julia
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:

```julia
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](https://discourse.julialang.org/t/error-with-modelingtoolkit-documentation-example/113946), 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!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 8, 2024, 2:01am UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/2 "2024-08-08T02:01:51Z")

</div>

Which version of ModelinsToolkit are you using?

Can you share the output of

```julia
]
st

```

?

---

<div class="post-metadata">

**Author:** ![LaraSchmalenstroer](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@LaraSchmalenstroer](https://discourse.julialang.org/u/LaraSchmalenstroer)\
**Post date:** [August 8, 2024, 4:09pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/3 "2024-08-08T16:09:57Z")

</div>

I’m using `ModelingToolkit` v9.30.1:

```julia
[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](https://discourse.julialang.org/t/error-with-modelingtoolkit-documentation-example/113946) 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.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 8, 2024, 4:27pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/4 "2024-08-08T16:27:42Z")

</div>

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

```julia
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:

```julia
versioninfo()

```

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

---

<div class="post-metadata">

**Author:** ![LaraSchmalenstroer](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@LaraSchmalenstroer](https://discourse.julialang.org/u/LaraSchmalenstroer)\
**Post date:** [August 8, 2024, 4:53pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/5 "2024-08-08T16:53:09Z")

</div>

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.

```julia
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.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 8, 2024, 5:24pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/6 "2024-08-08T17:24:54Z")

</div>

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

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

```

and then in Julia:

```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.

---

<div class="post-metadata">

**Author:** ![LaraSchmalenstroer](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@LaraSchmalenstroer](https://discourse.julialang.org/u/LaraSchmalenstroer)\
**Post date:** [August 9, 2024, 5:51pm UTC](https://discourse.julialang.org/t/mtk-error-messages-change-of-use/117931/7 "2024-08-09T17:51:51Z")

</div>

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