3.1.8.4. causality/Stochsim¶
3.1.8.4.1. Class MassActionKinetics
¶
-
class
mod.
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 callingdraw()
.
-
mod.
__init__
(dg, rate)¶ Construct a new instance, based on the given derivation graph. When evaluating reactions/hyperedges, the given callback is used to set the reaction rate. This rate may be cached by the object.
- Parameters
dg (DG) – the underlying derivation graph.
rate (Callable[[DGHyperEdge], float] or float) – the rate callback or constant.
- Raises
LogicError
ifnot dg
.- Raises
LogicError
if neitherdg.hasActiveBuilder
nordg.locked
.
-
mod.
syncSize
()¶ Enlarges the internal data structures to the current size of the underlying derivation graph.
-
mod.
draw
(possibles, m)¶ - Parameters
possibles (list[DGHyperEdge]) – the list of hyperedges to draw from.
m (PetriNetMarking) – the population to take into account.
- Returns
one of the given hyperedges, 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.
Use
rngReseed()
to seed the pseudo-random bit generator used for the selection.- Return type
- Raises
LogicError
ifpossibles
is empty.- Raises
LogicError
if an edge inpossibles
is null.- Raises
LogicError
if an edge inpossibles
does not belong to the underlying derivation graph.- Raises
LogicError
ifm
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.
3.1.8.4.2. Class EventTrace
¶
-
class
mod.
EventTrace
¶ A representation of a trace of events starting from an initial marking. An event is either a reaction/hyperedge being performed or a transfer of tokens out or in to the system.
-
__init__
(initialState)¶ Construct an empty event trace with an initial state. A copy of the given marking is being stored.
- Parameters
initialState (PetriNetMarking) – the marking to used as the initial state.
-
initialState
¶ (Read-only) Read a copy of the initial state for this event trace.
- Type
-
__getitem__
()¶ - Returns
the
i
th event in the trace.- Return type
- Raises
LogicError
ifi
is out of bounds.
-
__str__
()¶
-
addEdge
(time, e)¶ Append an edge event to the trace.
- Parameters
time (float) – the time associated with the event.
e (DGHyperEdge) – the hyperedge implementing the event
- Raises
LogicError
ifnot e
.- Raises
LogicError
ife
does not belong to the underlying derivation graph.
-
addTransfer
(time, v, count)¶ Append an edge event to the trace.
- Parameters
- Raises
LogicError
ifnot v
.- Raises
LogicError
ifv
does not belong to the underlying derivation graph.
-
print
()¶
Create a plot of the counts throughout the event trace at each time point. If the times given to
addEdge()
andaddTransfer()
at any point were decreasing or below 0, the resulting plot may fail to compile or look strange.- Returns
the filename for the PDF that will be compiled by the post processor.
- Return type
-