Skip to content

Commit e5e1172

Browse files
test: update several tests to MTKv9, fix minor bug
1 parent c2c0c29 commit e5e1172

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

src/scimlfunctions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ function ODEFunction{iip, specialize}(f;
22932293

22942294
_f = prepare_function(f)
22952295

2296-
sys = something(sys, SymbolCache(syms, paramsyms, indepsym))
2296+
sys = sys_or_symbolcache(sys, syms, paramsyms, indepsym)
22972297

22982298
@assert typeof(initializeprob) <:
22992299
Union{Nothing, NonlinearProblem, NonlinearLeastSquaresProblem}
@@ -3897,7 +3897,7 @@ end
38973897
function sys_or_symbolcache(sys, syms, paramsyms, indepsym = nothing)
38983898
if sys === nothing &&
38993899
(syms !== nothing || paramsyms !== nothing || indepsym !== nothing)
3900-
error("The use of keyword arguments `syms`, `paramsyms` and `indepsym` for `SciMLFunction`s is deprecated. Pass `sys = SymbolCache(syms, paramsyms, indepsym)` instead.")
3900+
Base.depwarn("The use of keyword arguments `syms`, `paramsyms` and `indepsym` for `SciMLFunction`s is deprecated. Pass `sys = SymbolCache(syms, paramsyms, indepsym)` instead.", :syms)
39013901
sys = SymbolCache(syms, paramsyms, indepsym)
39023902
end
39033903
return sys

test/downstream/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
44
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
55
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
66
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
7+
OptimizationMOI = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
78
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
89
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
910
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
1011
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1112
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
13+
SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226"
1214
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
1315
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
1416
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
@@ -25,6 +27,7 @@ OrdinaryDiffEq = "6.33"
2527
RecursiveArrayTools = "3"
2628
SciMLBase = "2"
2729
SciMLSensitivity = "7.11"
30+
SciMLStructures = "1.1"
2831
Sundials = "4.11"
2932
SymbolicIndexingInterface = "0.3"
3033
Unitful = "1.12"

test/downstream/integrator_indexing.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq,
22
SymbolicIndexingInterface, Test
33
using ModelingToolkit: t_nounits as t, D_nounits as D
4+
using SciMLStructures: canonicalize, Tunable
45
### Tests on non-layered model (everything should work). ###
56

67
@parameters a b c d
@@ -9,8 +10,8 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
910
eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1011
D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2]
1112

12-
@named population_model = ODESystem(eqs, t)
13-
13+
@named pop_model = ODESystem(eqs, t)
14+
population_model = complete(pop_model)
1415
# Tests on ODEProblem.
1516
u0 = [s1 => 2.0, s2 => 1.0]
1617
p = [a => 2.0, b => 1.0, c => 1.0, d => 1.0]
@@ -81,7 +82,8 @@ integrator[:s1] = 1.0
8182
# Tests on SDEProblem
8283
noiseeqs = [0.1 * s1,
8384
0.1 * s2]
84-
@named noisy_population_model = SDESystem(population_model, noiseeqs)
85+
@named noisy_population_model = SDESystem(pop_model, noiseeqs)
86+
noisy_population_model = complete(noisy_population_model)
8587
sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p)
8688
integrator = init(sprob, ImplicitEM())
8789

@@ -120,7 +122,6 @@ integrator[:s1] = 1.0
120122

121123
@parameters σ ρ β
122124
@variables x(t) y(t) z(t)
123-
D = Differential(t)
124125

