diff --git a/test/downstream/ensemble_multi_prob.jl b/test/downstream/ensemble_multi_prob.jl index 9f09a58b2..0ad6d49c3 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..7a10954c0 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] @@ -119,7 +118,7 @@ integrator[noisy_population_model.s2] = 10.0 integrator[:s1] = 1.0 @test integrator[s1] == integrator[noisy_population_model.s1] == integrator[:s1] == 1.0 -@parameters t σ ρ β +@parameters σ ρ β @variables x(t) y(t) z(t) D = Differential(t) @@ -127,15 +126,16 @@ 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 +185,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 +198,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) @@ -327,13 +327,12 @@ plot(sol,idxs=(t,α)) =# using LinearAlgebra -@variables t sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0 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..5c8c3ad6f 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, @@ -181,13 +179,12 @@ set_tuple!(sprob, [10.0, 10.0]) @test get_tuple(sprob) == (10.0, 10.0) using LinearAlgebra -@variables t sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0 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/remake_autodiff.jl b/test/downstream/remake_autodiff.jl index b012a4d15..98534a878 100644 --- a/test/downstream/remake_autodiff.jl +++ b/test/downstream/remake_autodiff.jl @@ -1,6 +1,7 @@ using OrdinaryDiffEq, ModelingToolkit, Zygote, SciMLSensitivity +using ModelingToolkit: t_nounits as t, D_nounits as D -@variables t x(t) o(t) +@variables x(t) o(t) D = Differential(t) function lotka_volterra(; name = name) unknowns = @variables x(t)=1.0 y(t)=1.0 o(t) diff --git a/test/downstream/solution_interface.jl b/test/downstream/solution_interface.jl index ce38d354d..b74c7da89 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] @@ -42,23 +39,22 @@ sol = solve(sprob, ImplicitEM()) @test_throws Exception sol[:a] ### Tests on layered model (some things should not work). ### -@parameters t σ ρ β +@parameters σ ρ β @variables x(t) y(t) z(t) -D = Differential(t) 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) +sys_simplified = complete(structural_simplify(sys)) u0 = [lorenz1.x => 1.0, lorenz1.y => 0.0, diff --git a/test/downstream/symbol_indexing.jl b/test/downstream/symbol_indexing.jl index 17a24ee28..766b0faf0 100644 --- a/test/downstream/symbol_indexing.jl +++ b/test/downstream/symbol_indexing.jl @@ -1,10 +1,8 @@ using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, SymbolicIndexingInterface, Test using Optimization, OptimizationOptimJL -# compat for MTKv8 and v9 -unknowns = isdefined(ModelingToolkit, :states) ? ModelingToolkit.states : - ModelingToolkit.unknowns +using ModelingToolkit: t_nounits as t, D_nounits as D -@parameters t σ ρ β +@parameters σ ρ β @variables x(t) y(t) z(t) D = Differential(t) @@ -19,8 +17,7 @@ eqs = [D(x) ~ σ * (y - x), @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 = ODESystem(connections, t, [a, α], [γ], systems = [lorenz1, lorenz2]) u0 = [lorenz1.x => 1.0, lorenz1.y => 0.0, @@ -39,7 +36,7 @@ p = [lorenz1.σ => 10.0, γ => 2.0] tspan = (0.0, 100.0) -prob = ODEProblem(sys_simplified, u0, tspan, p) +prob = ODEProblem(sys, u0, tspan, p) integ = init(prob, Rodas4()) sol = solve(prob, Rodas4()) @@ -135,7 +132,7 @@ sol1 = sol(0.0:1.0:10.0) sol2 = sol(0.1) @test sol2 isa Vector -@test length(sol2) == length(unknowns(sys_simplified)) +@test length(sol2) == length(unknowns(sys)) @test first(sol2) isa Real sol3 = sol(0.0:1.0:10.0, idxs = [lorenz1.x, lorenz2.x]) @@ -191,9 +188,9 @@ sol10 = sol(0.1, idxs = 2) @test sol10 isa Real @test is_timeseries(sol) == Timeseries() -getx = getu(sys_simplified, lorenz1.x) -get_arr = getu(sys_simplified, [lorenz1.x, lorenz2.x]) -get_tuple = getu(sys_simplified, (lorenz1.x, lorenz2.x)) +getx = getu(sys, lorenz1.x) +get_arr = getu(sys, [lorenz1.x, lorenz2.x]) +get_tuple = getu(sys, (lorenz1.x, lorenz2.x)) get_obs = getu(sol, lorenz1.x + lorenz2.x) # can't use sys for observed get_obs_arr = getu(sol, [lorenz1.x + lorenz2.x, lorenz1.y + lorenz2.y]) l1x_idx = variable_index(sol, lorenz1.x) @@ -218,7 +215,6 @@ plot(sol,idxs=(t,α)) =# using LinearAlgebra -@variables t sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0 ps = @parameters p[1:3] = [1, 2, 3] D = Differential(t) @@ -342,7 +338,7 @@ for (sym, oldval, newval, check_inference) in [ end # accessing parameters -@variables t x(t) +@variables x(t) @parameters tau D = Differential(t)