Skip to content

Commit 491b4f5

Browse files
committed
test rx edge cases
1 parent c42b3e4 commit 491b4f5

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2727
[compat]
2828
ArrayInterface = "2.8"
2929
DiffEqBase = "6.28"
30-
DiffEqJump = "6.6"
30+
DiffEqJump = "6.6.2"
3131
DiffRules = "0.1, 1.0"
3232
DocStringExtensions = "0.7, 0.8"
3333
GeneralizedGenerated = "0.1.4, 0.2"

src/systems/jumps/jumpsystem.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ end
4444

4545
function assemble_maj(js, maj::MassActionJump{U,Vector{Pair{V,W}},Vector{Pair{V2,W2}}},
4646
statetoid, ptoid, p, pcontext) where {U,V,W,V2,W2}
47-
pval = Base.eval(pcontext, Expr(maj.scaled_rates))
48-
47+
sr = maj.scaled_rates
48+
if sr isa Operation || sr isa Variable
49+
pval = Base.eval(pcontext, Expr(maj.scaled_rates))
50+
else
51+
pval = maj.scaled_rates
52+
end
53+
4954
rs = Vector{Pair{Int,W}}()
5055
for (spec,stoich) in maj.reactant_stoch
5156
if iszero(spec)

test/jumpsystem.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,37 @@ jprob = JumpProblem(prob,Direct(),jset, save_positions=(false,false))
105105
m2 = getmean(jprob,Nsims)
106106

107107
# test JumpSystem solution agrees with direct version
108-
@test abs(m-m2) ./ m < .01
108+
@test abs(m-m2)/m < .01
109109

110110

111111
# mass action jump tests for SIR model
112112
maj1 = MassActionJump(2*β/2, [S => 1, I => 1], [S => -1, I => 1])
113113
maj2 = MassActionJump(γ, [I => 1], [I => -1, R => 1])
114-
js = JumpSystem([maj1,maj2], t, [S,I,R], [β,γ])
114+
js3 = JumpSystem([maj1,maj2], t, [S,I,R], [β,γ])
115115
statetoid = Dict(convert(Variable,state) => i for (i,state) in enumerate(states(js)))
116116
ptoid = Dict(convert(Variable,par) => i for (i,par) in enumerate(parameters(js)))
117-
dprob = DiscreteProblem(js, u₀map, tspan, parammap)
118-
jprob = JumpProblem(js, dprob, Direct())
117+
dprob = DiscreteProblem(js3, u₀map, tspan, parammap)
118+
jprob = JumpProblem(js3, dprob, Direct())
119119
m3 = getmean(jprob,Nsims)
120-
@test abs(m2-m3) < .01
120+
@test abs(m-m3)/m < .01
121121

122-
# mass action jump tests for other reaction types (zero order, second order, decay)
123-
# TODO
122+
# mass action jump tests for other reaction types (zero order, decay)
123+
maj1 = MassActionJump(2.0, [0 => 1], [S => 1])
124+
maj2 = MassActionJump(γ, [S => 1], [S => -1])
125+
js4 = JumpSystem([maj1,maj2], t, [S], [β,γ])
126+
statetoid = Dict(convert(Variable,state) => i for (i,state) in enumerate(states(js)))
127+
ptoid = Dict(convert(Variable,par) => i for (i,par) in enumerate(parameters(js)))
128+
dprob = DiscreteProblem(js4, [S => 999], (0,1000.), [β => 100.=> .01])
129+
jprob = JumpProblem(js4, dprob, Direct())
130+
m4 = getmean(jprob,Nsims)
131+
@test abs(m4 - 2.0/.01)*.01/2.0 < .01
132+
133+
# test second order rx runs
134+
maj1 = MassActionJump(2.0, [0 => 1], [S => 1])
135+
maj2 = MassActionJump(γ, [S => 2], [S => -1])
136+
js4 = JumpSystem([maj1,maj2], t, [S], [β,γ])
137+
statetoid = Dict(convert(Variable,state) => i for (i,state) in enumerate(states(js)))
138+
ptoid = Dict(convert(Variable,par) => i for (i,par) in enumerate(parameters(js)))
139+
dprob = DiscreteProblem(js4, [S => 999], (0,1000.), [β => 100.=> .01])
140+
jprob = JumpProblem(js4, dprob, Direct())
141+
sol = solve(jprob, SSAStepper())

0 commit comments

Comments
 (0)