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 calling draw().

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 if not dg.

Raises

LogicError if neither dg.hasActiveBuilder nor dg.locked.

mod.syncSize()

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

mod.draw(possibles, m)
Parameters
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

tuple[DGHyperEdge, float]

Raises

LogicError if possibles is empty.

Raises

LogicError if an edge in possibles is null.

Raises

LogicError if an edge in possibles does not belong to the underlying derivation graph.

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.

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

PetriNetMarking

__len__()
Returns

the number of events in the trace.

Return type

int

__getitem__()
Returns

the ith event in the trace.

Return type

EdgeEvent or TransferEvent

Raises

LogicError if i 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 if not e.

Raises

LogicError if e does not belong to the underlying derivation graph.

addTransfer(time, v, count)

Append an edge event to the trace.

Parameters
  • time (float) – the time associated with the event.

  • v (DGVertex) – the vertex to transfer.

  • count (int) – the number of copies of v to transfer. It may be negative for extraction and positive for input.

Raises

LogicError if not v.

Raises

LogicError if v 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() and addTransfer() 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

str

3.1.8.4.3. Class EventTrace.EdgeEvent

class EventTrace.EdgeEvent

A representation of an edge event in an event trace.

time

(Read-only) the associated time for the event.

Type

float

edge

(Read-only) the hyperedge for the event.

Type

DGHyperEdge

3.1.8.4.4. Class EventTrace.TransferEvent

class EventTrace.TransferEvent

A representation of a trasfer event in an event trace.

time

(Read-only) the associated time for the event.

Type

float

vertex

(Read-only) the vertex being transferred.

Type

DGVertex

count

(Read-only) the amount being transferred. It is negative for extraction and positive for input.

Type

int