Skip to content

Commit 6081ad8

Browse files
test: test new deprecations
1 parent 24901fd commit 6081ad8

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed

test/sciml_problem_inputs.jl

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Fetch packages
44
using ModelingToolkit, JumpProcesses, NonlinearSolve, OrdinaryDiffEq, StaticArrays,
5-
SteadyStateDiffEq, StochasticDiffEq, Test
5+
SteadyStateDiffEq, StochasticDiffEq, SciMLBase, Test
66
using ModelingToolkit: t_nounits as t, D_nounits as D
77

88
# Sets rnd number.
@@ -101,7 +101,7 @@ begin
101101
end
102102

103103
# Perform ODE simulations (singular and ensemble).
104-
let
104+
@testset "ODE" begin
105105
# Creates normal and ensemble problems.
106106
base_oprob = ODEProblem(osys, [u0_alts[1]; p_alts[1]], tspan)
107107
base_sol = solve(base_oprob, Tsit5(); saveat = 1.0)
@@ -119,7 +119,7 @@ let
119119
end
120120

121121
# Solves a nonlinear problem (EnsembleProblems are not possible for these).
122-
let
122+
@testset "Nonlinear" begin
123123
base_nlprob = NonlinearProblem(nsys, [u0_alts[1]; p_alts[1]])
124124
base_sol = solve(base_nlprob, NewtonRaphson())
125125
# Solves problems for all input types, checking that identical solutions are found.
@@ -130,7 +130,7 @@ let
130130
end
131131

132132
# Perform steady state simulations (singular and ensemble).
133-
let
133+
@testset "SteadyState" begin
134134
# Creates normal and ensemble problems.
135135
base_ssprob = SteadyStateProblem(osys, [u0_alts[1]; p_alts[1]])
136136
base_sol = solve(base_ssprob, DynamicSS(Tsit5()))
@@ -146,3 +146,85 @@ let
146146
@test base_esol == solve(eprob, DynamicSS(Tsit5()); trajectories = 2)
147147
end
148148
end
149+
150+
@testset "Deprecations" begin
151+
@variables _x(..) = 1.0
152+
@parameters p = 1.0
153+
@brownian a
154+
x = _x(t)
155+
k = ShiftIndex(t)
156+
157+
@test_deprecated ODESystem([D(x) ~ x * p], t; name = :a)
158+
@mtkcompile odesys = System([D(x) ~ x * p], t)
159+
@mtkcompile sdesys = System([D(x) ~ x * p + a], t)
160+
@test_deprecated NonlinearSystem([0 ~ x^3 + p]; name = :a)
161+
@mtkcompile nlsys = System([0 ~ x^3 + p])
162+
@mtkcompile ddesys = System([D(x) ~ x * p + _x(t - 0.1)], t)
163+
@mtkcompile sddesys = System([D(x) ~ x * p + _x(t - 0.1) + a], t)
164+
@test_deprecated DiscreteSystem([x ~ x(k - 1) + x(k - 2)], t; name = :a)
165+
@mtkcompile discsys = System([x ~ x(k - 1) * p], t)
166+
@test_deprecated ImplicitDiscreteSystem([x ~ x(k - 1) + x(k - 2) * p * x], t; name = :a)
167+
@mtkcompile idiscsys = System([x ~ x(k - 1) * p * x], t)
168+
@mtkcompile optsys = OptimizationSystem(x^2 + p)
169+
170+
u0s = [
171+
Dict(x => 1.0),
172+
[x => 1.0],
173+
[1.0],
174+
[],
175+
nothing
176+
]
177+
ps = [
178+
Dict(p => 1.0),
179+
[p => 1.0],
180+
[1.0],
181+
[],
182+
nothing,
183+
SciMLBase.NullParameters()
184+
]
185+
tspan = (0.0, 1.0)
186+
187+
@testset "$ctor" for (sys, ctor) in [
188+
(odesys, ODEProblem),
189+
(odesys, ODEProblem{true}),
190+
(odesys, ODEProblem{true, SciMLBase.FullSpecialize}), (odesys, BVProblem),
191+
(odesys, BVProblem{true}),
192+
(odesys, BVProblem{true, SciMLBase.FullSpecialize}), (sdesys, SDEProblem),
193+
(sdesys, SDEProblem{true}),
194+
(sdesys, SDEProblem{true, SciMLBase.FullSpecialize}), (ddesys, DDEProblem),
195+
(ddesys, DDEProblem{true}),
196+
(ddesys, DDEProblem{true, SciMLBase.FullSpecialize}), (sddesys, SDDEProblem),
197+
(sddesys, SDDEProblem{true}),
198+
(sddesys, SDDEProblem{true, SciMLBase.FullSpecialize}),
199+
200+
# (discsys, DiscreteProblem),
201+
# (discsys, DiscreteProblem{true}),
202+
# (discsys, DiscreteProblem{true, SciMLBase.FullSpecialize}),
203+
204+
(idiscsys, ImplicitDiscreteProblem),
205+
(idiscsys, ImplicitDiscreteProblem{true}),
206+
(idiscsys, ImplicitDiscreteProblem{true, SciMLBase.FullSpecialize})
207+
]
208+
@testset "$(typeof(u0)) - $(typeof(p))" for u0 in u0s, p in ps
209+
if u0 isa Vector{Float64} && ctor <: ImplicitDiscreteProblem
210+
u0 = ones(2)
211+
end
212+
@test_deprecated ctor(sys, u0, tspan, p)
213+
end
214+
end
215+
@testset "$ctor" for (sys, ctor) in [
216+
(nlsys, NonlinearProblem),
217+
(nlsys, NonlinearProblem{true}),
218+
(nlsys, NonlinearProblem{true, SciMLBase.FullSpecialize}), (
219+
nlsys, NonlinearLeastSquaresProblem),
220+
(nlsys, NonlinearLeastSquaresProblem{true}),
221+
(nlsys, NonlinearLeastSquaresProblem{true, SciMLBase.FullSpecialize}), (
222+
nlsys, SCCNonlinearProblem),
223+
(nlsys, SCCNonlinearProblem{true}), (optsys, OptimizationProblem),
224+
(optsys, OptimizationProblem{true})
225+
]
226+
@testset "$(typeof(u0)) - $(typeof(p))" for u0 in u0s, p in ps
227+
@test_deprecated ctor(sys, u0, p)
228+
end
229+
end
230+
end

0 commit comments

Comments
 (0)