Skip to content

Commit 80a0fb7

Browse files
Merge pull request #1045 from AayushSabharwal/as/fix-mtk-downstream
test: update tests to MTKv10
2 parents 28cb4df + b9486c0 commit 80a0fb7

13 files changed

+147
-142
lines changed

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
88

99
[compat]
1010
Documenter = "1"
11-
ModelingToolkit = "8.35, 9"
11+
ModelingToolkit = "10"
1212
OrdinaryDiffEq = "6"
1313
Plots = "1"
1414
SciMLBase = "1.74, 2"

test/downstream/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ DelayDiffEq = "5"
3636
DiffEqCallbacks = "3, 4"
3737
ForwardDiff = "0.10"
3838
JumpProcesses = "9.10"
39-
ModelingToolkit = "9.64.3"
39+
ModelingToolkit = "10.0"
4040
ModelingToolkitStandardLibrary = "2.7"
4141
NonlinearSolve = "2, 3, 4"
4242
Optimization = "4"

test/downstream/adjoints.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ eqs = [D(x) ~ σ * (y - x),
88
D(y) ~ x *- z) - y,
99
D(z) ~ x * y - β * z]
1010

11-
@named lorenz1 = ODESystem(eqs, t)
12-
@named lorenz2 = ODESystem(eqs, t)
11+
@named lorenz1 = System(eqs, t)
12+
@named lorenz2 = System(eqs, t)
1313

