From 53f32e29c519a8bc48d61fd3b80a733d99bac049 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 18 Nov 2024 16:28:03 +0530 Subject: [PATCH 1/2] fix: `@mtkmodel` no longer makes `@variables` callable --- src/systems/model_parsing.jl | 2 +- test/model_parsing.jl | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 5402659b1c..52e46597bf 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -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) diff --git a/test/model_parsing.jl b/test/model_parsing.jl index 6ab7636b32..baaa4651bf 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -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, @@ -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 From 25fd631c599b5c885d1faadddbceff5787c23533 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 20 Nov 2024 21:47:38 +0530 Subject: [PATCH 2/2] build: bump Symbolics compat --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7b0997823c..2e4812c50f 100644 --- a/Project.toml +++ b/Project.toml @@ -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"