Skip to content

Commit f77febd

Browse files
Merge pull request #2435 from AayushSabharwal/as/deprecate-odaeproblem
feat!: deprecate ODAEProblem
2 parents ff8d231 + 77c1290 commit f77febd

File tree

13 files changed

+33
-159
lines changed

13 files changed

+33
-159
lines changed

docs/src/basics/Composition.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ sol[reqn.R]
254254

255255
## Tearing Problem Construction
256256

257-
Some system types, specifically `ODESystem` and `NonlinearSystem`, can be further
257+
Some system types (specifically `NonlinearSystem`) can be further
258258
reduced if `structural_simplify` has already been applied to them. This is done
259-
by using the alternative problem constructors, `ODAEProblem` and `BlockNonlinearProblem`
260-
respectively. In these cases, the constructor uses the knowledge of the
259+
by using the alternative problem constructors (`BlockNonlinearProblem`).
260+
In these cases, the constructor uses the knowledge of the
261261
strongly connected components calculated during the process of simplification
262262
as the basis for building pre-simplified nonlinear systems in the implicit
263263
solving. In summary: these problems are structurally modified, but could be

docs/src/examples/modelingtoolkitize_index_reduction.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tspan = (0, 10.0)
3030
pendulum_prob = ODEProblem(pendulum_fun!, u0, tspan, p)
3131
traced_sys = modelingtoolkitize(pendulum_prob)
3232
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
33-
prob = ODAEProblem(pendulum_sys, [], tspan)
33+
prob = ODEProblem(pendulum_sys, [], tspan)
3434
sol = solve(prob, Tsit5(), abstol = 1e-8, reltol = 1e-8)
3535
plot(sol, idxs = unknowns(traced_sys))
3636
```
@@ -162,20 +162,3 @@ variables which are symbolically eliminated, or any variable reordering
162162
done for enhanced parallelism/performance, still show up in the resulting
163163
plot and the plot is shown in the same order as the original numerical
164164
code.
165-
166-
Note that we can even go a bit further. If we use the `ODAEProblem`
167-
constructor, we can remove the algebraic equations from the unknowns of the
168-
system and fully transform the index-3 DAE into an index-0 ODE which can
169-
be solved via an explicit Runge-Kutta method:
170-
171-
```@example indexred
172-
traced_sys = modelingtoolkitize(pendulum_prob)
173-
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
174-
prob = ODAEProblem(pendulum_sys, Pair[], tspan)
175-
sol = solve(prob, Tsit5(), abstol = 1e-8, reltol = 1e-8)
176-
plot(sol, idxs = unknowns(traced_sys))
177-
```
178-
179-
And there you go: this has transformed the model from being too hard to
180-
solve with implicit DAE solvers, to something that is easily solved with
181-
explicit Runge-Kutta methods for non-stiff equations.

docs/src/examples/tearing_parallelism.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ is that, your attempts to parallelize are neigh: performing parallelism after
173173
structural simplification greatly improves the problem that can be parallelized,
174174
so this is better than trying to do it by hand.
175175

176-
After performing this, you can construct the `ODEProblem`/`ODAEProblem` and set
176+
After performing this, you can construct the `ODEProblem` and set
177177
`parallel_form` to use the exposed parallelism in multithreaded function
178178
constructions, but this showcases why `structural_simplify` is so important
179179
to that process.

docs/src/systems/ODESystem.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ ODEProblem(sys::ModelingToolkit.AbstractODESystem, args...)
5353
SteadyStateProblem(sys::ModelingToolkit.AbstractODESystem, args...)
5454
```
5555

56-
## Torn Problem Constructors
57-
58-
```@docs
59-
ODAEProblem
60-
```
61-
6256
## Expression Constructors
6357

