Skip to content

Commit

Permalink
test: update tests for MTKv9
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jan 25, 2024
1 parent 4cf5129 commit 1591f3e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/downstream/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
[compat]
BoundaryValueDiffEq = "5"
ForwardDiff = "0.10"
ModelingToolkit = "8.37"
ModelingToolkit = "8.37, 9"
NonlinearSolve = "2, 3"
Optimization = "3"
OptimizationOptimJL = "0.1, 0.2"
Expand Down
2 changes: 1 addition & 1 deletion test/downstream/integrator_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ integrator[lorenz2.x] = 2.0

# integrator2 = integrator(0.1)
# @test integrator2 isa Vector
# @test length(integrator2) == length(states(sys_simplified))
# @test length(integrator2) == length(unknowns(sys_simplified))
# @test first(integrator2) isa Real

# integrator3 = integrator(0.0:1.0:10.0, idxs = [lorenz1.x, lorenz2.x])
Expand Down
4 changes: 2 additions & 2 deletions test/downstream/remake_autodiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ using OrdinaryDiffEq, ModelingToolkit, Zygote, SciMLSensitivity
@variables t x(t) o(t)
D = Differential(t)
function lotka_volterra(; name = name)
states = @variables x(t)=1.0 y(t)=1.0 o(t)
unknowns = @variables x(t)=1.0 y(t)=1.0 o(t)
params = @parameters p1=1.5 p2=1.0 p3=3.0 p4=1.0
eqs = [
D(x) ~ p1 * x - p2 * x * y,
D(y) ~ -p3 * y + p4 * x * y,
o ~ x * y,
]
return ODESystem(eqs, t, states, params; name = name)
return ODESystem(eqs, t, unknowns, params; name = name)
end

@named lotka_volterra_sys = lotka_volterra()
Expand Down
4 changes: 3 additions & 1 deletion test/downstream/solution_interface.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, Test
# compat for MTKv8 and v9
unknowns = isdefined(ModelingToolkit.states) ? ModelingToolkit.states : ModelingToolkit.unknowns

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

Expand Down Expand Up @@ -78,5 +80,5 @@ prob = ODEProblem(sys_simplified, u0, tspan, p)
sol = solve(prob, Rodas4())

@test_throws ArgumentError sol[x]
@test in(sol[lorenz1.x], [getindex.(sol.u, 1) for i in 1:length(states(sol.prob.f.sys))])
@test in(sol[lorenz1.x], [getindex.(sol.u, 1) for i in 1:length(unknowns(sol.prob.f.sys))])
@test_throws ArgumentError sol[:x]
4 changes: 3 additions & 1 deletion test/downstream/symbol_indexing.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, SymbolicIndexingInterface, Test
using Optimization, OptimizationOptimJL
# compat for MTKv8 and v9
unknowns = isdefined(ModelingToolkit.states) ? ModelingToolkit.states : ModelingToolkit.unknowns

@parameters t σ ρ β
@variables x(t) y(t) z(t)
Expand Down Expand Up @@ -122,7 +124,7 @@ sol1 = sol(0.0:1.0:10.0)

sol2 = sol(0.1)
@test sol2 isa Vector
@test length(sol2) == length(states(sys_simplified))
@test length(sol2) == length(unknowns(sys_simplified))
@test first(sol2) isa Real

sol3 = sol(0.0:1.0:10.0, idxs = [lorenz1.x, lorenz2.x])
Expand Down

0 comments on commit 1591f3e

Please sign in to comment.