1414
@parameters γ
1515
@variables a(t) α(t)
1616
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ,
1717
α ~ 2lorenz1.x + a * γ]
18-
@mtkbuild sys = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
18+
@mtkcompile sys = System(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
1919

2020
u0 = [lorenz1.x => 1.0,
2121
lorenz1.y => 0.0,
@@ -33,7 +33,7 @@ p = [lorenz1.σ => 10.0,
3333
γ => 2.0]
3434

3535
tspan = (0.0, 100.0)
36-
prob = ODEProblem(sys, u0, tspan, p)
36+
prob = ODEProblem(sys, [u0; p], tspan)
3737
sol = solve(prob, Rodas4())
3838

3939
gs_sym, = Zygote.gradient(sol) do sol
@@ -71,10 +71,10 @@ end
7171

7272
# BatchedInterface AD
7373
@variables x(t)=1.0 y(t)=1.0 z(t)=1.0 w(t)=1.0
74-
@named sys1 = ODESystem([D(x) ~ x + y, D(y) ~ y * z, D(z) ~ z * t * x], t)
74+
@named sys1 = System([D(x) ~ x + y, D(y) ~ y * z, D(z) ~ z * t * x], t)
7575
sys1 = complete(sys1)
7676
prob1 = ODEProblem(sys1, [], (0.0, 10.0))
77-
@named sys2 = ODESystem([D(x) ~ x + w, D(y) ~ w * t, D(w) ~ x + y + w], t)
77+
@named sys2 = System([D(x) ~ x + w, D(y) ~ w * t, D(w) ~ x + y + w], t)
7878
sys2 = complete(sys2)
7979
prob2 = ODEProblem(sys2, [], (0.0, 10.0))
8080

test/downstream/comprehensive_indexing.jl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ begin
4040
loss = kd * (k1 - X)^2 + k2 * (kp * Y - X^2)^2
4141

4242
# Create systems (without structural_simplify, since that might modify systems to affect intended tests).
43-
osys = complete(ODESystem(diff_eqs, t; observed, name = :osys))
44-
ssys = complete(SDESystem(
45-
diff_eqs, noise_eqs, t, [X, Y], [kp, kd, k1, k2]; observed, name = :ssys))
43+
osys = complete(System(diff_eqs, t; observed, name = :osys))
44+
ssys = complete(System(
45+
diff_eqs, t, [X, Y], [kp, kd, k1, k2]; noise_eqs, observed, name = :ssys))
4646
jsys = complete(JumpSystem(jumps, t, [X, Y], [kp, kd, k1, k2]; observed, name = :jsys))
47-
nsys = complete(NonlinearSystem(alg_eqs; observed, name = :nsys))
47+
nsys = complete(System(alg_eqs; observed, name = :nsys))
4848
optsys = complete(OptimizationSystem(
4949
loss, [X, Y], [kp, kd, k1, k2]; observed, name = :optsys))
5050
end
@@ -57,14 +57,14 @@ begin
5757
p_vals = [kp => 1.0, kd => 0.1, k1 => 0.25, k2 => 0.5]
5858

5959
# Creates problems.
60-
oprob = ODEProblem(osys, u0_vals, tspan, p_vals)
61-
sprob = SDEProblem(ssys, u0_vals, tspan, p_vals)
62-
dprob = DiscreteProblem(jsys, u0_vals, tspan, p_vals)
63-
jprob = JumpProblem(jsys, deepcopy(dprob), Direct(); rng)
64-
nprob = NonlinearProblem(nsys, u0_vals, p_vals)
60+
oprob = ODEProblem(osys, [u0_vals; p_vals], tspan)
61+
sprob = SDEProblem(ssys, [u0_vals; p_vals], tspan)
62+
dprob = DiscreteProblem(jsys, )
63+
jprob = JumpProblem(jsys, [u0_vals; p_vals], tspan; aggregator = Direct(), rng)
64+
nprob = NonlinearProblem(nsys, [u0_vals; p_vals])
6565
hcprob = NonlinearProblem(HomotopyNonlinearFunction(nprob.f), nprob.u0, nprob.p)
66-
ssprob = SteadyStateProblem(osys, u0_vals, p_vals)
67-
optprob = OptimizationProblem(optsys, u0_vals, p_vals, grad = true, hess = true)
66+
ssprob = SteadyStateProblem(osys, [u0_vals; p_vals])
67+
optprob = OptimizationProblem(optsys, [u0_vals; p_vals], grad = true, hess = true)
6868
problems = [oprob, sprob, dprob, jprob, nprob, hcprob, ssprob, optprob]
6969
systems = [osys, ssys, jsys, jsys, nsys, nsys, osys, optsys]
7070

@@ -358,7 +358,7 @@ end
358358
ps = @parameters p[1:3] = [1, 2, 3]
359359
eqs = [collect(D.(x) .~ x)
360360
D(y) ~ norm(x) * y - x[1]]
361-
@named sys = ODESystem(eqs, t, [sts...;], ps)
361+
@named sys = System(eqs, t, [sts...;], ps)
362362
sys = complete(sys)
363363
prob = ODEProblem(sys, [], (0, 1.0))
364364
sol = solve(prob, Tsit5())
@@ -510,9 +510,9 @@ end
510510
# Issue https://github.com/SciML/ModelingToolkit.jl/issues/2697
511511
@testset "Interpolation of derivative of observed variables" begin
512512
@variables x(t) y(t) z(t) w(t)[1:2]
513-
@named sys = ODESystem(
513+
@named sys = System(
514514
[D(x) ~ 1, y ~ x^2, z ~ 2y^2 + 3x, w[1] ~ x + y + z, w[2] ~ z * x * y], t)
515-
sys = structural_simplify(sys)
515+
sys = mtkcompile(sys)
516516
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0))
517517
sol = solve(prob, Tsit5())
518518
@test_throws ErrorException sol(1.0, Val{1}, idxs = y)
@@ -912,9 +912,9 @@ end
912912
@testset "Continuous interpolation before discrete save" begin
913913
@variables x(t)
914914
@parameters c(t)
915-
@mtkbuild sys = ODESystem(
916-
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [1.0 => [c ~ c + 1]])
917-
prob = ODEProblem(sys, [x => 0.0], (0.0, 2pi), [c => 1.0])
915+
@mtkcompile sys = System(
916+
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [1.0 => [c ~ Pre(c) + 1]])
917+
prob = ODEProblem(sys, [x => 0.0, c => 1.0], (0.0, 2pi))
918918
sol = solve(prob, Tsit5())
919919
@test_nowarn sol(-0.1; idxs = sys.x)
920920
@test_nowarn sol(-0.1; idxs = [sys.x, 2sys.x])
@@ -939,7 +939,7 @@ end
939939
osc2.jcn ~ osc1.delx]
940940
@named coupledOsc = System(eqs, t)
941941
@named coupledOsc = compose(coupledOsc, systems)
942-
sys = structural_simplify(coupledOsc)
942+
sys = mtkcompile(coupledOsc)
943943
prob = DDEProblem(sys, [], (0.0, 10.0); constant_lags = [sys.osc1.τ, sys.osc2.τ])
944944
sym = sys.osc1.delx
945945
delay = sys.osc1.τ
@@ -970,7 +970,7 @@ end
970970
osc2.jcn ~ osc1.delx]
971971
@named coupledOsc = System(eqs, t)
972972
@named coupledOsc = compose(coupledOsc, systems)
973-
sys = structural_simplify(coupledOsc)
973+
sys = mtkcompile(coupledOsc)
974974
prob = SDDEProblem(sys, [], (0.0, 10.0); constant_lags = [sys.osc1.τ, sys.osc2.τ])
975975
sym = sys.osc1.delx
976976
delay = sys.osc1.τ
@@ -983,14 +983,14 @@ end
983983
@testset "RODESolutions save discretes" begin
984984
@parameters k(t)
985985
@variables A(t)
986-
function affect2!(integ, u, p, ctx)
987-
integ.ps[p.k] += 1.0
986+
function affect2!(m, o, ctx, integ)
987+
return (; k = m.k + 1.0)
988988
end
989-
db = 1.0 => (affect2!, [], [k], [k], nothing)
989+
db = 1.0 => ModelingToolkit.ImperativeAffect(affect2!; modified = (; k))
990990