125126
eqs = [D(x) ~ σ * (y - x),
126127
D(y) ~ x *- z) - y,
@@ -133,9 +134,8 @@ eqs = [D(x) ~ σ * (y - x),
133134
@variables a(t) α(t)
134135
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ,
135136
α ~ 2lorenz1.x + a * γ]
136-
@mtkbuild sys_simplified = ODESystem(
137+
@mtkbuild sys = ODESystem(
137138
connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
138-
sys_simplified = complete(structural_simplify(sys))
139139

140140
u0 = [lorenz1.x => 1.0,
141141
lorenz1.y => 0.0,
@@ -154,7 +154,7 @@ p = [lorenz1.σ => 10.0,
154154
γ => 2.0]
155155

156156
tspan = (0.0, 100.0)
157-
prob = ODEProblem(sys_simplified, u0, tspan, p)
157+
prob = ODEProblem(sys, u0, tspan, p)
158158
integrator = init(prob, Rodas4())
159159
step!(integrator, 100.0, true)
160160

@@ -185,8 +185,8 @@ step!(integrator, 100.0, true)
185185
eqs = [D(q[1]) ~ 2q[1]
186186
D(q[2]) ~ 2.0]
187187
@named sys2 = ODESystem(eqs, t, [q...], [])
188-
sys2_simplified = complete(structural_simplify(sys2))
189-
prob2 = ODEProblem(sys2, [], (0.0, 5.0))
188+
sys2_simplified = structural_simplify(sys2)
189+
prob2 = ODEProblem(sys2_simplified, [], (0.0, 5.0))
190190
integrator2 = init(prob2, Tsit5())
191191

192192
@test integrator2[q] isa Vector{Float64}
@@ -215,8 +215,9 @@ end
215215

216216
# Tests various interface methods:
217217
@test_throws Any getp(sys, σ)(integrator)
218-
@test in(getp(sys, lorenz1.σ)(integrator), integrator.p)
219-
@test in(getp(sys, lorenz2.σ)(integrator), integrator.p)
218+
tunable, _, _ = canonicalize(Tunable(), integrator.p)
219+
@test in(getp(sys, lorenz1.σ)(integrator), tunable)
220+
@test in(getp(sys, lorenz2.σ)(integrator), tunable)
220221
@test_throws Any getp(sol, )(sol)
221222

222223
@test_throws Any integrator[x]
@@ -329,7 +330,6 @@ plot(sol,idxs=(t,α))
329330
using LinearAlgebra
330331
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
331332
ps = @parameters p[1:3] = [1, 2, 3]
332-
D = Differential(t)
333333
eqs = [collect(D.(x) .~ x)
334334
D(y) ~ norm(x) * y - x[1]]
335335
@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;])

test/downstream/problem_interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ noiseeqs = [0.1 * x,
110110
0.1 * y,
111111
0.1 * z]
112112
@named noise_sys = SDESystem(sys, noiseeqs)
113+
noise_sys = complete(noise_sys)
113114
sprob = SDEProblem(noise_sys, u0, (0.0, 100.0), p)
114115
u0
115116

@@ -181,7 +182,6 @@ set_tuple!(sprob, [10.0, 10.0])
181182
using LinearAlgebra
182183
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
183184
ps = @parameters p[1:3] = [1, 2, 3]
184-
D = Differential(t)
185185
eqs = [collect(D.(x) .~ x)
186186
D(y) ~ norm(x) * y - x[1]]
187187
@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;])

test/downstream/remake_autodiff.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ using OrdinaryDiffEq, ModelingToolkit, Zygote, SciMLSensitivity
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33

44
@variables x(t) o(t)
5-
D = Differential(t)
65
function lotka_volterra(; name = name)
76
unknowns = @variables x(t)=1.0 y(t)=1.0 o(t)
87
params = @parameters p1=1.5 p2=1.0 p3=3.0 p4=1.0

test/downstream/solution_interface.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ sol = solve(oprob, Rodas4())
2929
noiseeqs = [0.1 * s1,
3030
0.1 * s2]
3131
@named noisy_population_model = SDESystem(population_model, noiseeqs)
32-
sprob = SDEProblem(complete(noisy_population_model), u0, (0.0, 100.0), p)
32+
noisy_population_model = complete(noisy_population_model)
33+
sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p)
3334
sol = solve(sprob, ImplicitEM())
3435

3536
@test sol[s1] == sol[noisy_population_model.s1] == sol[:s1]
@@ -46,8 +47,8 @@ eqs = [D(x) ~ σ * (y - x),
4647
D(y) ~ x *- z) - y,
4748
D(z) ~ x * y - β * z]
4849

