Skip to content

Commit

Permalink
test: add tests for setp_oop using MTK
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Sep 2, 2024
1 parent c0d8cd1 commit 95aad09
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/downstream/setp_oop.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using ModelingToolkit
using SymbolicIndexingInterface

@variables x(t)
@parameters a b[1:3] c(t) d(t)::Int e [tunable = false] f[1:4] [tunable = false] g::Function

@named sys = ODESystem(D(x) ~ x, t, [x], [a, b, c, d, e, f, g];
discrete_events = [[1.0] => [c ~ 2c, d ~ d + 1]])
sys = complete(sys)

prob = ODEProblem(sys,
[x => 1.0],
(0.0, 1.0),
[a => 1.0, b => collect(1.0:3.0), c => 2.0, d => 3,
e => 4.0, f => collect(5.0:8.0), g => identity])
ps = prob.p

syms = [a, b, c, d, e, f, g]
newvals = [1.0f0, view(rand(Float32, 5), 2:4), c => BigFloat("1.01"),
d => BigInt("12345"), e => 2.0f0, f => view(rand(2, 2), 1:4), g => (+)]

for (sym, val) in zip(syms, vals)
for valp in (prob, ps)
newps = setp_oop(sys, sym)(valp, val)
@test newps isa MTKParameters
v = getp(sys, sym)(newps)
@test v == val
@test typeof(v) == typeof(val)
end
end

setter = setp_oop(sys, syms)
for wrapper in (identity, Tuple)
vals = wrapper(newvals)
for valp in (prob, ps)
newps = setter(valp, vals)
@test newps isa MTKParameters
for (sym, newval) in zip(syms, vals)
v = getp(sys, sym)(newps)
@test v == newval
@test typeof(v) == typeof(newval)
end
end
end
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ if GROUP == "All" || GROUP == "Downstream"
@safetestset "BatchedInterface with array symbolics test" begin
@time include("downstream/batchedinterface_arrayvars.jl")
end
@safetestset "remake_buffer with array symbolics test" begin
@time include("downstream/remake_arrayvars.jl")
end
@safetestset "setp_oop with MTK" begin
@time include("downstream/setp_oop.jl")
end
end

0 comments on commit 95aad09

Please sign in to comment.