Skip to content

Commit

Permalink
fix: retain system metadata when calling flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 18, 2024
1 parent 31f7a54 commit e4d5710
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ function flatten(sys::ODESystem, noeqs = false)
initialization_eqs = initialization_equations(sys),
is_dde = is_dde(sys),
tstops = symbolic_tstops(sys),
metadata = get_metadata(sys),
checks = false)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/systems/discrete_system/discrete_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function flatten(sys::DiscreteSystem, noeqs = false)
defaults = defaults(sys),
name = nameof(sys),
description = description(sys),
metadata = get_metadata(sys),
checks = false)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/systems/nonlinear/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ function flatten(sys::NonlinearSystem, noeqs = false)
defaults = defaults(sys),
name = nameof(sys),
description = description(sys),
metadata = get_metadata(sys),
checks = false)
end
end
Expand Down
1 change: 1 addition & 0 deletions src/systems/optimization/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function flatten(sys::OptimizationSystem)
constraints = constraints(sys),
defaults = defaults(sys),
name = nameof(sys),
metadata = get_metadata(sys),
checks = false
)
end
Expand Down
36 changes: 36 additions & 0 deletions test/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,39 @@ end
ss = structural_simplify(cbar)
@test isequal(cbar.foo.x, ss.foo.x)
end

@testset "Issue#3275: Metadata retained on `complete`" begin
@variables x(t) y(t)
@testset "ODESystem" begin
@named inner = ODESystem(D(x) ~ x, t)
@named outer = ODESystem(D(y) ~ y, t; systems = [inner], metadata = "test")
@test ModelingToolkit.get_metadata(outer) == "test"
sys = complete(outer)
@test ModelingToolkit.get_metadata(sys) == "test"
end
@testset "NonlinearSystem" begin
@named inner = NonlinearSystem([0 ~ x^2 + 4x + 4], [x], [])
@named outer = NonlinearSystem(
[0 ~ x^3 - y^3], [x, y], []; systems = [inner], metadata = "test")
@test ModelingToolkit.get_metadata(outer) == "test"
sys = complete(outer)
@test ModelingToolkit.get_metadata(sys) == "test"
end
k = ShiftIndex(t)
@testset "DiscreteSystem" begin
@named inner = DiscreteSystem([x(k) ~ x(k - 1) + x(k - 2)], t, [x], [])
@named outer = DiscreteSystem([y(k) ~ y(k - 1) + y(k - 2)], t, [x, y],
[]; systems = [inner], metadata = "test")
@test ModelingToolkit.get_metadata(outer) == "test"
sys = complete(outer)
@test ModelingToolkit.get_metadata(sys) == "test"
end
@testset "OptimizationSystem" begin
@named inner = OptimizationSystem(x^2 + y^2 - 3, [x, y], [])
@named outer = OptimizationSystem(
x^3 - y, [x, y], []; systems = [inner], metadata = "test")
@test ModelingToolkit.get_metadata(outer) == "test"
sys = complete(outer)
@test ModelingToolkit.get_metadata(sys) == "test"
end
end

0 comments on commit e4d5710

Please sign in to comment.