Hi,
Apologies if this isn’t the correct forum for this style of question, but I think it could be viewed as a performance problem.
Sensitive/Resistant Birth Death Simulation
I have a birth-death simulation I am running in Julia. Specifically, I model sensitive and resistant cells growing over time.
I currently model the system as a Jump Problem using the ‘MassAction’ Jumps. For now, to keep the simulation simple, the populations evolve independently. Here is the code I use to set up these independent birth-death processes for sensitive (‘S’) and resistant populations (‘R’):
# Define the rate identities
rateidxs = [1, 2, 3, 4]
# Define the reactant stoichiometry
reactant_stoich =
[
[1 => 1], # b for S cells
[1 => 1], # d for S cells
[2 => 1], # b for R cells
[2 => 1], # d for R cells
]
# Define the net stoichiometry
net_stoich =
[
[1 => 1], # b for S cells
[1 => -1], # d for S cells
[2 => 1], # b for R cells
[2 => -1] # d for R cells
]
# Formulate as a mass action jump problem.
mass_act_jump = MassActionJump(reactant_stoich, net_stoich;
param_idxs=rateidxs)
prob = DiscreteProblem(u₀, tspan, p)
jump_prob = JumpProblem(prob, Direct(), mass_act_jump,
save_positions= (false, false))
Additionally (not shown here) I use callbacks to do the following:
- Switch between treated and non-treated environments periodically (I change the death rates of the sensitive cells
- Check for extinction (
if nS+nR == 0
) - Check for some carrying capacity being reached (
if nS+nR >= Nmax
)
Parameter Inference with ABC
This all runs as expected, and for a starting population of 1000 cells, and given the other parameters (time of growth, max population size, ratio of sensitive:resistant cells etc.) this takes around 1s to run. I use the simulation to infer various parameters via ABC and I can recover the true values of parameters I care about.
The problem is that the runtime of this simulation scales linearly with the number of cells. I eventually aim to use this for systems with millions of cells, and because of the large number of simulations one has to run for ABC, the time it takes to run becomes prohibitive.
Speeding up the Simulation
Are there any creative ways I might significantly improve the speed of this simulation? - And by significantly, I mean break the current linear relationship between cell number and simulation run time.
Thoughts I have had so far:
- It feels wasteful to be simulating each individual cell (which I think is what is going on under the hood in these JumpProblems? Which explains the way the sim scales with number of cells?) when I only care about 2 types… can I leverage the fact only have two species to speedup the simulation somehow?
- Instead of a jump problem I could use a stochastic differential equation (SDE)? - the problem here is that, because the population sizes often start at/approach 0, the SDE solution becomes unstable.
- Because once the population sizes reach a threshold the stochastic component of the model becomes insignificant, could I do some adaptive switching from a JumpProcess to an ODE when some population size is reached?
- Related to the previous point, is there a clever way I could combine a JumpProcess and an ODE to be constantly switching depending on what the population size was? - and would there be a way to still have the two models ‘talk to eachother’ (say if I wanted to allow cells to transition from one type to another, but one sub-population was currently being modelled via a JumpProcess whilst the other via an ODE?)
Thanks for any help, and apologies again if this is too vague a question for the Performance topic - please point me in the right direction if so.