Tutorials › Quantitative Systems Pharmacology (QSP) › Exact Simulation of Delayed Reaction Events

Delay and Stochastic Extensions · Tutorial 106 of 799

Exact Simulation of Delayed Reaction Events

You will build an exact event-scheduling algorithm for fixed-delay reactions and see how pending completions interact with new reaction initiations.

Advanced 12 min read

What You'll Learn

  • Distinguish a reaction’s initiation update from its scheduled completion update.
  • Compare a stochastic initiation time with the earliest pending completion.
  • Explain why propensities must be recalculated after every state-changing event.
  • Handle multiple completions at the same time consistently with the model.
  • Identify assumptions and failure modes of exact delayed-event simulation.

Why Delays Require an Event Queue

In an ordinary stochastic simulation, each reaction changes the state as soon as it fires. A fixed-delay reaction has two relevant times: the time it is initiated and the later time when its completion effect occurs. Between those times, other reactions may fire and change which reactions are possible. An exact simulation must therefore represent both the current state and the reactions already scheduled to complete.

The key computational distinction is between a reaction initiation and a reaction completion. An initiation is selected stochastically using the current propensities. A completion occurs at a previously determined time; it is not a new random reaction firing. The simulator must compare the next possible stochastic initiation with the earliest scheduled completion and process whichever comes first.

Definition: For delayed reaction channel \(j\), let \(a_j(x)\) be its initiation propensity in state \(x\), let \(\nu_j^{I}\) be its state change at initiation, let \(\nu_j^{C}\) be its state change at completion, and let \(\tau_j>0\) be its fixed delay. If the channel initiates at time \(t\), the model applies \(\nu_j^{I}\) at \(t\) and schedules \(\nu_j^{C}\) at \(t+\tau_j\). A pending event is a scheduled completion together with its time and completion update.

This two-update description makes the reaction semantics explicit. For example, a reaction that consumes reactants when it begins and produces products after a delay has \(\nu_j^{I}\) equal to the reactant loss and \(\nu_j^{C}\) equal to the product gain. A different biological assumption may reserve reactants until completion; that requires different state updates and feasibility rules. The scheduling algorithm does not decide which interpretation is biologically appropriate.

Assume that, between events, the state is constant and each initiation propensity is therefore constant. Given state \(x\), the waiting time to the next initiation is exponentially distributed with rate \(a_0(x)=\sum_j a_j(x)\), and channel \(j\) is selected with probability \(a_j(x)/a_0(x)\). Propensities must be nonnegative and consistent with the model’s available molecules. The updates at initiation and completion must also leave the state valid. These assumptions are the basis for exact event scheduling.

The Event-Scheduling Algorithm

Maintain the current time \(t\), the state \(x\), and a priority queue of pending completions ordered by their scheduled times. At each step, calculate the next stochastic initiation time from the current propensities, then compare it with the earliest pending completion. A queued completion is processed before any later proposed initiation. Once a state-changing event occurs, the old proposed initiation is no longer valid: calculate propensities again and draw a new candidate.

1
Calculate the current initiation rate.
Evaluate \(a_j(x)\) for each channel and set \(a_0(x)=\sum_j a_j(x)\). If \(a_0(x)=0\), there is no stochastic initiation until a pending completion changes the state.
2
Draw a candidate initiation.
If \(a_0(x)>0\), draw \(r_1\) uniformly from \((0,1)\) and set \(\Delta=-\ln(r_1)/a_0(x)\). The candidate time is \(t+\Delta\). Draw an independent uniform value to select a channel with probabilities \(a_j(x)/a_0(x)\).
3
Compare the candidate with the queue.
If the earliest pending completion is before the candidate time, advance to that completion, apply its update, remove it from the queue, and return to Step 1. Discard the candidate.
4
Process the initiation if it comes first.
Advance to the candidate time, apply \(\nu_j^{I}\), and, when \(\tau_j>0\), insert the completion update \(\nu_j^{C}\) at time \(t+\tau_j\). Then return to Step 1.

A reaction with no delay can be represented as an immediate state change in its initiation step. The description above treats delayed channels as having positive fixed delays, avoiding the special case of a zero-delay event being inserted at the current time.