991-
@named ssys = SDESystem(D(A) ~ k * A, [0.0], t, [A], [k], discrete_events = db)
991+
@named ssys = System(D(A) ~ k * A, t, [A], [k]; noise_eqs = [0.0] discrete_events = db)
992992
ssys = complete(ssys)
993-
prob = SDEProblem(ssys, [A => 1.0], (0.0, 4.0), [k => 1.0])
993+
prob = SDEProblem(ssys, [A => 1.0, k => 1.0], (0.0, 4.0))
994994
sol = solve(prob, RI5())
995995
@test sol[k] isa AbstractVector
996996
@test sol[k] == [1.0, 2.0, 3.0, 4.0]

test/downstream/ensemble_multi_prob.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ using ModelingToolkit, OrdinaryDiffEq, Test
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33
@variables x(t), y(t)
44

5-
@mtkbuild sys1 = ODESystem([D(x) ~ x,
5+
@mtkcompile sys1 = System([D(x) ~ x,
66
D(y) ~ -y], t)
7-
@mtkbuild sys2 = ODESystem([D(x) ~ 2x,
7+
@mtkcompile sys2 = System([D(x) ~ 2x,
88
D(y) ~ -2y], t)
9-
@mtkbuild sys3 = ODESystem([D(x) ~ 3x,
9+
@mtkcompile sys3 = System([D(x) ~ 3x,
1010
D(y) ~ -3y], t)
1111

1212
prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0))

test/downstream/initialization.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ end
4444

4545
@variables x(t) [guess = 1.0] y(t) [guess = 1.0]
4646
@parameters p=missing [guess=1.0] q=missing [guess=1.0]
47-
@mtkbuild sys = ODESystem([D(x) ~ p * y + q * t, D(y) ~ 5x + q], t;
47+
@mtkcompile sys = System([D(x) ~ p * y + q * t, D(y) ~ 5x + q], t;
4848
initialization_eqs = [p^2 + q^2 ~ 3, x^3 + y^3 ~ 5])
4949
prob = ODEProblem(
50-
sys, [x => 1.0], (0.0, 1.0), [p => 1.0]; initializealg = SciMLBase.NoInit())
50+
sys, [x => 1.0, p => 1.0], (0.0, 1.0); initializealg = SciMLBase.NoInit())
5151

5252
@test prob.f.initialization_data isa SciMLBase.OverrideInitData
5353
integ = init(prob, Tsit5())
@@ -68,15 +68,15 @@ end
6868
eqs = [D(D(x)) ~ λ * x
6969
D(D(y)) ~ λ * y - g
7070
x^2 + y^2 ~ 1]
71-
@mtkbuild pend = ODESystem(eqs, t)
71+
@mtkcompile pend = System(eqs, t)
7272

73-
prob = ODEProblem(pend, [x => 1, y => 0], (0.0, 1.5), [g => 1], guesses ==> 1])
73+
prob = ODEProblem(pend, [x => 1, y => 0, g => 1], (0.0, 1.5), guesses ==> 1])
7474
@test occursin("Initialization status: FULLY_DETERMINED", sprint(summary, prob))
7575

76-
prob = ODEProblem(pend, [], (0.0, 1.5), [g => 1], guesses ==> 1, x => 1, y => 0])
76+
prob = ODEProblem(pend, [g => 1], (0.0, 1.5), guesses ==> 1, x => 1, y => 0])
7777
@test occursin("Initialization status: UNDERDETERMINED", sprint(summary, prob))
7878

79-
prob = ODEProblem(pend, [x => 1, y => 0, λ => 2], (0.0, 1.5), [g => 1])
79+
prob = ODEProblem(pend, [x => 1, y => 0, λ => 2, g => 1], (0.0, 1.5))
8080
@test occursin("Initialization status: OVERDETERMINED", sprint(summary, prob))
8181
end
8282

