Skip to content

Commit 69142fa

Browse files
Merge pull request #3806 from AayushSabharwal/as/odesystem-type
feat: make deprecated `ODESystem` alias `System` type
2 parents 12d356d + 2a3a9ab commit 69142fa

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/ModelingToolkit.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ $(TYPEDEF)
138138
TODO
139139
"""
140140
abstract type AbstractSystem end
141+
# Solely so that `ODESystem` can be deprecated and still act as a valid type.
142+
# See `deprecations.jl`.
143+
abstract type IntermediateDeprecationSystem <: AbstractSystem end
141144

142145
function independent_variable end
143146

@@ -275,7 +278,7 @@ PrecompileTools.@compile_workload begin
275278
end
276279

277280
export ODEFunction, convert_system_indepvar,
278-
System, OptimizationSystem, JumpSystem, SDESystem, NonlinearSystem
281+
System, OptimizationSystem, JumpSystem, SDESystem, NonlinearSystem, ODESystem
279282
export SDEFunction
280283
export SystemStructure
281284
export DiscreteProblem, DiscreteFunction

src/deprecations.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ macro mtkbuild(exprs...)
99
end |> esc
1010
end
1111

12-
for T in [:ODESystem, :NonlinearSystem, :DiscreteSystem, :ImplicitDiscreteSystem]
12+
const ODESystem = IntermediateDeprecationSystem
13+
14+
function IntermediateDeprecationSystem(args...; kwargs...)
15+
Base.depwarn("`ODESystem(args...; kwargs...)` is deprecated. Use `System(args...; kwargs...) instead`.", :ODESystem)
16+
17+
return System(args...; kwargs...)
18+
end
19+
20+
for T in [:NonlinearSystem, :DiscreteSystem, :ImplicitDiscreteSystem]
1321
@eval @deprecate $T(args...; kwargs...) System(args...; kwargs...)
1422
end
1523

src/systems/system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ structure.
2424
2525
$(TYPEDFIELDS)
2626
"""
27-
struct System <: AbstractSystem
27+
struct System <: IntermediateDeprecationSystem
2828
"""
2929
$INTERNAL_FIELD_WARNING
3030
A unique integer tag for the system.

test/odesystem.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,3 +1600,17 @@ end
16001600
@test getmetadata(sys, TestMeta, nothing) == "test"
16011601
@test getmetadata(sys2, TestMeta, nothing) == "test"
16021602
end
1603+
1604+
struct TestWrapper
1605+
sys::ODESystem
1606+
end
1607+
1608+
@testset "`ODESystem` is a type" begin
1609+
@variables x(t)
1610+
@named sys = ODESystem(D(x) ~ x, t)
1611+
@test sys isa ODESystem
1612+
@test sys isa System
1613+
arr = ODESystem[]
1614+
@test_nowarn push!(arr, sys)
1615+
@test_nowarn TestWrapper(sys)
1616+
end

0 commit comments

Comments
 (0)