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

Consistent variable creation #2428

Merged
merged 3 commits into from
Jan 25, 2024
Merged
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 src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
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)

Check warning on line 222 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L222

Added line #L222 was not covered by tests
else
vd[a][:size] = Tuple(lastindex.(indices))
first(@variables $a(iv)[indices...])
Expand Down
18 changes: 15 additions & 3 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, ModelingToolkit
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()
Expand Down Expand Up @@ -539,3 +538,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[])
Loading