49-
@named lorenz1 = ODESystem(eqs,t)
50-
@named lorenz2 = ODESystem(eqs,t)
50+
@named lorenz1 = ODESystem(eqs, t)
51+
@named lorenz2 = ODESystem(eqs, t)
5152

5253
@parameters γ
5354
@variables a(t) α(t)

test/downstream/symbol_indexing.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
44

55
@parameters σ ρ β
66
@variables x(t) y(t) z(t)
7-
D = Differential(t)
87

98
eqs = [D(x) ~ σ * (y - x),
109
D(y) ~ x *- z) - y,
1110
D(z) ~ x * y - β * z]
1211

13-
@named lorenz1 = ODESystem(eqs)
14-
@named lorenz2 = ODESystem(eqs)
12+
@named lorenz1 = ODESystem(eqs, t)
13+
@named lorenz2 = ODESystem(eqs, t)
1514

1615
@parameters γ
1716
@variables a(t) α(t)
@@ -103,7 +102,7 @@ eqs = [D(q[1]) ~ 2q[1]
103102
D(q[2]) ~ 2.0]
104103
@named sys2 = ODESystem(eqs, t, [q...], [])
105104
sys2_simplified = structural_simplify(sys2)
106-
prob2 = ODEProblem(sys2, [], (0.0, 5.0))
105+
prob2 = ODEProblem(sys2_simplified, [], (0.0, 5.0))
107106
sol2 = solve(prob2, Tsit5())
108107

109108
@test sol2[q] isa Vector{Vector{Float64}}
@@ -217,10 +216,10 @@ plot(sol,idxs=(t,α))
217216
using LinearAlgebra
218217
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
219218
ps = @parameters p[1:3] = [1, 2, 3]
220-
D = Differential(t)
221219
eqs = [collect(D.(x) .~ x)
222220
D(y) ~ norm(x) * y - x[1]]
223221
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])
222+
sys = complete(sys)
224223
prob = ODEProblem(sys, [], (0, 1.0))
225224
sol = solve(prob, Tsit5())
226225
@test sol[x] isa Vector{<:Vector}
@@ -340,9 +339,9 @@ end
340339
# accessing parameters
341340
@variables x(t)
342341
@parameters tau
343-
D = Differential(t)
344342

345-
@named fol = ODESystem([D(x) ~ (1 - x) / tau])
343+
@named fol = ODESystem([D(x) ~ (1 - x) / tau], t)
344+
fol = complete(fol)
346345
prob = ODEProblem(fol, [x => 0.0], (0.0, 10.0), [tau => 3.0])
347346
sol = solve(prob, Tsit5())
348347
@test getp(fol, tau)(sol) == 3
@@ -355,6 +354,7 @@ sol = solve(prob, Tsit5())
355354
@parameters a=1 b=1
356355
loss = (a - x)^2 + b * (y - x^2)^2
357356
@named sys = OptimizationSystem(loss, [x, y], [a, b])
357+
sys = complete(sys)
358358
u0 = [x => 1.0
359359
y => 2.0]
360360
p = [a => 1.0

test/traits.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SciMLBase, Test
22
using ModelingToolkit, OrdinaryDiffEq, DataFrames
3+
using ModelingToolkit: t_nounits as t, D_nounits as D
34

45
@test SciMLBase.Tables.isrowtable(ODESolution)
56
@test SciMLBase.Tables.isrowtable(RODESolution)
@@ -9,8 +10,7 @@ using ModelingToolkit, OrdinaryDiffEq, DataFrames
910
@test !SciMLBase.Tables.isrowtable(SciMLBase.QuadratureSolution)
1011
@test !SciMLBase.Tables.isrowtable(SciMLBase.OptimizationSolution)
1112

12-
@variables t x(t)=1
13-
D = Differential(t)
13+
@variables x(t)=1
1414
eqs = [D(x) ~ -x]
1515
@named sys = ODESystem(eqs, t)
1616
sys = complete(sys)

0 commit comments

Comments
 (0)