Skip to content

Commit 64fb99d

Browse files
committed
tests
1 parent 6c2ef68 commit 64fb99d

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/systems/jumps/jumpsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ function DiffEqBase.ODEProblem(sys::JumpSystem, u0map, tspan::Union{Tuple, Nothi
461461
observedfun = ObservedFunctionCache(sys; eval_expression, eval_module)
462462

463463
f = (du, u, p, t) -> (du .= 0; nothing)
464-
df = ODEFunction(f; sys = sys, observed = observedfun)
464+
df = ODEFunction(f; sys, observed = observedfun)
465465
ODEProblem(df, u0, tspan, p; kwargs...)
466466
end
467467

test/jumpsystem.jl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelingToolkit, DiffEqBase, JumpProcesses, Test, LinearAlgebra, StableRNGs
2+
using OrdinaryDiffEq
23
using ModelingToolkit: t_nounits as t, D_nounits as D
34
MT = ModelingToolkit
45

@@ -67,7 +68,7 @@ tspan = (0.0, 250.0);
6768
u₀map = [S => 999, I => 1, R => 0]
6869
parammap ==> 0.1 / 1000, γ => 0.01]
6970
dprob = DiscreteProblem(js2, u₀map, tspan, parammap)
70-
jprob = JumpProblem(js2, dprob, Direct(), save_positions = (false, false), rng)
71+
jprob = JumpProblem(js2, dprob, Direct(); save_positions = (false, false), rng)
7172
Nsims = 30000
7273
function getmean(jprob, Nsims; use_stepper = true)
7374
m = 0.0
@@ -89,13 +90,13 @@ obs = [S2 ~ 2 * S]
8990
@named js2b = JumpSystem([j₁, j₃], t, [S, I, R], [β, γ], observed = obs)
9091
js2b = complete(js2b)
9192
dprob = DiscreteProblem(js2b, u₀map, tspan, parammap)
92-
jprob = JumpProblem(js2b, dprob, Direct(), save_positions = (false, false), rng)
93-
sol = solve(jprob, SSAStepper(), saveat = tspan[2] / 10)
93+
jprob = JumpProblem(js2b, dprob, Direct(); save_positions = (false, false), rng)
94+
sol = solve(jprob, SSAStepper(); saveat = tspan[2] / 10)
9495
@test all(2 .* sol[S] .== sol[S2])
9596

9697
# test save_positions is working
97-
jprob = JumpProblem(js2, dprob, Direct(), save_positions = (false, false), rng)
98-
sol = solve(jprob, SSAStepper(), saveat = 1.0)
98+
jprob = JumpProblem(js2, dprob, Direct(); save_positions = (false, false), rng)
99+
sol = solve(jprob, SSAStepper(); saveat = 1.0)
99100
@test all((sol.t) .== collect(0.0:tspan[2]))
100101

101102
#test the MT JumpProblem rates/affects are correct
@@ -129,7 +130,7 @@ function a2!(integrator)
129130
end
130131
j2 = ConstantRateJump(r2, a2!)
131132
jset = JumpSet((), (j1, j2), nothing, nothing)
132-
jprob = JumpProblem(prob, Direct(), jset, save_positions = (false, false), rng)
133+
jprob = JumpProblem(prob, Direct(), jset; save_positions = (false, false), rng)
133134
m2 = getmean(jprob, Nsims)
134135

135136
# test JumpSystem solution agrees with direct version
@@ -141,17 +142,17 @@ maj2 = MassActionJump(γ, [I => 1], [I => -1, R => 1])
141142
@named js3 = JumpSystem([maj1, maj2], t, [S, I, R], [β, γ])
142143
js3 = complete(js3)
143144
dprob = DiscreteProblem(js3, u₀map, tspan, parammap)
144-
jprob = JumpProblem(js3, dprob, Direct(), rng)
145+
jprob = JumpProblem(js3, dprob, Direct(); rng)
145146
m3 = getmean(jprob, Nsims)
146147
@test abs(m - m3) / m < 0.01
147148

148149
# maj jump test with various dep graphs
149150
@named js3b = JumpSystem([maj1, maj2], t, [S, I, R], [β, γ])
150151
js3b = complete(js3b)
151-
jprobb = JumpProblem(js3b, dprob, NRM(), rng)
152+
jprobb = JumpProblem(js3b, dprob, NRM(); rng)
152153
m4 = getmean(jprobb, Nsims)
153154
@test abs(m - m4) / m < 0.01
154-
jprobc = JumpProblem(js3b, dprob, RSSA(), rng)
155+
jprobc = JumpProblem(js3b, dprob, RSSA(); rng)
155156
m4 = getmean(jprobc, Nsims)
156157
@test abs(m - m4) / m < 0.01
157158

@@ -161,7 +162,7 @@ maj2 = MassActionJump(γ, [S => 1], [S => -1])
161162
@named js4 = JumpSystem([maj1, maj2], t, [S], [β, γ])
162163
js4 = complete(js4)
163164
dprob = DiscreteProblem(js4, [S => 999], (0, 1000.0), [β => 100.0, γ => 0.01])
164-
jprob = JumpProblem(js4, dprob, Direct(), rng)
165+
jprob = JumpProblem(js4, dprob, Direct(); rng)
165166
m4 = getmean(jprob, Nsims)
166167
@test abs(m4 - 2.0 / 0.01) * 0.01 / 2.0 < 0.01
167168

@@ -171,7 +172,7 @@ maj2 = MassActionJump(γ, [S => 2], [S => -1])
171172
@named js4 = JumpSystem([maj1, maj2], t, [S], [β, γ])
172173
js4 = complete(js4)
173174
dprob = DiscreteProblem(js4, [S => 999], (0, 1000.0), [β => 100.0, γ => 0.01])
174-
jprob = JumpProblem(js4, dprob, Direct(), rng)
175+
jprob = JumpProblem(js4, dprob, Direct(); rng)
175176
sol = solve(jprob, SSAStepper());
176177

177178
# issue #819
@@ -295,3 +296,16 @@ let
295296
@test jprob.aggregator isa algtype
296297
end
297298
end
299+
300+
# basic VariableRateJump test
301+
let
302+
@variables A(t)
303+
vrj = VariableRateJump(sin(t) + 1, [A ~ A + 1])
304+
js = complete(JumpSystem([vrj], t, [A], []; name = :js))
305+
oprob = ODEProblem(js, [A => 0], (0.0, 10.0))
306+
jprob = JumpProblem(js, oprob, Direct())
307+
sol = solve(jprob, Tsit5())
308+
309+
310+
311+
end

0 commit comments

Comments
 (0)