-
-
Notifications
You must be signed in to change notification settings - Fork 232
fix: array parameters in nested @mtkmodel components #3944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
|
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
for var in expr_vars | ||
var_unwrapped = unwrap(var) | ||
# If any variable in the expression is from parent scope, don't namespace | ||
if isparameter(var_unwrapped) && !(var_unwrapped in sys_params || var_unwrapped in sys_unknowns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
if isparameter(var_unwrapped) && !(var_unwrapped in sys_params || var_unwrapped in sys_unknowns) | |
if isparameter(var_unwrapped) && | |
!(var_unwrapped in sys_params || var_unwrapped in sys_unknowns) |
Dict((isparameter(k) ? parameters(sys, k) : unknowns(sys, k)) => | ||
(should_namespace(v) ? namespace_expr(v, sys) : v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
Dict((isparameter(k) ? parameters(sys, k) : unknowns(sys, k)) => | |
(should_namespace(v) ? namespace_expr(v, sys) : v) | |
Dict((isparameter(k) ? parameters(sys, k) : | |
unknowns(sys, k)) => (should_namespace(v) ? namespace_expr(v, sys) : v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail
I don't think I have sufficient insight into the internals to make everything pass. This was enough to allow me to move forward on a time critical problem, so I'll probably leave it here for now |
Makes sense, I'll try and take a look when I can. |
Here's another test case that fails both on latest release and this PR branch, wrong number of defaults generated using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
@mtkmodel inner2 begin
@parameters begin
a[1:2] = a
end
@variables begin
x(t)[1:2] = zeros(2)
end
@equations begin
D(x) ~ a
end
end
@mtkmodel outer2 begin
@parameters begin
a1 = 1
a2 = 1
end
@components begin
i = inner2(a=[a1,a2])
end
@variables begin
y(t)[1:2] = zeros(2)
dy(t)[1:2]
end
@equations begin
D(y) ~ dy
dy ~ [a1, a2]
end
end
@named o = outer2()
o = complete(o)
ssys = mtkcompile(o)
varmap = []
prob = ODEProblem(ssys, varmap, (0, 1)) This looks fishy julia> MTK=ModelingToolkit;filter(kvp -> !MTK.isinitial(kvp[1]) && !MTK.isparameter(kvp[1]), defaults(ssys))
Dict{Any, Any} with 6 entries:
(i₊x(t))[2] => 0.0
(i₊x(t))[1] => 0.0
(y(t))[2] => 0.0
(y(t))[1] => 0.0
(dy(t))[2] => NoValue()
(dy(t))[1] => NoValue() |
attempt to close #2813
This only handles defaults that are a single Num, liker=r_def
, it does not yet handler_def
being an expression with multiple variables