Why the Comparison Gives an Exact Simulation

Suppose the current propensities are constant up to the next scheduled completion, which occurs after \(d\) time units. Before that completion, the probability that no initiation occurs for \(u\) time units is \(e^{-a_0(x)u}\). Thus the candidate waiting time drawn from an exponential distribution is the correct waiting time for the next initiation if the state remains unchanged.

$$ P(\text{initiation before completion})=P(\Delta<d)=1-e^{-a_0(x)d}. $$

If the candidate time is later than the completion, the state changes at the completion and may have new propensities. The candidate drawn under the old state must not be used to select a later reaction. Instead, recompute the rates in the new state. The exponential waiting-time distribution is memoryless: conditional on no initiation before a fixed time \(d\), the remaining wait has the same exponential distribution with rate \(a_0(x)\). Therefore drawing afresh after processing the completion gives the correct post-completion waiting time.

At an initiation, the channel probabilities \(a_j(x)/a_0(x)\) are the standard competing-hazards probabilities. The channel selection is made using the pre-initiation state; after applying its initiation update, the propensity calculation is repeated. Together, this race among initiations and the exact ordering of scheduled completions reproduce the model’s event process, provided the stated assumptions hold.

Worked Example: A Pending Completion Precedes the Candidate

At time \(t=2.0\) minutes, suppose the state has two available initiation channels with propensities \(0.8\) and \(0.2\) events per minute. One completion is already scheduled for \(2.7\) minutes. Use \(r_1=0.30\) to calculate the candidate initiation time and decide what the simulator does.

The total initiation propensity is \(a_0=0.8+0.2=1.0\) per minute. The proposed waiting time is \(\Delta=-\ln(0.30)/1.0=1.204\) minutes, so the candidate initiation time is \(2.0+1.204=3.204\) minutes.

The pending completion at \(2.7\) minutes is earlier than the candidate at \(3.204\) minutes. The simulator advances to \(2.7\), applies the completion update, removes that event from the queue, and recalculates the propensities. It discards the candidate time and the associated channel draw. Keeping that candidate would incorrectly use rates calculated for a state that stopped being current at \(2.7\) minutes.

New Initiations Do Not Cancel Earlier Completions

A scheduled completion remains in the queue when another reaction initiates, unless the model explicitly specifies a cancellation mechanism. In particular, if reactants are consumed at initiation, later changes in their availability do not undo a completion that was already scheduled. This is why the initiation update must encode what is consumed immediately and the completion update must encode what is produced later.

Worked Example: Two Delayed Initiations Compete With an Immediate Reaction

Let \(X\) be the available reactant. A delayed channel consumes one \(X\) at initiation and produces one \(Y\) two minutes later, with propensity \(0.2X\) per minute. An immediate channel consumes one \(X\) and produces one \(Z\), with propensity \(0.1X\) per minute. Initially, \(X=3\), \(Y=Z=0\), and the queue is empty. Suppose the random draws lead to a delayed initiation after \(0.5\) minutes, then an immediate initiation \(0.5\) minutes later.

Initially, the propensities are \(0.2(3)=0.6\) and \(0.1(3)=0.3\) per minute, giving total rate \(0.9\). A waiting time of \(0.5\) minutes is possible with \(r_1=e^{-0.9(0.5)}=0.6376\). If the channel-selection draw gives a value below \(0.6/0.9=0.6667\), the delayed channel is selected.

At \(t=0.5\) minutes, initiation consumes one \(X\): the state becomes \(X=2\), and a completion adding one \(Y\) is scheduled at \(t=2.5\). The updated propensities are \(0.4\) for the delayed channel and \(0.2\) for the immediate channel, total \(0.6\) per minute. Another waiting time of \(0.5\) minutes is possible with \(r_1=e^{-0.6(0.5)}=0.7408\). A channel-selection draw above \(0.4/0.6=0.6667\) selects the immediate channel.

At \(t=1.0\), the immediate initiation consumes one more \(X\) and produces one \(Z\), leaving \(X=1\), \(Z=1\). The pending production of \(Y\) at \(t=2.5\) remains scheduled. The next propensities must be calculated from the updated state, while the simulator continues to retain the completion time already in the queue.

