4.2. stochsim
submodule¶
- class mod.stochsim.Simulator(*, labelSettings: mod.LabelSettings = mod.LabelSettings(mod.LabelType.String, mod.LabelRelation.Isomorphism), graphDatabase: List[mod.Graph], expandNetwork: Callable[[mod.DGBuilder, List[mod.Graph], List[mod.Graph]], None], initialState: Dict[mod.Graph, int], draw: Callable[[mod.DG], DrawFunction], drawTime: Callable[[float], float] = DrawTimeExponential(), withSetCompare: bool = True)¶
The main class for performing stochasim simulations.
- Parameters
labelSettings (LabelSettings) – a settings object that will be passed to
mod.DG.__init__()
.GraphDatabase (list[mod.Graph]) – a list of graphs that will be passed to
mod.DG.__init__()
.expandNetwork (Callable[ [DGBuilder, list[mod.Graph], list[mod.Graph]], None]) –
a callback which will be called when the simulator needs new hyperedge/reaction information. The callback will be given:
the DG builder object for the underlying derivation graph.
a list of graphs that were newly discovered in the last iteration.
a list of all graphs in the current state.
For example, if expansion is done via some
mod.DGStrat
,strat
, a reasonable callback could bedef expandNetwork(b, subset, universe): b.execute(addSubset(subset) >> addUniverse(universe) >> strat, verbosity=0)
The
ExpandByStrategy
class is a shorthand for this type of callback.initialState (dict[mod.Graph, int]) – the initial simulation state in terms of the number of copies of each graph/molecule. Graphs/molecules not mentioned are set to 0.
draw (Callable[[DG], DrawFunction]) – The simulator will initially create a
mod.DG
which is given to this function. It must then return a callable that is used in each simulation step to draw the next hyperedge/reaction. Defaults to a default constructed instance ofDrawMassAction
.drawTime (Callable[[float], float]) – The function to use for drawing the time increment in each simulation step. The function will be given the reactivity, and must return the time increment. Defaults to an instance of
DrawTimeExponential
.
- simulate(self, *, time: Optional[float] = None, iterations: Optional[int] = None)¶
Start/continue the simulation.
Simulate an additional amount of time or number of iterations, whichever is reached first.
- Parameters
- Returns
a references to the event trace for the simulation. It should not be modified.
- Return type
- class mod.stochsim.ExpandByStrategy(strat: mod.DGStrat)¶
A shorthand for an expansion callback that executes a strategy.
- Parameters
strat (DGStrat) – a strategy.
- class mod.stochsim.DrawFunction¶
An abstract base class for draw functions.
When constructing a simulator, a draw function creator must be given. When that is invoked, it must return an object that conforms to the interface of this class.
- draw(self, marking: mod.DGPetriNetMarking)¶
Called in order to draw the next edge event.
- Parameters
marking (DGPetriNetMarking) – the current state of the simulation. This may not be changed.
- Returns
one of the given hyperedges and a number indicating the reactivity of the system.
- Return type
- syncSize(self)¶
Called whenever the underlying derivation graph has changed size. If the drawing function has internal data structures, this method is where such data structures can be resized. The derivation graph must be given to this object by its creator.
- class mod.stochsim.DrawMassAction(*, inputRate: Union[Callable[[mod.DGVertex], float], float] = 0.0, reactionRate: Union[Callable[[mod.DGHyperEdge], float], float] = 1.0, outputRate: Union[Callable[[mod.DGVertex], float], float] = 0.0)¶
A creator for a drawing function implementing the law of mass action.
- Parameters
inputRate (Callable[[DGVertex], float] or float) – the rate used for pseudo-reactions for creating molecules, defaulting to 0.0.
reactionRate (Callable[[DGHyperEdge], float] or float) – a callback for reaction rates, defaulting to a function returning 1.0 for every reaction.
outputRate (Callable[[DGVertex], float] or float) – the rate used for pseudo-reactions for destroying molecules, defaulting to 0.0.