4.1.8.6. causality/Stochsim

class causality.MassActionKinetics

A helper class for performing stochastic simulations where events are drawn according to the law of mass action. Importantly, if the underlying derivation graph is enlarged then syncSize() must be called before calling draw().

__init__(dg, inputRate, reactionRate, outputRate)

Construct a new instance, based on the given derivation graph. The return value of the rate callbacks must be 1) the rate and 2) a boolean telling whether the library should cache the rate. If True no more calls with the same argument will be made.

Parameters:
Raises:

LogicError if not dg.

Raises:

LogicError if neither dg.hasActiveBuilder nor dg.locked.

syncSize()

Enlarges the internal data structures to the current size of the underlying derivation graph.

draw(m)
Parameters:

m (Marking) – the population to take into account.

Returns:

one of the hyperedges enabled in m, randomly selected according to the low of mass action based on the given population/marking and the reaction rates. The second returned component is the sum of reactivity for the given reactions/hyperedges.

If no events are possible, then the second component is 0.

Use rngReseed() to seed the pseudo-random bit generator used for the selection.

Return type:

tuple[Union[EdgeAction, InputAction, OutputAction], float]

Raises:

LogicError if m is not a marking on the underlying derivation graph.

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.