Skip to content

Commit

Permalink
Merge pull request #3217 from AayushSabharwal/as/mtkmodel-variables
Browse files Browse the repository at this point in the history
fix: `@mtkmodel` no longer makes `@variables` callable
  • Loading branch information
ChrisRackauckas authored Jan 9, 2025
2 parents a976298 + 25fd631 commit 113aec7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ StochasticDiffEq = "6.72.1"
StochasticDelayDiffEq = "1.8.1"
SymbolicIndexingInterface = "0.3.36"
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 @@ -990,3 +990,22 @@ struct CustomStruct end
@named sys = MyModel(p = CustomStruct())
@test ModelingToolkit.defaults(sys)[@nonamespace sys.p] == CustomStruct()
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

0 comments on commit 113aec7

Please sign in to comment.