From 14b869088108572b62544d32d207701e4aa9a0e2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 27 Feb 2024 01:47:17 -0600 Subject: [PATCH] Fix downstream tests for MTK v9 --- test/downstream/ensemble_multi_prob.jl | 17 ++++++++--------- test/downstream/integrator_indexing.jl | 21 ++++++++++----------- test/downstream/problem_interface.jl | 10 ++++------ test/downstream/solution_interface.jl | 13 +++++-------- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/test/downstream/ensemble_multi_prob.jl b/test/downstream/ensemble_multi_prob.jl index 9f09a58b2..de27acd84 100644 --- a/test/downstream/ensemble_multi_prob.jl +++ b/test/downstream/ensemble_multi_prob.jl @@ -1,14 +1,13 @@ using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D +@variables x(t), y(t) -@variables t, x(t), y(t) -D = Differential(t) - -@named sys1 = ODESystem([D(x) ~ x, - D(y) ~ -y]) -@named sys2 = ODESystem([D(x) ~ 2x, - D(y) ~ -2y]) -@named sys3 = ODESystem([D(x) ~ 3x, - D(y) ~ -3y]) +@mtkbuild sys1 = ODESystem([D(x) ~ x, + D(y) ~ -y],t) +@mtkbuild sys2 = ODESystem([D(x) ~ 2x, + D(y) ~ -2y],t) +@mtkbuild sys3 = ODESystem([D(x) ~ 3x, + D(y) ~ -3y],t) prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0)) prob2 = ODEProblem(sys2, [2.0, 2.0], (0.0, 1.0)) diff --git a/test/downstream/integrator_indexing.jl b/test/downstream/integrator_indexing.jl index 7f8795495..448bd19a0 100644 --- a/test/downstream/integrator_indexing.jl +++ b/test/downstream/integrator_indexing.jl @@ -1,16 +1,15 @@ using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, SymbolicIndexingInterface, Test - +using ModelingToolkit: t_nounits as t, D_nounits as D ### Tests on non-layered model (everything should work). ### -@parameters t a b c d +@parameters a b c d @variables s1(t) s2(t) -D = Differential(t) eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1, D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2] -@named population_model = ODESystem(eqs) +@named population_model = ODESystem(eqs,t) # Tests on ODEProblem. u0 = [s1 => 2.0, s2 => 1.0] @@ -127,15 +126,15 @@ eqs = [D(x) ~ σ * (y - x), D(y) ~ x * (ρ - z) - y, D(z) ~ x * y - β * z] -@named lorenz1 = ODESystem(eqs) -@named lorenz2 = ODESystem(eqs) +@named lorenz1 = ODESystem(eqs,t) +@named lorenz2 = ODESystem(eqs,t) @parameters γ @variables a(t) α(t) connections = [0 ~ lorenz1.x + lorenz2.y + a * γ, α ~ 2lorenz1.x + a * γ] -@named sys = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2]) -sys_simplified = structural_simplify(sys) +@mtkbuild sys_simplified = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2]) +sys_simplified = complete(structural_simplify(sys)) u0 = [lorenz1.x => 1.0, lorenz1.y => 0.0, @@ -185,7 +184,7 @@ step!(integrator, 100.0, true) eqs = [D(q[1]) ~ 2q[1] D(q[2]) ~ 2.0] @named sys2 = ODESystem(eqs, t, [q...], []) -sys2_simplified = structural_simplify(sys2) +sys2_simplified = complete(structural_simplify(sys2)) prob2 = ODEProblem(sys2, [], (0.0, 5.0)) integrator2 = init(prob2, Tsit5()) @@ -198,7 +197,7 @@ integrator2 = init(prob2, Tsit5()) @variables u(t) eqs = [D(u) ~ u] - @named sys2 = ODESystem(eqs) + @mtkbuild sys2 = ODESystem(eqs,t) tspan = (0.0, 5.0) @@ -333,7 +332,7 @@ ps = @parameters p[1:3] = [1, 2, 3] D = Differential(t) eqs = [collect(D.(x) .~ x) D(y) ~ norm(x) * y - x[1]] -@named sys = ODESystem(eqs, t, [sts...;], [ps...;]) +@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;]) prob = ODEProblem(sys, [], (0, 1.0)) integrator = init(prob, Tsit5(), save_everystep = false) @test integrator[x] isa Vector{Float64} diff --git a/test/downstream/problem_interface.jl b/test/downstream/problem_interface.jl index c0ddce89b..1f245b3c7 100644 --- a/test/downstream/problem_interface.jl +++ b/test/downstream/problem_interface.jl @@ -1,17 +1,15 @@ using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using SymbolicIndexingInterface @parameters σ ρ β -@variables t x(t) y(t) z(t) -D = Differential(t) +@variables x(t) y(t) z(t) eqs = [D(D(x)) ~ σ * (y - x), D(y) ~ x * (ρ - z) - y, D(z) ~ x * y - β * z] -@named sys = ODESystem(eqs) - -sys = structural_simplify(sys) +@mtkbuild sys = ODESystem(eqs,t) u0 = [D(x) => 2.0, x => 1.0, @@ -187,7 +185,7 @@ ps = @parameters p[1:3] = [1, 2, 3] D = Differential(t) eqs = [collect(D.(x) .~ x) D(y) ~ norm(x) * y - x[1]] -@named sys = ODESystem(eqs, t, [sts...;], [ps...;]) +@mtkbuild sys = ODESystem(eqs, t, [sts...;], [ps...;]) prob = ODEProblem(sys, [], (0, 1.0)) @test getp(sys, p)(prob) == prob.ps[p] == [1, 2, 3] setp(sys, p)(prob, [4, 5, 6]) diff --git a/test/downstream/solution_interface.jl b/test/downstream/solution_interface.jl index ce38d354d..ea4eff21d 100644 --- a/test/downstream/solution_interface.jl +++ b/test/downstream/solution_interface.jl @@ -1,18 +1,15 @@ using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, Test -# compat for MTKv8 and v9 -unknowns = isdefined(ModelingToolkit, :states) ? ModelingToolkit.states : - ModelingToolkit.unknowns +using ModelingToolkit: t_nounits as t, D_nounits as D ### Tests on non-layered model (everything should work). ### -@parameters t a b c d +@parameters a b c d @variables s1(t) s2(t) -D = Differential(t) eqs = [D(s1) ~ a * s1 / (1 + s1 + s2) - b * s1, D(s2) ~ +c * s2 / (1 + s1 + s2) - d * s2] -@named population_model = ODESystem(eqs) +@mtkbuild population_model = ODESystem(eqs,t) # Tests on ODEProblem. u0 = [s1 => 2.0, s2 => 1.0] @@ -32,7 +29,7 @@ sol = solve(oprob, Rodas4()) noiseeqs = [0.1 * s1, 0.1 * s2] @named noisy_population_model = SDESystem(population_model, noiseeqs) -sprob = SDEProblem(noisy_population_model, u0, (0.0, 100.0), p) +sprob = SDEProblem(complete(noisy_population_model), u0, (0.0, 100.0), p) sol = solve(sprob, ImplicitEM()) @test sol[s1] == sol[noisy_population_model.s1] == sol[:s1] @@ -58,7 +55,7 @@ eqs = [D(x) ~ σ * (y - x), connections = [0 ~ lorenz1.x + lorenz2.y + a * γ, α ~ 2lorenz1.x + a * γ] @named sys = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2]) -sys_simplified = structural_simplify(sys) +sys_simplified = complete(structural_simplify(sys)) u0 = [lorenz1.x => 1.0, lorenz1.y => 0.0,