Closed david-hofmann closed 1 month ago
Why are you making 2b
a parameter of the system, though? Also you're applying ParentScope
, but the parent system (level1
) doesn't actually have that variable (b
) which seems wrong.
This works:
@parameters a b
_b = ParentScope(2b)
eq = [D(x) ~ (a+_b)*x]
p = [a, b]
level0 = System(eq, t, [x], [a]; name = :level0)
level1 = ODESystem(Equation[], t, [], [b]; name = :level1) ∘ level0
Which is what ParentScope
means.
If I'm missing the point here, please correct me.
I see, thank you! This makes sense and seems actually cleaner. How I coded it used to work in the past version, I suppose that is because the parameters were inferred from the equations, rather than passed to System
explicitly?
The way we coded it up currently in Neuroblox relies on that parameter inference, so please help me fully understand the new implementation.
Let's say I remove the parameters in System
, it can still infer them from the equation but only the one that is not scoped:
using ModelingToolkit
const t = ModelingToolkit.t_nounits
const D = ModelingToolkit.D_nounits
@parameters a b
@variables x(t)
_b = ParentScope(2b)
eq = [D(x) ~ (a+_b)*x]
p = [a, b]
level0 = System(eq, t; name = :level0)
level1 = ODESystem(Equation[], t; name = :level1) ∘ level0
gives
Model level0 with 1 equations
Unknowns (1):
x(t)
Parameters (1):
a
Model level1 with 1 equations
Unknowns (1):
level0₊x(t)
Parameters (1):
level0₊a
Is this intended behavior? It seems somehow inconsistent, why would I not infer also b? Why just not show it? It makes sense to not show it on level0 but on level1 it could be included, no? That would solve our issue.
Hmm. Yeah I guess we could infer it in level1
. I'm fairly certain this working before was more of a happy accident that also ended up breaking other systems.
Thanks so much for #3112 it all works now!
The latest MTK version does not allow parent scoping on expressions
While this worked in the previous version, applying
ParentScope
on expressions does cause an error. Probably due to this PR? This causes problems in Neuroblox (https://github.com/Neuroblox/Neuroblox.jl/issues/439)Minimal Reproducible Example 👇 Related to this documentation example.
It also breaks when applying
ParentScope
only to the parameter and compose the expression afterwardsb = 2*ParentScope(b)
Error & Stacktrace ⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()