Skip to content

Commit 4f68c98

Browse files
test: update several tests to MTKv9, fix minor bug
1 parent 579b5ba commit 4f68c98

File tree

9 files changed

+37
-47
lines changed

9 files changed

+37
-47
lines changed

src/scimlfunctions.jl

Lines changed: 1 addition & 1 deletion
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}

test/downstream/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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"

test/downstream/ensemble_multi_prob.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
23

3-
@variables t, x(t), y(t)
4-
D = Differential(t)
4+
@variables x(t), y(t)
55

66
@named sys1 = ODESystem([D(x) ~ x,
7-
D(y) ~ -y])
7+
D(y) ~ -y], t)
88
@named sys2 = ODESystem([D(x) ~ 2x,
9-
D(y) ~ -2y])
9+
D(y) ~ -2y], t)
1010
@named sys3 = ODESystem([D(x) ~ 3x,
11-
D(y) ~ -3y])
11+
D(y) ~ -3y], t)
1212

13-
prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0))
14-
prob2 = ODEProblem(sys2, [2.0, 2.0], (0.0, 1.0))
15-
prob3 = ODEProblem(sys3, [3.0, 3.0], (0.0, 1.0))
13+
prob1 = ODEProblem(complete(sys1), [1.0, 1.0], (0.0, 1.0))
14+
prob2 = ODEProblem(complete(sys2), [2.0, 2.0], (0.0, 1.0))
15+
prob3 = ODEProblem(complete(sys3), [3.0, 3.0], (0.0, 1.0))
1616

1717
# test that when passing a vector of problems, trajectories and the prob_func are chosen appropriately
1818
ensemble_prob = EnsembleProblem([prob1, prob2, prob3])

test/downstream/integrator_indexing.jl

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

45
### Tests on non-layered model (everything should work). ###
56

6-
@parameters t a b c d
7+
@parameters a b c d
78
@variables s1(t) s2(t)
8-
D = Differential(t)
99

1010
eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1111
D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2]
@@ -119,9 +119,8 @@ integrator[noisy_population_model.s2] = 10.0
119119
integrator[:s1] = 1.0
120120
@test integrator[s1] == integrator[noisy_population_model.s1] == integrator[:s1] == 1.0
121121

122-
@parameters t σ ρ β
122+
@parameters σ ρ β
123123
@variables x(t) y(t) z(t)
124-
D = Differential(t)
125124

126125
eqs = [D(x) ~ σ * (y - x),
127126
D(y) ~ x *- z) - y,
@@ -327,10 +326,8 @@ plot(sol,idxs=(t,α))
327326
=#
328327

329328
using LinearAlgebra
330-
@variables t
331329
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
332330
ps = @parameters p[1:3] = [1, 2, 3]
333-
D = Differential(t)
334331
eqs = [collect(D.(x) .~ x)
335332
D(y) ~ norm(x) * y - x[1]]
336333
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])

test/downstream/problem_interface.jl

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

45
@parameters σ ρ β
5-
@variables t x(t) y(t) z(t)
6-
D = Differential(t)
6+
@variables x(t) y(t) z(t)
77

88
eqs = [D(D(x)) ~ σ * (y - x),
99
D(y) ~ x *- z) - y,
1010
D(z) ~ x * y - β * z]
1111

12-
@named sys = ODESystem(eqs)
12+
@named sys = ODESystem(eqs, t)
1313

1414
sys = structural_simplify(sys)
1515

@@ -181,10 +181,8 @@ set_tuple!(sprob, [10.0, 10.0])
181181
@test get_tuple(sprob) == (10.0, 10.0)
182182

183183
using LinearAlgebra
184-
@variables t
185184
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
186185
ps = @parameters p[1:3] = [1, 2, 3]
187-
D = Differential(t)
188186
eqs = [collect(D.(x) .~ x)
189187
D(y) ~ norm(x) * y - x[1]]
190188
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])

test/downstream/remake_autodiff.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using OrdinaryDiffEq, ModelingToolkit, Zygote, SciMLSensitivity
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
23

3-
@variables t x(t) o(t)
4-
D = Differential(t)
4+
@variables x(t) o(t)
55
function lotka_volterra(; name = name)
66
unknowns = @variables x(t)=1.0 y(t)=1.0 o(t)
77
params = @parameters p1=1.5 p2=1.0 p3=3.0 p4=1.0

test/downstream/solution_interface.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, Test
2-
# compat for MTKv8 and v9
3-
unknowns = isdefined(ModelingToolkit, :states) ? ModelingToolkit.states :
4-
ModelingToolkit.unknowns
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
53

64
### Tests on non-layered model (everything should work). ###
75

8-
@parameters t a b c d
6+
@parameters a b c d
97
@variables s1(t) s2(t)
10-
D = Differential(t)
118