Multiple Completions, Diagnostics, and Alternatives

Two or more events can have the same completion time, especially when they share a fixed delay and were initiated simultaneously or at the same recorded time. If their completion updates are additive and the model defines them as simultaneous, apply their combined update as one batch, then recalculate propensities. For example, two pending completions each adding one \(Y\) change \(Y\) by two at their shared time. If updates are not additive, or their order could affect validity, the model must specify how coincident completions are resolved; an arbitrary software ordering should not silently become a biological assumption.

Under a continuous exponential waiting-time model, an independently drawn initiation has probability zero of landing at exactly a fixed completion time. Nonetheless, ties can occur from finite-precision arithmetic or when multiple completions share a scheduled time. A practical implementation should use a documented tie rule: batch compatible simultaneous completions, apply their updates consistently, and then recalculate propensities. It should not execute an initiation based on rates calculated before those completions.

Useful diagnostics follow directly from the event semantics. Check that completion times are no earlier than their initiations, that the queue is processed in time order, and that every initiation uses propensities from the current state. Track the queue in a small hand-worked case and verify that each scheduled completion occurs once. If species counts become negative, investigate the reaction updates and feasibility rules; do not repair the path by truncating counts to zero. Also check that a newly initiated event does not accidentally overwrite or erase an unrelated pending event.

This method differs from tau-leaping, which approximates groups of reaction firings over a time step, and from deterministic delay equations, which describe continuous-valued population dynamics rather than individual stochastic events. Transit-chain models can represent delay dispersion through extra stochastic or deterministic stages, rather than one fixed completion time per initiation. Those approaches may be useful for different scientific questions, but they do not replace exact scheduling when the intended model has discrete events with fixed completion delays. Exactness here means exact simulation of the specified stochastic model, not proof that the model is biologically correct.

Common pitfall: If a proposed initiation lies after the earliest pending completion, retaining that proposal and executing it later uses a waiting time and channel choice based on outdated propensities. Process the completion first, discard the proposal, and draw again from the updated state. Similarly, do not cancel a pending event merely because another reaction changed the state; cancellation must be part of the model’s explicit rules.

Worked Example: Applying Simultaneous Completions as a Batch

At time \(t=4\) minutes, two pending completions are both scheduled. One adds one molecule of \(A\), and the other adds one molecule of \(B\). Just before the events, \(A=2\) and \(B=0\). A reaction has propensity \(0.5A+0.25B\) per minute. Find the state and propensity immediately after the completions.

Under the stated simultaneous, additive update rule, the combined completion update is \((\Delta A,\Delta B)=(1,1)\). Thus \(A=3\) and \(B=1\) immediately after \(t=4\). The reaction propensity is then \(0.5(3)+0.25(1)=1.75\) per minute. The simulator uses this updated propensity for the next stochastic waiting-time draw; it does not draw using the pre-completion rate \(0.5(2)+0.25(0)=1.0\) per minute.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. A candidate initiation is at \(6.4\) minutes and the earliest pending completion is at \(6.1\) minutes. Which event is processed first, and what happens to the candidate?
  2. A delayed reaction consumes two \(X\) molecules at initiation and produces one \(Y\) molecule after a fixed delay. State its initiation and completion updates.
  3. Two compatible pending completions at the same time each add one \(B\). If \(B=4\) beforehand, what is the post-completion value, and when are propensities recalculated?
  4. Why is it generally incorrect to keep a candidate initiation drawn before processing an earlier completion?

Solutions. (1) Process the completion at \(6.1\) minutes, apply its update, and discard the candidate at \(6.4\); recalculate propensities and draw again. (2) The initiation update consumes two \(X\), so its \(X\) component is \(-2\); the completion update adds one \(Y\), so its \(Y\) component is \(+1\). Other components are zero unless specified by the model. (3) Apply the simultaneous additive updates as a batch, giving \(B=4+1+1=6\), then recalculate propensities. (4) The completion may change the state and hence the propensities; the old candidate was generated using the pre-completion rates and is not valid for the new state.

Clinical Biostats