fix: array parameters in nested @mtkmodel components#3944
Open
baggepinnen wants to merge 2 commits intomasterfrom
Open
fix: array parameters in nested @mtkmodel components#3944baggepinnen wants to merge 2 commits intomasterfrom
baggepinnen wants to merge 2 commits intomasterfrom
Conversation
Contributor
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
|
Contributor
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) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| 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) |
Comment on lines
+1170
to
+1171
| Dict((isparameter(k) ? parameters(sys, k) : unknowns(sys, k)) => | ||
| (should_namespace(v) ? namespace_expr(v, sys) : v) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| 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) |
Contributor
Author
|
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 |
Member
|
Makes sense, I'll try and take a look when I can. |
Contributor
Author
|
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
attempt to close #2813
This only handles defaults that are a single Num, liker=r_def, it does not yet handler_defbeing an expression with multiple variables