Skip to content

Commit 1cf743c

Browse files
committed
higher order tests fix
1 parent 08f70b2 commit 1cf743c

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/networkapi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ function validate(rs::ReactionSystem, info::String = "")
16141614

16151615
# no units for species, time or parameters then assume validated
16161616
if (specunits in (MT.unitless, nothing)) && (timeunits in (MT.unitless, nothing))
1617-
all(u == 1.0 for u in ModelingToolkit.get_unit(get_ps(rs))) || return true
1617+
all(u == 1.0 for u in ModelingToolkit.get_unit(get_ps(rs))) && return true
16181618
end
16191619

16201620
rateunits = specunits / timeunits

test/reactionsystem_structure/higher_order_reactions.jl

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ end
5555
# Currently fails for reason I do not understand. Likely reason similar to the weird case in the jump tests.
5656
# Spent loads of time trying to figure out, the best I can get to is that it seems like the rng/seed is
5757
# not fully reproducible.
58-
let
59-
@test_broken false
60-
# Declares a JumpSystem manually. Would have used Catalyst again, but `binomial` still errors when
61-
# called on symbolics. For reference, here is the network as it would be created using Catalyst.
62-
63-
# higher_order_network_alt2 = @reaction_network begin
64-
# p, ∅ ⟼ X1
65-
# r1 * binomial(X1, 2), 2X1 ⟾ 3X2
66-
# mm(X1, r2, K) * binomial(X2, 3), 3X2 ⟾ X3 + 2X4
67-
# r3 * binomial(X3, 1) * binomial(X4, 2), X3 + 2X4 ⟾ 3X5 + 3X6
68-
# r4 * X2 * binomial(X5, 3) * binomial(X6, 3), 3X5 + 3X6 ⟾ 3X5 + 2X7 + 4X8
69-
# r5 * binomial(X5, 3) * binomial(X7, 2) * binomial(X8, 4), 3X5 + 2X7 + 4X8 ⟾ 10X9
70-
# r6 * binomial(X9, 10), 10X9 ⟾ X10
71-
# d * binomial(X10, 2), 2X10 ⟾ ∅
72-
# end
58+
let
59+
# Declares a JumpSystem manually.
7360

61+
# Declares the reactions using Catalyst, but defines the propensities manually.
62+
higher_order_network_alt1 = @reaction_network begin
63+
p, ∅ X1
64+
r1 * binomial(X1, 2), 2X1 3X2
65+
mm(X1, r2, K) * binomial(X2, 3), 3X2 X3 + 2X4
66+
r3 * binomial(X3, 1) * binomial(X4, 2), X3 + 2X4 3X5 + 3X6
67+
r4 * X2 * binomial(X5, 3) * binomial(X6, 3), 3X5 + 3X6 3X5 + 2X7 + 4X8
68+
r5 * binomial(X5, 3) * binomial(X7, 2) * binomial(X8, 4), 3X5 + 2X7 + 4X8 10X9
69+
r6 * binomial(X9, 10), 10X9 X10
70+
d * binomial(X10, 2), 2X10
71+
end
72+
73+
# Declares both the reactions and the propensities manually.
7474
rate1(u, p, t) = p[1]
7575
rate2(u, p, t) = p[2] * binomial(u[1], 2)
7676
rate3(u, p, t) = mm(u[1], p[3], p[4]) * binomial(u[2], 3)
@@ -93,22 +93,27 @@ let
9393
[affect1!, affect2!, affect3!, affect4!, affect5!, affect6!, affect7!, affect8!])
9494

9595
# For the systems created via Catalyst and manually, compares that they yield identical simulations.
96-
for n in [5, 50]
96+
for n in [5, 50]
9797
# Prepares JumpProblem via Catalyst.
9898
u0_base = rnd_u0_Int64(base_higher_order_network, rng; n)
9999
ps_base = rnd_ps(base_higher_order_network, rng; factor = n/10.0)
100100
dprob_base = DiscreteProblem(base_higher_order_network, u0_base, (0.0, 100.0), ps_base)
101101
jprob_base = JumpProblem(base_higher_order_network, dprob_base, Direct(); rng = StableRNG(1234))
102102

103+
# Prepares JumpProblem partially declared manually.
104+
dprob_alt1 = DiscreteProblem(higher_order_network_alt1, u0_base, (0.0, 100.0), ps_base)
105+
jprob_alt1 = JumpProblem(higher_order_network_alt1, dprob_alt1, Direct(); rng = StableRNG(1234))
106+
103107
# Prepares JumpProblem via manually declared system.
104-
u0_alt = map_to_vec(u0_base, [:X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10])
105-
ps_alt = map_to_vec(ps_base, [:p, :r1, :r2, :K, :r3, :r4, :r5, :r6, :d])
106-
dprob_alt = DiscreteProblem(u0_alt, (0.0, 100.0), ps_alt)
107-
jprob_alt = JumpProblem(dprob_alt, Direct(), higher_order_network_alt2...; rng = StableRNG(1234))
108+
u0_alt2 = map_to_vec(u0_base, [:X1, :X2, :X3, :X4, :X5, :X6, :X7, :X8, :X9, :X10])
109+
ps_alt2 = map_to_vec(ps_base, [:p, :r1, :r2, :K, :r3, :r4, :r5, :r6, :d])
110+
dprob_alt2 = DiscreteProblem(u0_alt2, (0.0, 100.0), ps_alt2)
111+
jprob_alt2 = JumpProblem(dprob_alt2, Direct(), higher_order_network_alt2...; rng = StableRNG(1234))
108112

109113
# Compares the simulations
110114
sol_base = solve(jprob_base, SSAStepper(); seed, saveat = 1.0)
111-
sol_alt = solve(jprob_alt, SSAStepper(); seed, saveat = 1.0)
112-
sol_base == sol_alt
115+
sol_alt1 = solve(jprob_alt1, SSAStepper(); seed, saveat = 1.0)
116+
sol_alt2 = solve(jprob_alt2, SSAStepper(); seed, saveat = 1.0)
117+
@test_broken sol_base == sol_alt1 == sol_alt2
113118
end
114119
end

0 commit comments

Comments
 (0)