3.2. stochsim
submodule¶
-
class
mod.stochsim.
Simulator
(*, labelSettings: mod.LabelSettings = mod.LabelSettings(mod.LabelType.String, mod.LabelRelation.Isomorphism), graphDatabase: List[mod.Graph], strategy: mod.DGStrat, initialState: Dict[mod.Graph, int], draw: Callable[[mod.DG], Callable[[List[mod.DGHyperEdge], mod.PetriNetMarking], Tuple[mod.DGHyperEdge, float]]] = DrawMassAction(), transfer: Dict[mod.Graph, Callable[[mod.Graph, int, float, float], float]] = {}, defaultTransfer: Optional[Callable[[mod.Graph, int, float, float], float]] = None, withSetCompare=True, sortReactions=False)¶ The main class for performing stochasim simulations.
- Parameters
labelSettings (mod.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__()
.strategy (mod.DGStrat) – a strategy that will be passed to
mod.DGBuilder.execute()
when the simulator needs new hyperedge/reaction information.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[[mod.DG], Callable[[list[mod.DGHyperEdge], mod.PetriNetMarking], tuple[mod.DGHyperEdge, float]]]) – 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
.transfer (dict[mod.Graph, Callable[[mod.Graph, int, float, float], float]]) –
a collection of callbacks used in each simulation step to forcibly add or remove copies of specific graphs/molecules. The collection is indexed by the graph/molecule to invoke the callback on. The callback is given
that same graph,
the population count of that graph in the current state,
the current simulation time,
the increase in simulation time for this step.
It must then return the number of copies to change the population count with. Use a negative count to remove copies and a positive to add. The count may be fractional, and will then be rounded by the simulator randomly weighted by the fractional part. If the resulting count removes more copies from the simulation than are present, then all copies are removed.
The helper classes
LinearTransfer
andExponentialTransfer
can be used as a shorthand to make specific types of callbacks.defaultTransfer – a callback similar to those in
transfer
, but will be applied to every graph/molecule with non-zero population count.
-
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.
DrawMassAction
(rate: Callable[[mod.DGHyperEdge], float] = lambda r: ...)¶ A creator for a drawing function implementing the law of mass action.
- Parameters
rate (Callable[[mod.DGHyperEdge], float]) – a callback for reaction rates, defaulting to a function returning 1.0 for every reaction.
-
class
mod.stochsim.
LinearTransfer
(change: float, perTime: float)¶ A shorthand for a linear transfer function.
Transfer with a fixed rate, given as a fraction
change/perTime
.- Parameters