129
eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1310
D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2]
1411

15-
@named population_model = ODESystem(eqs)
12+
@mtkbuild population_model = ODESystem(eqs, t)
1613

1714
# Tests on ODEProblem.
1815
u0 = [s1 => 2.0, s2 => 1.0]
@@ -32,6 +29,7 @@ sol = solve(oprob, Rodas4())
3229
noiseeqs = [0.1 * s1,
3330
0.1 * s2]
3431
@named noisy_population_model = SDESystem(population_model, noiseeqs)
32+
noisy_population_model = complete(noisy_population_model)
3533
sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p)
3634
sol = solve(sprob, ImplicitEM())
3735

@@ -42,16 +40,15 @@ sol = solve(sprob, ImplicitEM())
4240
@test_throws Exception sol[:a]
4341
### Tests on layered model (some things should not work). ###
4442

45-
@parameters t σ ρ β
43+
@parameters σ ρ β
4644
@variables x(t) y(t) z(t)
47-
D = Differential(t)
4845

4946
eqs = [D(x) ~ σ * (y - x),
5047
D(y) ~ x *- z) - y,
5148
D(z) ~ x * y - β * z]
5249

53-
@named lorenz1 = ODESystem(eqs)
54-
@named lorenz2 = ODESystem(eqs)
50+
@named lorenz1 = ODESystem(eqs, t)
51+
@named lorenz2 = ODESystem(eqs, t)
5552

5653
@parameters γ
5754
@variables a(t) α(t)

test/downstream/symbol_indexing.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, SymbolicIndexingInterface, Test
22
using Optimization, OptimizationOptimJL
3-
# compat for MTKv8 and v9
4-
unknowns = isdefined(ModelingToolkit, :states) ? ModelingToolkit.states :
5-
ModelingToolkit.unknowns
3+
using ModelingToolkit: t_nounits as t, D_nounits as D
64

7-
@parameters t σ ρ β
5+
@parameters σ ρ β
86
@variables x(t) y(t) z(t)
9-
D = Differential(t)
107

118
eqs = [D(x) ~ σ * (y - x),
129
D(y) ~ x *- z) - y,
1310
D(z) ~ x * y - β * z]
1411

15-
@named lorenz1 = ODESystem(eqs)
16-
@named lorenz2 = ODESystem(eqs)
12+
@named lorenz1 = ODESystem(eqs, t)
13+
@named lorenz2 = ODESystem(eqs, t)
1714

1815
@parameters γ
1916
@variables a(t) α(t)
@@ -106,7 +103,7 @@ eqs = [D(q[1]) ~ 2q[1]
106103
D(q[2]) ~ 2.0]
107104
@named sys2 = ODESystem(eqs, t, [q...], [])
108105
sys2_simplified = structural_simplify(sys2)
109-
prob2 = ODEProblem(sys2, [], (0.0, 5.0))
106+
prob2 = ODEProblem(sys2_simplified, [], (0.0, 5.0))
110107
sol2 = solve(prob2, Tsit5())
111108

112109
@test sol2[q] isa Vector{Vector{Float64}}
@@ -218,13 +215,12 @@ plot(sol,idxs=(t,α))
218215
=#
219216

220217
using LinearAlgebra
221-
@variables t
222218
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
223219
ps = @parameters p[1:3] = [1, 2, 3]
224-
D = Differential(t)
225220
eqs = [collect(D.(x) .~ x)
226221
D(y) ~ norm(x) * y - x[1]]
227222
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])
223+
sys = complete(sys)
228224
prob = ODEProblem(sys, [], (0, 1.0))
229225
sol = solve(prob, Tsit5())
230226
@test sol[x] isa Vector{<:Vector}
@@ -342,11 +338,11 @@ for (sym, oldval, newval, check_inference) in [
342338
end
343339

344340
# accessing parameters
345-
@variables t x(t)
341+
@variables x(t)
346342
@parameters tau
347-
D = Differential(t)
348343

349-
@named fol = ODESystem([D(x) ~ (1 - x) / tau])
344+
@named fol = ODESystem([D(x) ~ (1 - x) / tau], t)
345+
fol = complete(fol)
350346
prob = ODEProblem(fol, [x => 0.0], (0.0, 10.0), [tau => 3.0])
351347
sol = solve(prob, Tsit5())
352348
@test getp(fol, tau)(sol) == 3
@@ -359,6 +355,7 @@ sol = solve(prob, Tsit5())
359355
@parameters a=1 b=1
360356
loss = (a - x)^2 + b * (y - x^2)^2
361357
@named sys = OptimizationSystem(loss, [x, y], [a, b])
358+
sys = complete(sys)
362359
u0 = [x => 1.0
363360
y => 2.0]
364361
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)