From c7d666729938c7432b4c75fb08d89e25280f7d0a Mon Sep 17 00:00:00 2001 From: Yingbo Ma <mayingbo5@gmail.com> Date: Wed, 17 Jan 2024 14:13:03 -0500 Subject: [PATCH 1/3] Consistent variable creation --- src/systems/model_parsing.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 4a8d73652c..f772abbb00 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -219,7 +219,7 @@ function generate_var!(dict, a, b, varclass; vd isa Vector && (vd = first(vd)) vd[a] = Dict{Symbol, Any}() var = if indices === nothing - Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Real}, Real})(iv) + Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Any}, Real})(iv) else vd[a][:size] = Tuple(lastindex.(indices)) first(@variables $a(iv)[indices...]) From a0aad457e7e2301b4d16a44d40f6435ce3cecaec Mon Sep 17 00:00:00 2001 From: Yingbo Ma <mayingbo5@gmail.com> Date: Wed, 17 Jan 2024 14:17:00 -0500 Subject: [PATCH 2/3] Add tests --- test/model_parsing.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/model_parsing.jl b/test/model_parsing.jl index f94d7483fd..240ea2485f 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -329,7 +329,7 @@ end # Ensure that modules consisting MTKModels with component arrays and icons of # `Expr` type and `unit` metadata can be precompiled. module PrecompilationTest -using Unitful, Test, ModelingToolkit +using Unitful, Test, ModelParsingPrecompile @testset "Precompile packages with MTKModels" begin push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test")) @@ -539,3 +539,16 @@ end @test Equation[ternary_true.ternary_parameter_true ~ 0] == equations(ternary_true) @test Equation[ternary_false.ternary_parameter_false ~ 0] == equations(ternary_false) end + +_b = Ref{Any}() +@mtkmodel MyModel begin + @variables begin + x___(t) = 0 + end + begin + _b[] = x___ + end +end +@named m = MyModel() +@variables t x___(t) +@test isequal(x___, _b[]) From 90124ec3cf486949c9a310623ce3104c2f1b858d Mon Sep 17 00:00:00 2001 From: Yingbo Ma <mayingbo5@gmail.com> Date: Thu, 25 Jan 2024 16:38:14 -0500 Subject: [PATCH 3/3] Fix tests --- test/model_parsing.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/model_parsing.jl b/test/model_parsing.jl index 240ea2485f..f2a23037d3 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -329,10 +329,9 @@ end # Ensure that modules consisting MTKModels with component arrays and icons of # `Expr` type and `unit` metadata can be precompiled. module PrecompilationTest -using Unitful, Test, ModelParsingPrecompile +push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test")) +using Unitful, Test, ModelParsingPrecompile, ModelingToolkit @testset "Precompile packages with MTKModels" begin - push!(LOAD_PATH, joinpath(@__DIR__, "precompile_test")) - using ModelParsingPrecompile: ModelWithComponentArray @named model_with_component_array = ModelWithComponentArray()