Skip to content

Commit 7ce1a8a

Browse files
committed
fix
1 parent ea25919 commit 7ce1a8a

File tree

3 files changed

+39
-52
lines changed

3 files changed

+39
-52
lines changed

benchmarks/Jumps/AggregatorBenchmark.jmd

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,70 +33,57 @@ concentration curve for each method.
3333

3434

3535
# Performance Benchmark (Sanft 2015)
36-
For our performance benchmark test, we will look at a very simple reaction network.
37-
```julia
38-
rn = @reaction_network begin
39-
@parameters kA kB
40-
kA, 0 --> A
41-
kB, 0 --> B
42-
end
43-
```
36+
For our performance benchmark test, we will look at a very simple reaction network consisting of conversion reactions of the form A <--> B.
37+
38+
Below we define the function that we will use to generate the jump problem from this network. Fundamentally
39+
we want to test how quickly each SSA updates dependent reaction times in response to a reaction event. To
40+
standardize this, we will make each reaction force 10 updates. In a network of conversion reactions Ai <--> Aj,
41+
each reaction event will force updates on any reaction that has Ai or Aj as their reactant. The way we will
42+
implement 10 updates per event is to make each species the reactant (and product) of 5 different reactions.
4443

45-
Below we define the function that we will use to generate the jump problem from this network. Fundamentally we want to test how quickly each SSA updates dependent reaction times in response to a reaction event. To standardize this, we will make each reaction force 10 updates, and force updates to the times by rescaling the rate of those reactions by randexp() at each timestep.
46-
```julia
47-
# z A B
48-
u0 = [1., 1, 1]
49-
p = (kA = 1.0, kB = 2.0)
50-
rateA(u, p, t) = p.kA * u[1]
51-
rateB(u, p, t) = p.kB * u[1]
52-
53-
# Our affect resamples u[1] to effectively resample the next time-to-reaction. This is the
54-
# simplest way to get random updates on the times, since we don't resample times
55-
# when the propensities are updated.
56-
affectA!(integrator) = (integrator.u[1] = randexp(rng); integrator.u[2] += 1)
57-
affectB!(integrator) = (integrator.u[1] = randexp(rng); integrator.u[3] += 1)
5844

45+
```julia
5946
function generateJumpProblem(method, N::Int64, end_time)
6047
depgraph = Vector{Vector{Int64}}()
6148
jumpvec = Vector{ConstantRateJump}()
49+
numspecies = div(N, 5)
50+
u0 = 10 * ones(Int64, numspecies)
51+
52+
jumptovars = Vector{Vector{Int64}}()
53+
vartojumps = Vector{Vector{Int64}}()
54+
55+
# This matrix will store the products of each reaction. Reactions 1-5 will have u[1] as the reactant,
56+
# reactions 6-10 will have u[2] as the reactant, etc., and their products will be randomly sampled.
57+
prods = zeros(Int64, 5, numspecies)
58+
for i in 1:numspecies
59+
(@view prods[:, i]) .= rand(1:numspecies, 5)
60+
push!(vartojumps, vcat(5*(i-1)+1:5*(i-1)+5, @view prods[:, i]))
61+
end
62+
63+
# For each reaction, it will update the rates of reac
64+
for sub in 1:numspecies, i in 1:5
65+
prod = prods[i, sub]
66+
67+
push!(depgraph, vcat(5*(sub-1)+1:5*(sub-1)+5, 5*(prod-1)+1:5*(prod-1)+5))
68+
push!(jumptovars, [sub, prod])
69+
70+
rate(u, p, t) = u[i]
71+
affect!(integrator) = begin
72+
integrator.u[sub] -= 1
73+
integrator.u[prod] += 1
74+
end
6275

63-
for i in 1:N
64-
# We make each reaction affect the rates of 10 others, so there are 10 updates per jump.
65-
push!(depgraph, rand(rng, 1:N, 10))
66-
iseven(i) ? push!(jumpvec, ConstantRateJump(rateA, affectA!)) :
67-
push!(jumpvec, ConstantRateJump(rateB, affectB!))
76+
push!(jumpvec, ConstantRateJump(rate, affect!))
6877
end
6978

7079
jset = JumpSet((), jumpvec, nothing, nothing)
7180
dprob = DiscreteProblem(u0, (0., end_time), p)
72-
varstojumps = [collect(1:N), Int64[], Int64[]]
73-
jumptovars = [i%2 == 1 ? [2] : [3] for i in 1:N]
74-
jump_prob = JumpProblem(dprob, method, jset; dep_graph = depgraph, save_positions = (false, false), rng, jumptovars_map = jumptovars, vartojumps_map = varstojumps)
81+
jump_prob = JumpProblem(dprob, method, jset; dep_graph = depgraph, save_positions = (false, false),
82+
rng, jumptovars_map = jumptovars, vartojumps_map = vartojumps)
7583
jump_prob
7684
end
7785
```
7886

79-
# Sanity Check
80-
Let's look at a few reaction networks to make sure we get consistent results for all the networks.
81-
Let's look at one example to make sure that our model seems reasonable. Since
82-
half of the reactions correspond to 0 --> A and half correspond to 0 --> B,
83-
and the 0 --> B rate constant is twice the 0 --> A rate constant, we'd expect
84-
that the A/B ratio would approach 1/2 as the simulation goes on.
85-
86-
```julia
87-
end_time = 10.0; N = 1000
88-
algs = [DirectCR(), CCNRM(), NRM(), RSSACR()]
89-
plt = plot()
90-
91-
for alg in algs
92-
jprob = generateJumpProblem(alg, N, end_time)
93-
sol = solve(jprob, SSAStepper(); saveat = end_time/200)
94-
ABratio = [u[2]/u[3] for u in sol.u]
95-
plot!(plt, sol.t, ABratio, label="$alg", ylims = (0., 1.))
96-
end
97-
plot!(plt)
98-
```
99-
10087
# Benchmarking performance of the methods
10188
We can now run the solvers and record the performance with `BenchmarkTools`.
10289
Let's first create a `DiscreteCallback` to terminate simulations once we reach

benchmarks/Jumps/BCR_Benchmark.jmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author:
77
using JumpProcesses, Plots, StableRNGs, Random, BenchmarkTools, ReactionNetworkImporters, StatsPlots, Catalyst
88
```
99

10-
We will benchmark the aggregators of JumpProcesses on a B-cell receptor network (1122 species, 24388 reactions).[^1]
10+
We will benchmark the aggregators of JumpProcesses on a B-cell receptor network (1122 species, 24388 reactions).[^1] This model reaches equilibrium after 10,000 seconds.
1111

1212
# Model Benchmark
1313
We define a function to benchmark the model and then plot the results in a benchmark.

benchmarks/Jumps/Fceri_gamma2_Benchmark.jmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author:
77
using JumpProcesses, Plots, StableRNGs, Random, BenchmarkTools, ReactionNetworkImporters, StatsPlots, Catalyst
88
```
99

10-
We will benchmark the aggregators of JumpProcesses on a human IgE receptor signaling network (3744 species, 58276 reactions).[^1, ^2]
10+
We will benchmark the aggregators of JumpProcesses on a human IgE receptor signaling network (3744 species, 58276 reactions)[^1, ^2]. This network reaches steady state after 150 seconds.
1111

1212
# Model Benchmark
1313
We define a function to benchmark the model and then plot the results in a benchmark.

0 commit comments

Comments
 (0)