6458
```@docs

src/structural_transformation/codegen.jl

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -505,50 +505,7 @@ function build_observed_function(state, ts, var_eq_matching, var_sccs,
505505
expression ? ex : drop_expr(@RuntimeGeneratedFunction(ex))
506506
end
507507

508-
"""
509-
ODAEProblem{iip}(sys, u0map, tspan, parammap = DiffEqBase.NullParameters(); kw...)
510-
511-
This constructor acts similar to the one for [`ODEProblem`](@ref) with the following changes:
512-
`ODESystem`s can sometimes be further reduced if `structural_simplify` has
513-
already been applied to them.
514-
In these cases, the constructor uses the knowledge of the strongly connected
515-
components calculated during the process of simplification as the basis for
516-
building pre-simplified nonlinear systems in the implicit solving.
517-
518-
In summary: these problems are structurally modified, but could be
519-
more efficient and more stable. Note, the returned object is still of type
520-
[`ODEProblem`](@ref).
521-
"""
522508
struct ODAEProblem{iip} end
523509

524-
ODAEProblem(args...; kw...) = ODAEProblem{true}(args...; kw...)
525-
526-
function ODAEProblem{iip}(sys,
527-
u0map,
528-
tspan,
529-
parammap = DiffEqBase.NullParameters();
530-
callback = nothing,
531-
use_union = true,
532-
tofloat = true,
533-
check = true,
534-
kwargs...) where {iip}
535-
eqs = equations(sys)
536-
check && ModelingToolkit.check_operator_variables(eqs, Differential)
537-
fun, dvs = build_torn_function(sys; kwargs...)
538-
ps = parameters(sys)
539-
defs = defaults(sys)
540-
541-
defs = ModelingToolkit.mergedefaults(defs, parammap, ps)
542-
defs = ModelingToolkit.mergedefaults(defs, u0map, dvs)
543-
u0 = ModelingToolkit.varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true)
544-
p = ModelingToolkit.varmap_to_vars(parammap, ps; defaults = defs, tofloat, use_union)
545-
546-
cbs = process_events(sys; callback, kwargs...)
547-
548-
kwargs = filter_kwargs(kwargs)
549-
if cbs === nothing
550-
ODEProblem{iip}(fun, u0, tspan, p; kwargs...)
551-
else
552-
ODEProblem{iip}(fun, u0, tspan, p; callback = cbs, kwargs...)
553-
end
554-
end
510+
@deprecate ODAEProblem(args...; kw...) ODEProblem(args...; kw...)
511+
@deprecate ODAEProblem{iip}(args...; kw...) where {iip} ODEProblem{iip}(args...; kw...)

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ struct ODESystem <: AbstractODESystem
135135
"""
136136
discrete_subsystems::Any
137137
"""
138-
A list of actual unknowns needed to be solved by solvers. Only
139-
used for ODAEProblem.
138+
A list of actual unknowns needed to be solved by solvers.
140139
"""
141140
solved_unknowns::Union{Nothing, Vector{Any}}
142141
"""

test/components.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ u0 = [capacitor.v => 0.0
5252
prob = ODEProblem(sys, u0, (0, 10.0))
5353
sol = solve(prob, Rodas4())
5454
check_rc_sol(sol)
55-
prob = ODAEProblem(sys, u0, (0, 10.0))
55+
prob = ODEProblem(sys, u0, (0, 10.0))
5656
sol = solve(prob, Rodas4())
5757
check_rc_sol(sol)
5858

@@ -80,7 +80,7 @@ let
8080
params = [param_r1 => 1.0, param_c1 => 1.0]
8181
tspan = (0.0, 10.0)
8282

83-
prob = ODAEProblem(sys, u0, tspan, params)
83+
prob = ODEProblem(sys, u0, tspan, params)
8484
@test solve(prob, Tsit5()).retcode == ReturnCode.Success
8585
end
8686

@@ -97,8 +97,8 @@ let
9797
@named rc_model2 = compose(_rc_model2,
9898
[resistor, resistor2, capacitor, source, ground])
9999
sys2 = structural_simplify(rc_model2)
100-
prob2 = ODAEProblem(sys2, u0, (0, 10.0))
101-
sol2 = solve(prob2, Tsit5())
100+
prob2 = ODEProblem(sys2, u0, (0, 10.0))
101+
sol2 = solve(prob2, Rosenbrock23())
102102
@test sol2[source.p.i] sol2[rc_model2.source.p.i] -sol2[capacitor.i]
103103
end
104104

@@ -138,7 +138,7 @@ sol_inner_outer = solve(prob, Rodas4())
138138
u0 = [
139139
capacitor.v => 0.0,
140140
]
141-
prob = ODAEProblem(sys, u0, (0, 10.0))
141+
prob = ODEProblem(sys, u0, (0, 10.0))
142142
sol = solve(prob, Tsit5())
143143

144144
@test sol[resistor.p.i] == sol[capacitor.p.i]
@@ -155,7 +155,6 @@ sys = structural_simplify(ll_model)
155155
@test length(equations(sys)) == 2
156156
u0 = unknowns(sys) .=> 0
157157
@test_nowarn ODEProblem(sys, u0, (0, 10.0))
158-
@test_nowarn ODAEProblem(sys, u0, (0, 10.0))
159158
prob = DAEProblem(sys, Differential(t).(unknowns(sys)) .=> 0, u0, (0, 0.5))
160159
sol = solve(prob, DFBDF())
161160
@test sol.retcode == SciMLBase.ReturnCode.Success
@@ -294,5 +293,5 @@ rc_eqs = [connect(capacitor.n, resistor.p)
294293
@named rc_model = compose(_rc_model,
295294
[resistor, capacitor, ground])
296295
sys = structural_simplify(rc_model)
297-
prob = ODAEProblem(sys, u0, (0, 10.0))
296+
prob = ODEProblem(sys, u0, (0, 10.0))
298297
sol = solve(prob, Tsit5())

test/odaeproblem.jl

Lines changed: 0 additions & 59 deletions
This file was deleted.

test/odesystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ let
935935
der = Differential(t)
936936
@named sys4 = ODESystem([der(x) ~ -y; der(y) ~ 1 + pp * y + x], t)
937937
sys4s = structural_simplify(sys4)
938-
prob = ODAEProblem(sys4s, [x => 1.0, D(x) => 1.0], (0, 1.0))
938+
prob = ODEProblem(sys4s, [x => 1.0, D(x) => 1.0], (0, 1.0))
939939
@test string.(unknowns(prob.f.sys)) == ["x(t)", "y(t)"]
940940
@test string.(parameters(prob.f.sys)) == ["pp"]
941941
@test string.(independent_variables(prob.f.sys)) == ["t"]
@@ -988,7 +988,7 @@ let
988988
der = Differential(t)
989989
@named sys4 = ODESystem([der(x) ~ -y; der(y) ~ 1 + pp * y + x], t)
990990
sys4s = structural_simplify(sys4)
991-
prob = ODAEProblem(sys4s, [x => 1.0, D(x) => 1.0], (0, 1.0))
991+
prob = ODEProblem(sys4s, [x => 1.0, D(x) => 1.0], (0, 1.0))
992992
@test !isnothing(prob.f.sys)
993993
end
994994

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ end
3535
@safetestset "Constraints Test" include("constraints.jl")
3636
@safetestset "Reduction Test" include("reduction.jl")
3737
@safetestset "Split Parameters Test" include("split_parameters.jl")
38-
@safetestset "ODAEProblem Test" include("odaeproblem.jl")
3938
@safetestset "StaticArrays Test" include("static_arrays.jl")
4039
@safetestset "Components Test" include("components.jl")
4140
@safetestset "Model Parsing Test" include("model_parsing.jl")

test/state_selection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let
127127
D(return_pipe.fluid_port_a.m) => 0.0,
128128
D(supply_pipe.fluid_port_a.m) => 0.0]
129129
prob1 = ODEProblem(sys, u0, (0.0, 10.0), [])
130-
prob2 = ODAEProblem(sys, u0, (0.0, 10.0), [])
130+
prob2 = ODEProblem(sys, u0, (0.0, 10.0), [])
131131
prob3 = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, u0, (0.0, 10.0), [])
132132
@test solve(prob1, FBDF()).retcode == ReturnCode.Success
133133
#@test solve(prob2, FBDF()).retcode == ReturnCode.Success
@@ -194,9 +194,9 @@ let
194194
mo_3 => 2
195195
Ek_3 => 3]
196196
prob1 = ODEProblem(sys, u0, (0.0, 0.1))
197-
prob2 = ODAEProblem(sys, u0, (0.0, 0.1))
197+
prob2 = ODEProblem(sys, u0, (0.0, 0.1))
198198
@test solve(prob1, FBDF()).retcode == ReturnCode.Success
199-
@test_broken solve(prob2, FBDF()).retcode == ReturnCode.Success
199+
@test solve(prob2, FBDF()).retcode == ReturnCode.Success
200200
end
201201

202202
let

test/structural_transformation/tearing.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,36 @@ newdaesys = structural_simplify(daesys)
155155
@test equations(newdaesys) == [D(x) ~ z; 0 ~ y + sin(z) - p * t]
156156
@test equations(tearing_substitution(newdaesys)) == [D(x) ~ z; 0 ~ x + sin(z) - p * t]
157157
@test isequal(unknowns(newdaesys), [x, z])
158-
prob = ODAEProblem(newdaesys, [x => 1.0], (0, 1.0), [p => 0.2])
159-
du = [0.0];
160-
u = [1.0];
158+
@test isequal(states(newdaesys), [x, z])
159+
@test_deprecated ODAEProblem(newdaesys, [x => 1.0, z => -0.5π], (0, 1.0), [p => 0.2])
160+
prob = ODEProblem(newdaesys, [x => 1.0, z => -0.5π], (0, 1.0), [p => 0.2])
161+
du = [0.0, 0.0];
162+
u = [1.0, -0.5π];
161163
pr = 0.2;
162164
tt = 0.1;
163165
@test_skip (@ballocated $(prob.f)($du, $u, $pr, $tt)) == 0
164166
prob.f(du, u, pr, tt)
165-
@test du[-asin(u[1] - pr * tt)] atol=1e-5
167+
@test du [u[2], u[1] + sin(u[2]) - pr * tt] atol=1e-5
166168

167169
# test the initial guess is respected
168170
@named sys = ODESystem(eqs, t, defaults = Dict(z => Inf))
169-
infprob = ODAEProblem(structural_simplify(sys), [x => 1.0], (0, 1.0), [p => 0.2])
170-
@test_throws Any infprob.f(du, u, pr, tt)
171+
infprob = ODEProblem(structural_simplify(sys), [x => 1.0], (0, 1.0), [p => 0.2])
172+
@test_throws Any infprob.f(du, infprob.u0, pr, tt)
171173

172-
sol1 = solve(prob, Tsit5())
174+
sol1 = solve(prob, RosShamp4(), reltol=8e-7)
173175
sol2 = solve(ODEProblem{false}((u, p, t) -> [-asin(u[1] - pr * t)],
174176
[1.0],
175177
(0, 1.0),
176178
0.2), Tsit5(), tstops = sol1.t, adaptive = false)
177-
@test Array(sol1)Array(sol2) atol=1e-5
179+
@test Array(sol1[x])Array(sol2[1, :]) atol=1e-5
178180

179181
@test sol1[x] == first.(sol1.u)
180182
@test sol1[y] == first.(sol1.u)
181-
@test sin.(sol1[z]) .+ sol1[y]pr[1] * sol1.t atol=1e-5
183+
@test sin.(sol1[z]) .+ sol1[y]pr[1] * sol1.t atol=5e-5
182184
@test sol1[sin(z) + y]sin.(sol1[z]) .+ sol1[y] rtol=1e-12
183185

184186
@test sol1[y, :] == sol1[x, :]
185-
@test (@. sin(sol1[z, :]) + sol1[y, :])pr * sol1.t atol=1e-5
187+
@test (@. sin(sol1[z, :]) + sol1[y, :])pr * sol1.t atol=5e-5
186188

187189
# 1426
188190
function Translational_Mass(; name, m = 1.0)
@@ -214,6 +216,6 @@ u0 = [mass.s => 0.0
214216
sys = structural_simplify(ms_model)
215217
@test ModelingToolkit.get_jac(sys)[] === ModelingToolkit.EMPTY_JAC
216218
@test ModelingToolkit.get_tgrad(sys)[] === ModelingToolkit.EMPTY_TGRAD
217-
prob_complex = ODAEProblem(sys, u0, (0, 1.0))
219+
prob_complex = ODEProblem(sys, u0, (0, 1.0))
218220
sol = solve(prob_complex, Tsit5())
219221
@test all(sol[mass.v] .== 1)

test/symbolic_events.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ eq = [vs ~ sin(2pi * t)
292292
ev = [sin(20pi * t) ~ 0.0] => [vmeasured ~ v]
293293
@named sys = ODESystem(eq, continuous_events = ev)
294294
sys = structural_simplify(sys)
295-
prob = ODAEProblem(sys, zeros(2), (0.0, 5.1))
295+
prob = ODEProblem(sys, zeros(2), (0.0, 5.1))
296296
sol = solve(prob, Tsit5())
297297
@test all(minimum((0:0.1:5) .- sol.t', dims = 2) .< 0.0001) # test that the solver stepped every 0.1s as dictated by event
298298
@test sol([0.25])[vmeasured][] == sol([0.23])[vmeasured][] # test the hold property

0 commit comments

Comments
 (0)