Skip to content
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

fix: @mtkmodel no longer makes @variables callable #3217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
StaticArrays = "0.10, 0.11, 0.12, 1.0"
SymbolicIndexingInterface = "0.3.35"
SymbolicUtils = "3.7"
Symbolics = "6.19"
Symbolics = "6.22"
URIs = "1"
UnPack = "0.1, 1.0"
Unitful = "1.1"
Expand Down
2 changes: 1 addition & 1 deletion src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function generate_var!(dict, a, b, varclass, mod;
vd isa Vector && (vd = first(vd))
vd[a] = Dict{Symbol, Any}()
var = if indices === nothing
Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Any}, type})(iv)
first(@variables $a(iv)::type)
else
vd[a][:size] = Tuple(lastindex.(indices))
first(@variables $a(iv)[indices...]::type)
Expand Down
21 changes: 20 additions & 1 deletion test/model_parsing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ModelingToolkit, Test
using ModelingToolkit, Symbolics, Test
using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
get_systems, get_ps, getdefault, getname, readable_code,
scalarize, symtype, VariableDescription, RegularConnector,
Expand Down Expand Up @@ -979,3 +979,22 @@ end
@test MultipleExtend.structure[:extend][1] == [:inmodel, :b, :inmodel_b]
@test tosymbol.(parameters(multiple_extend)) == [:b, :inmodel_b₊p, :inmodel₊p]
end

@testset "Variables are not callable symbolics" begin
@mtkmodel Example begin
@variables begin
x(t)
y(t)
end
@equations begin
x ~ y
end
end
@named ex = Example()
vars = Symbolics.get_variables(only(equations(ex)))
@test length(vars) == 2
for u in Symbolics.unwrap.(unknowns(ex))
@test !Symbolics.hasmetadata(u, Symbolics.CallWithParent)
@test any(isequal(u), vars)
end
end
Loading