# MTK & \`@mtkmodel\` & \`@mtkbuild\`

**URL:** <https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793>\
**Category:** Modelling & Simulations\
**Created:** [October 10, 2023, 9:26am UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793 "2023-10-10T09:26:24Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 9:26am UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/1 "2023-10-10T09:26:24Z")

</div>

Great to see the latest update of the `ModelingToolkit.jl` documentation! The “new way” of doing things with `@mtkmodel` makes sense to me!

There are a few things that I don’t understand in the transition from the “old” way to do things, and the new way.

1. Will the “old way” still work? [I.e., not using new macros, etc.?]

2. New `@mtkbuild` …

- When I try to run the _Getting Started_ section, the example under _Copy-Pastable Simplified Example_ , I get the following error message:  

- how does `@mtkbuild` (when I get it to work) compare to the “old way”? From the first example in the updated documentation (_Getting Started_ section):

```julia
@mtkmodel FOL begin
    @parameters begin
        τ # parameters
    end
    @variables begin
        x(t) # dependent variables
    end
    @equations begin
        D(x) ~ (1 - x) / τ
    end
end

@mtkbuild fol = FOL()
prob = ODEProblem(fol, [fol.x => 0.0], (0.0, 10.0), [fol.τ => 3.0])

```

In the “old way”, I always did instantiation followed by `structural_simplify` before sending the model to `ODEProblem`.

- Does `@mtkbuild` _combine_ the instantiation step (`@named fol = FOL()`) and the `structural_simplify`?
- One reason for my uncertainty… the first example of the subsequent _Building component-based, hierarchical models_ builds the model in the “old way”, i.e., does not use the `@mtkbuild` macro, and proceeds with `@named`, etc.

1. The macro `@structural_parameters`… I assume that the listed structural parameters, e.g., can be used for switching between different _equations_ in the model?

2. _Parameters_ vs. “derived parameters”  
Sometimes in the past, I have needed to introduce a common (“independent” parameter?), and then two derived parameters (“dependent” parameters?):

`@parameters a=1, b=2*a, c=1/a`

where `a` does not appear in the equations. That has caused problems, although the problems are avoided by adding the list of parameters in the `ODESystem` specification.

Should this case be handled as follows when using `@mtkmodel`?

```julia
@parameters begin
    a = 1
end

begin
    b = 2*a
    c = 1/a
end

```

1. Does the _order_ of the various macro blocks (`@parameters`, etc.) matter within the `@mtkmodel` block? In other words: do I have to specify parameter values _before_ I use them to set initial values for states, etc.?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 10, 2023, 2:10pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/2 "2023-10-10T14:10:38Z")

</div>

> [@BLI](#):
>
> Great to see the latest update of the `ModelingToolkit.jl` documentation! The “new way” of doing things with `@mtkmodel` makes sense to me!

Good to hear!

> [@BLI](#):
>
> Will the “old way” still work? [I.e., not using new macros, etc.?]

Yes, and it’s documented here:

> **[Programmatically Generating and Scripting ODESystems · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/programmatically_generating/)**
>
> Documentation for ModelingToolkit.jl.

That probably even de-mystifies some of the IR. Basically, `@mtkmodel` is the front-end to ModelingToolkit. It lowers to the intermediate representation (IR). The IR is quite nice to work on though: it’s not like LLVM, the IR is itself the symbolic representation that you previously used to work with. We now just put a face over it.

> [@BLI](#):
>
> When I try to run the _Getting Started_ section, the example under _Copy-Pastable Simplified Example_ , I get the following error message:

What version do you have? You need the latest of the latest, the one released like 2 days ago.

> [@BLI](#):
>
> Does `@mtkbuild` _combine_ the instantiation step (`@named fol = FOL()`) and the `structural_simplify`?

Yes, well and another step.

```julia
@named fol = FOL()
fol = complete(structural_simplify(fol))

```

is how to to write it in full. Technically, you should’ve been calling `complete` before: it’s what makes `fol.x` “work well” (because a completed system by default does not namespace the top level). In practice, I don’t think a lot of people did use `complete`, and so this will help people do things much more easily.

> [@BLI](#):
>
> One reason for my uncertainty… the first example of the subsequent _Building component-based, hierarchical models_ builds the model in the “old way”, i.e., does not use the `@mtkbuild` macro, and proceeds with `@named`, etc.

oh I’ll update that.

> [@BLI](#):
>
> - The macro `@structural_parameters`… I assume that the listed structural parameters, e.g., can be used for switching between different _equations_ in the model?

Not quite yet. We’ll get that done rather soon though.

> [@BLI](#):
>
> Should this case be handled as follows when using `@mtkmodel`?
> 
> ```julia
> 
> ```

```julia
@parameters begin
    a = 1
    b = 2*a
    c = 1/a
end

```

is the intended syntax. I’ll need to check if that works.

> [@BLI](#):
>
> Does the _order_ of the various macro blocks (`@parameters`, etc.) matter within the `@mtkmodel` block? In other words: do I have to specify parameter values _before_ I use them to set initial values for states, etc.?

I’m not sure if we check that right now, but I think it would be sane to enforce and order. Sometimes a little bit of order makes the world a bit cleaner.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 2:16pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/3 "2023-10-10T14:16:03Z")

</div>

> [@ChrisRackauckas](#):
>
> What version do you have? You need the latest of the latest, the one released like 2 days ago

![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/0799f3631cdc9185f0ca87f80707e4c4f06fe091.png)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 10, 2023, 2:18pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/4 "2023-10-10T14:18:20Z")

</div>

Okay yes you need v8.72.2. Try updating?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 2:26pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/5 "2023-10-10T14:26:56Z")

</div>

Ah. I did a `Pkg.update()` before I posted the questions 5 hours ago. I’m trying again – seems like now `Symbolics` has been updated from `v5.8.0` to `v5.9.0` within these 5 hours.

`ModelingToolkit` does not update, but there is a warning associated with it:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/c/3c703caf09b78937f712704cda5c0744adbb896b.png)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 10, 2023, 2:27pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/6 "2023-10-10T14:27:56Z")

</div>

> [@BLI](#):
>
> `ModelingToolkit` does not update, but there is a warning associated with it:

Do `]add ModelingToolkit@8.72.2`? Something may be holding it back.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 2:28pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/7 "2023-10-10T14:28:51Z")

</div>

Will try. From `Pkg.status()`:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/a/caae1aef453fbda31ba446c517d1652cbfeeca53.png)  
So there is a new version waiting…

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 2:30pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/8 "2023-10-10T14:30:53Z")

</div>

> [@ChrisRackauckas](#):
>
> Do `]add ModelingToolkit@8.72.2`? Something may be holding it back

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/4/445224789b8fe5ec5e043b79215c2d8eda667508.png)

OK – I could uninstall `MethodOfLines` for now.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 10, 2023, 2:33pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/9 "2023-10-10T14:33:37Z")

</div>

Yeah not everything will have updated around the ecosystem yet. You’re on the cutting edge 😅 . (@xtalax make note)

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 2:46pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/10 "2023-10-10T14:46:47Z")

