Skip to content

Commit 14b8690

Browse files
Fix downstream tests for MTK v9
1 parent 8a63727 commit 14b8690

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

test/downstream/ensemble_multi_prob.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
@variables x(t), y(t)
24

3-
@variables t, x(t), y(t)
4-
D = Differential(t)
5-
6-
@named sys1 = ODESystem([D(x) ~ x,
7-
D(y) ~ -y])
8-
@named sys2 = ODESystem([D(x) ~ 2x,
9-
D(y) ~ -2y])
10-
@named sys3 = ODESystem([D(x) ~ 3x,
11-
D(y) ~ -3y])
5+
@mtkbuild sys1 = ODESystem([D(x) ~ x,
6+
D(y) ~ -y],t)
7+
@mtkbuild sys2 = ODESystem([D(x) ~ 2x,
8+
D(y) ~ -2y],t)
9+
@mtkbuild sys3 = ODESystem([D(x) ~ 3x,
10+
D(y) ~ -3y],t)
1211

1312
prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0))
1413
prob2 = ODEProblem(sys2, [2.0, 2.0], (0.0, 1.0))

test/downstream/integrator_indexing.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq,
22
SymbolicIndexingInterface, Test
3-
3+
using ModelingToolkit: t_nounits as t, D_nounits as D
44
### Tests on non-layered model (everything should work). ###
55

6-
@parameters t a b c d
6+
@parameters a b c d
77
@variables s1(t) s2(t)
8-
D = Differential(t)
98

109
eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1110
D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2]
1211

13-
@named population_model = ODESystem(eqs)
12+
@named population_model = ODESystem(eqs,t)
1413

1514
# Tests on ODEProblem.
1615
u0 = [s1 => 2.0, s2 => 1.0]
@@ -127,15 +126,15 @@ eqs = [D(x) ~ σ * (y - x),
127126
D(y) ~ x *- z) - y,
128127
D(z) ~ x * y - β * z]
129128

130-
@named lorenz1 = ODESystem(eqs)
131-
@named lorenz2 = ODESystem(eqs)
129+
@named lorenz1 = ODESystem(eqs,t)
130+
@named lorenz2 = ODESystem(eqs,t)
132131

133132
@parameters γ
134133
@variables a(t) α(t)
135134
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ,
136135
α ~ 2lorenz1.x + a * γ]
137-
@named sys = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
138-
sys_simplified = structural_simplify(sys)
136+
@mtkbuild sys_simplified = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
137+
sys_simplified = complete(structural_simplify(sys))
139138

140139
u0 = [lorenz1.x => 1.0,
141140
lorenz1.y => 0.0,
@@ -185,7 +184,7 @@ step!(integrator, 100.0, true)
185184
eqs = [D(q[1]) ~ 2q[1]
186185
D(q[2]) ~ 2.0]
187186
@named sys2 = ODESystem(eqs, t, [q...], [])
188-
sys2_simplified = structural_simplify(sys2)
187+
sys2_simplified = complete(structural_simplify(sys2))
189188
prob2 = ODEProblem(sys2, [], (0.0, 5.0))
190189
integrator2 = init(prob2, Tsit5())
191190

@@ -198,7 +197,7 @@ integrator2 = init(prob2, Tsit5())
198197
@variables u(t)
199198
eqs = [D(u) ~ u]
200199

201-
@named sys2 = ODESystem(eqs)
200+
@mtkbuild sys2 = ODESystem(eqs,t)
202201

203202
tspan = (0.0, 5.0)
204203

@@ -333,7 +332,7 @@ ps = @parameters p[1:3] = [1, 2, 3]
333332
D = Differential(t)
334333
eqs = [collect(D.(x) .~ x)
335334
D(y) ~ norm(x) * y - x[1]]
336-
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])
335+
@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;])
337336
prob = ODEProblem(sys, [], (0, 1.0))
338337
integrator = init(prob, Tsit5(), save_everystep = false)
339338
@test integrator[x] isa Vector{Float64}

test/downstream/problem_interface.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
23
using SymbolicIndexingInterface
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)
13-
14-
sys = structural_simplify(sys)
12+
@mtkbuild sys = ODESystem(eqs,t)
1513

1614
u0 = [D(x) => 2.0,
1715
x => 1.0,
@@ -187,7 +185,7 @@ ps = @parameters p[1:3] = [1, 2, 3]
187185
D = Differential(t)
188186
eqs = [collect(D.(x) .~ x)
189187
D(y) ~ norm(x) * y - x[1]]
190-
@named sys = ODESystem(eqs, t, [sts...;], [ps...;])
188+
@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;])
191189
prob = ODEProblem(sys, [], (0, 1.0))
192190
@test getp(sys, p)(prob) == prob.ps[p] == [1, 2, 3]
193191
setp(sys, p)(prob, [4, 5, 6])

test/downstream/solution_interface.jl

Lines changed: 5 additions & 8 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,7 +29,7 @@ sol = solve(oprob, Rodas4())
3229
noiseeqs = [0.1 * s1,
3330
0.1 * s2]
3431
@named noisy_population_model = SDESystem(population_model, noiseeqs)
35-
sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p)
32+
sprob = SDEProblem(complete(noisy_population_model), u0, (0.0, 100.0), p)
3633
sol = solve(sprob, ImplicitEM())
3734

3835
@test sol[s1] == sol[noisy_population_model.s1] == sol[:s1]
@@ -58,7 +55,7 @@ eqs = [D(x) ~ σ * (y - x),
5855
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ,
5956
α ~ 2lorenz1.x + a * γ]
6057
@named sys = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
61-
sys_simplified = structural_simplify(sys)
58+
sys_simplified = complete(structural_simplify(sys))
6259

6360
u0 = [lorenz1.x => 1.0,
6461
lorenz1.y => 0.0,

0 commit comments

Comments
 (0)