|
2 | 2 |
|
3 | 3 | # Fetch packages
|
4 | 4 | using ModelingToolkit, JumpProcesses, NonlinearSolve, OrdinaryDiffEq, StaticArrays,
|
5 |
| - SteadyStateDiffEq, StochasticDiffEq, Test |
| 5 | + SteadyStateDiffEq, StochasticDiffEq, SciMLBase, Test |
6 | 6 | using ModelingToolkit: t_nounits as t, D_nounits as D
|
7 | 7 |
|
8 | 8 | # Sets rnd number.
|
@@ -101,7 +101,7 @@ begin
|
101 | 101 | end
|
102 | 102 |
|
103 | 103 | # Perform ODE simulations (singular and ensemble).
|
104 |
| -let |
| 104 | +@testset "ODE" begin |
105 | 105 | # Creates normal and ensemble problems.
|
106 | 106 | base_oprob = ODEProblem(osys, [u0_alts[1]; p_alts[1]], tspan)
|
107 | 107 | base_sol = solve(base_oprob, Tsit5(); saveat = 1.0)
|
|
119 | 119 | end
|
120 | 120 |
|
121 | 121 | # Solves a nonlinear problem (EnsembleProblems are not possible for these).
|
122 |
| -let |
| 122 | +@testset "Nonlinear" begin |
123 | 123 | base_nlprob = NonlinearProblem(nsys, [u0_alts[1]; p_alts[1]])
|
124 | 124 | base_sol = solve(base_nlprob, NewtonRaphson())
|
125 | 125 | # Solves problems for all input types, checking that identical solutions are found.
|
|
130 | 130 | end
|
131 | 131 |
|
132 | 132 | # Perform steady state simulations (singular and ensemble).
|
133 |
| -let |
| 133 | +@testset "SteadyState" begin |
134 | 134 | # Creates normal and ensemble problems.
|
135 | 135 | base_ssprob = SteadyStateProblem(osys, [u0_alts[1]; p_alts[1]])
|
136 | 136 | base_sol = solve(base_ssprob, DynamicSS(Tsit5()))
|
|
146 | 146 | @test base_esol == solve(eprob, DynamicSS(Tsit5()); trajectories = 2)
|
147 | 147 | end
|
148 | 148 | 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