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):
@mtkmodel FOL begin
τ # parameters
x(t) # dependent variables
D(x) ~ (1 - x) / τ
@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 @mtkbuildcombine 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.
The macro @structural_parameters… I assume that the listed structural parameters, e.g., can be used for switching between different equations in the model?
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?
a = 1
b = 2*a
c = 1/a
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.?
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.
What version do you have? You need the latest of the latest, the one released like 2 days ago.
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.
oh I’ll update that.
Not quite yet. We’ll get that done rather soon though.
a = 1
b = 2*a
c = 1/a
is the intended syntax. I’ll need to check if that works.
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.
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 .]