Skip to content

Commit 413d258

Browse files
committed
get tests workings
1 parent 2c24809 commit 413d258

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/systems/jumps/jumpsystem.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
9696
"""
9797
discrete_events::Vector{SymbolicDiscreteCallback}
9898
"""
99-
A `Vector{SymbolicContinuousCallback}` that model events.
100-
The integrator will use root finding to guarantee that it steps at each zero crossing.
101-
"""
102-
continuous_events::Vector{SymbolicContinuousCallback}
103-
"""
10499
Topologically sorted parameter dependency equations, where all symbols are parameters and
105100
the LHS is a single parameter.
106101
"""
@@ -172,13 +167,14 @@ function JumpSystem(eqs, iv, unknowns, ps;
172167
iv′ = value(iv)
173168
us′ = value.(unknowns)
174169
ps′ = value.(ps)
175-
parameter_dependencies, ps = process_parameter_dependencies(parameter_dependencies, ps′)
170+
parameter_dependencies, ps′ = process_parameter_dependencies(
171+
parameter_dependencies, ps′)
176172
if !(isempty(default_u0) && isempty(default_p))
177173
Base.depwarn(
178174
"`default_u0` and `default_p` are deprecated. Use `defaults` instead.",
179175
:JumpSystem, force = true)
180176
end
181-
defaults = todict(defaults)
177+
defaults = Dict{Any,Any}(todict(defaults))
182178
var_to_name = Dict()
183179
process_variables!(var_to_name, defaults, us′)
184180
process_variables!(var_to_name, defaults, ps′)
@@ -188,7 +184,14 @@ function JumpSystem(eqs, iv, unknowns, ps;
188184
if value(v) !== nothing)
189185
isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))
190186

187+
sysnames = nameof.(systems)
188+
if length(unique(sysnames)) != length(sysnames)
189+
throw(ArgumentError("System names must be unique."))
190+
end
191+
191192
# equation processing
193+
# this and the treatment of continuous events are the only part
194+
# unique to JumpSystems
192195
eqs = scalarize.(eqs)
193196
ap = ArrayPartition(MassActionJump[], ConstantRateJump[], VariableRateJump[])
194197
for eq in eqs
@@ -203,11 +206,6 @@ function JumpSystem(eqs, iv, unknowns, ps;
203206
end
204207
end
205208

206-
sysnames = nameof.(systems)
207-
if length(unique(sysnames)) != length(sysnames)
208-
throw(ArgumentError("System names must be unique."))
209-
end
210-
211209
(continuous_events === nothing) ||
212210
error("JumpSystems currently only support discrete events.")
213211
disc_callbacks = SymbolicDiscreteCallbacks(discrete_events)
@@ -220,17 +218,19 @@ end
220218

221219
##### MTK dispatches for JumpSystems #####
222220
function collect_vars!(unknowns, parameters, j::MassActionJump, iv; depth = 0,
223-
op = Differential)
221+
op = Differential)
224222
for field in (j.scaled_rates, j.reactant_stoch, j.net_stoch)
225-
collect_vars!(unknowns, parameters, field, iv; depth, op)
223+
for el in field
224+
collect_vars!(unknowns, parameters, el, iv; depth, op)
225+
end
226226
end
227227
return nothing
228228
end
229229

230230
function collect_vars!(unknowns, parameters, j::Union{ConstantRateJump,VariableRateJump},
231231
iv; depth = 0, op = Differential)
232-
collect_vars!(unknowns, parameters, j.condition, iv; depth, op)
233-
for eq in j.affect
232+
collect_vars!(unknowns, parameters, j.rate, iv; depth, op)
233+
for eq in j.affect!
234234
(eq isa Equation) && collect_vars!(unknowns, parameters, eq, iv; depth, op)
235235
end
236236
return nothing

test/jumpsystem.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,39 @@ let
340340

341341
@test all(abs.(cmean .- cmean2) .<= 0.05 .* cmean)
342342
end
343+
344+
345+
# collect_vars! tests for jumps
346+
let
347+
@variables x1(t) x2(t) x3(t) x4(t) x5(t)
348+
@parameters p1 p2 p3 p4 p5
349+
j1 = ConstantRateJump(p1, [x1 ~ x1 + 1])
350+
j2 = MassActionJump(p2, [x2 => 1], [x3 => -1])
351+
j3 = VariableRateJump(p3, [x3 ~ x3 + 1, x4 ~ x4 + 1])
352+
j4 = MassActionJump(p4*p5, [x1 => 1, x5 => 1], [x1 => -1, x5 => -1, x2 => 1])
353+
us = Set()
354+
ps = Set()
355+
iv = t
356+
357+
MT.collect_vars!(us, ps, j1, iv)
358+
@test issetequal(us, [x1])
359+
@test issetequal(ps, [p1])
360+
361+
empty!(us)
362+
empty!(ps)
363+
MT.collect_vars!(us, ps, j2, iv)
364+
@test issetequal(us, [x2, x3])
365+
@test issetequal(ps, [p2])
366+
367+
empty!(us)
368+
empty!(ps)
369+
MT.collect_vars!(us, ps, j3, iv)
370+
@test issetequal(us, [x3, x4])
371+
@test issetequal(ps, [p3])
372+
373+
empty!(us)
374+
empty!(ps)
375+
MT.collect_vars!(us, ps, j4, iv)
376+
@test issetequal(us, [x1, x5, x2])
377+
@test issetequal(ps, [p4, p5])
378+
end

0 commit comments

Comments
 (0)