</div>

> [@ChrisRackauckas](#):
>
> You’re on the cutting edge 😅 .

Cutting edge makes life exciting 😛  
[I’ve been playing around with `@mtkmodel` for a couple of weeks, based on the `ModelingToolkitStandardLibrary` presentation at JuliaCon 2023 + some input from @baggepinnen .]

`remove MethodOfLines` enabled updating `ModelingToolkit`.

Now, `@mtkbuild` works.

Still, my code doesn’t work yet… I get an error message on `None Sym BasicSymbolic doesn't have a name`.

Will post in a new thread.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [December 20, 2023, 3:33pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/11 "2023-12-20T15:33:44Z")

</div>

@BLI, did you open this other thread ? I’m running into the exact same problem with `None Sym BasicSymbolic doesn't have a name` and so far I don’t understand what to correct…

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [December 20, 2023, 3:54pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/12 "2023-12-20T15:54:36Z")

</div>

I opened this thread, which has been solved.

You write that you run “into the exact same problem with `None Sym BasicSymbolic doesn't have a name`”.

A couple of questions:

- Where in my thread did I say that I had a `None Sym BasicSymbolic doesn't have a name` message?
- If I didn’t have this message, how do we know that your problem is “the exact same problem”?

Can you be a little bit more explicit with what you try to do, and what the problem is?

[My problem was related to the use of the `@mtkbuild` where it turned out I used an outdated version of `ModelingToolkit` because another package, `MethodOfLines`, held back the updating of `ModelingToolkit`. That problem has long been solved, so your problem is not the same, I think.]

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 20, 2023, 4:00pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/13 "2023-12-20T16:00:13Z")

</div>

> [@BLI](#):
>
> Still, my code doesn’t work yet… I get an error message on `None Sym BasicSymbolic doesn't have a name`.
> 
> Will post in a new thread.

^^ This is what @BambOoxX is referring to. There are exactly two google hits on that error message; the “solution” to this topic and the un-answered ["None Sym BasicSymbolic doesn't have a name" Problem when using NeuralPDE](https://discourse.julialang.org/t/none-sym-basicsymbolic-doesnt-have-a-name-problem-when-using-neuralpde/100348). Let’s take the discussion here to the latter.

@BambOoxX if you could post the complete error message (including stack trace) and package versions there, that’d be great!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [December 20, 2023, 4:11pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/14 "2023-12-20T16:11:10Z")

</div>

Ah… perhaps I did not post in a new thread?

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [December 20, 2023, 4:54pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/15 "2023-12-20T16:54:51Z")

</div>

> [@mbauman](#):
>
> ^^ This is what @BambOoxX is referring to

Yes exactly ^^ thanks.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [December 20, 2023, 4:59pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/16 "2023-12-20T16:59:35Z")

</div>

> [@mbauman](#):
>
> ^^ This is what @BambOoxX is referring to. There are exactly two google hits on that error message; the “solution” to this topic and the un-answered [“None Sym BasicSymbolic doesn’t have a name” Problem when using NeuralPDE](https://discourse.julialang.org/t/none-sym-basicsymbolic-doesnt-have-a-name-problem-when-using-neuralpde/100348). Let’s take the discussion here to the latter.
> 
> @BambOoxX if you could post the complete error message (including stack trace) and package versions there, that’d be great!

I am not sure this needs a new thread (at least from my perspective) I was just curious if there was already an answer given @BLI 's comment. I’ll open a new thread if I have a concrete example to show. Thanks for the help.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [December 20, 2023, 5:01pm UTC](https://discourse.julialang.org/t/mtk-mtkmodel-mtkbuild/104793/17 "2023-12-20T17:01:56Z")

</div>

Yeah, this was 2 months ago. I don’t remember what the problem was. I have since moved on and MTK mainly works for me now.