test/downstream/integrator_indexing.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ using SciMLStructures: canonicalize, Tunable
1010
eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1111
D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2]
1212

13-
@named pop_model = ODESystem(eqs, t)
13+
@named pop_model = System(eqs, t)
1414
population_model = complete(pop_model)
1515
# Tests on ODEProblem.
1616
u0 = [s1 => 2.0, s2 => 1.0]
1717
p = [a => 2.0, b => 1.0, c => 1.0, d => 1.0]
1818
tspan = (0.0, 1000000.0)
19-
oprob = ODEProblem(population_model, u0, tspan, p)
19+
oprob = ODEProblem(population_model, [u0; p], tspan)
2020
integrator = init(oprob, Rodas4())
2121

2222
@test_throws Exception integrator[a]
@@ -84,7 +84,7 @@ noiseeqs = [0.1 * s1,
8484
0.1 * s2]
8585
@named noisy_population_model = SDESystem(pop_model, noiseeqs)
8686
noisy_population_model = complete(noisy_population_model)
87-
sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p)
87+
sprob = SDEProblem(noisy_population_model, [u0; p], (0.0, 100.0))
8888
integrator = init(sprob, ImplicitEM())
8989

9090
step!(integrator, 100.0, true)
@@ -127,14 +127,14 @@ eqs = [D(x) ~ σ * (y - x),
127127
D(y) ~ x *- z) - y,
128128
D(z) ~ x * y - β * z]
129129

130-
@named lorenz1 = ODESystem(eqs, t)
131-
@named lorenz2 = ODESystem(eqs, t)
130+
@named lorenz1 = System(eqs, t)
131+
@named lorenz2 = System(eqs, t)
132132

133133
@parameters γ
134134
@variables a(t) α(t)
135135
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ,
136136
α ~ 2lorenz1.x + a * γ]
137-
@mtkbuild sys = ODESystem(
137+
@mtkbuild sys = System(
138138
connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
139139

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

156156
tspan = (0.0, 100.0)
157-
prob = ODEProblem(sys, u0, tspan, p)
157+
prob = ODEProblem(sys, [u0; p], tspan)
158158
integrator = init(prob, Rodas4())
159159
sol = solve(prob, Rodas4())
160160
step!(integrator, 100.0, true)
@@ -185,8 +185,8 @@ step!(integrator, 100.0, true)
185185
@variables q(t)[1:2] = [1.0, 2.0]
186186
eqs = [D(q[1]) ~ 2q[1]
187187
D(q[2]) ~ 2.0]
188-
@named sys2 = ODESystem(eqs, t, [q...], [])
189-
sys2_simplified = structural_simplify(sys2)
188+
@named sys2 = System(eqs, t, [q...], [])
189+
sys2_simplified = mtkcompile(sys2)
190190
prob2 = ODEProblem(sys2_simplified, [], (0.0, 5.0))
191191
integrator2 = init(prob2, Tsit5())
192192

@@ -199,7 +199,7 @@ integrator2 = init(prob2, Tsit5())
199199
@variables u(t)
200200
eqs = [D(u) ~ u]
201201

202-
@mtkbuild sys2 = ODESystem(eqs, t)
202+
@mtkcompile sys2 = System(eqs, t)
203203

204204
tspan = (0.0, 5.0)
205205

@@ -324,7 +324,7 @@ sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0
324324
ps = @parameters p[1:3] = [1, 2, 3]
325325
eqs = [collect(D.(x) .~ x)
326326
D(y) ~ norm(x) * y - x[1]]
327-
@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;])
327+
@mtkcompile sys = System(eqs, t, [sts...;], [ps...;])
328328
prob = ODEProblem(sys, [], (0, 1.0))
329329
integrator = init(prob, Tsit5(), save_everystep = false)
330330
@test integrator[x] isa Vector{Float64}
@@ -365,5 +365,5 @@ integrator.ps[p] = [7, 8, 9]
365365
@variables X(t)
366366

367367
eq = D(X) ~ p - X
368-
@mtkbuild osys = ODESystem([eq], t)
369-
oprob = ODEProblem(osys, [X => 0.1], (0.0, 1.0), [p => 1.0])
368+
@mtkcompile osys = System([eq], t)
369+
oprob = ODEProblem(osys, [X => 0.1, p => 1.0], (0.0, 1.0))

0 commit comments

Comments
 (0)