Systems
A system is a part that holds elements, interactions, nested systems, a space, and a time. BaseSystem is the base
of every system: a subclass takes the parameters of its model in __init__, builds its parts from them in
_build_system, and derives its capability tags from its parts, which get_tags() returns. System is the generic
composite you build from parts. A general system of the core, such as MassActionSystem, builds the parts of a
structure that several fields share from a table of parameters. The ready-made systems of skcomplex.systems are
subclasses of these, one class per model. The catalog lists them by field and by topic, with
their import paths, their model parameters, and their capability tags, and all_systems of skcomplex.systems lists
them by field, topic, or tag. The table lists the system classes of the core.
| System | Import | Description |
|---|---|---|
System |
from skcomplex.core.components.system import System |
Composition of elements and the interactions between them, with nested systems. |
MassActionSystem |
from skcomplex.core.components.mass_action import MassActionSystem |
Species in compartments and the reactions between them at mass-action rates. |
A compatible system
A mass-action system in the mode jump has random reaction events, which GillespieSolver draws.
from skcomplex.core.components.mass_action import MassActionSystem
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import GillespieSolver
reactions = {'forth': ({'A': 1}, {'B': 1}, 0.3), 'back': ({'B': 1}, {'A': 1}, 0.1)}
isomerization = MassActionSystem(species={'A': 10.0, 'B': 0.0}, reactions=reactions, mode='jump')
sorted(isomerization.get_tags().laws), isomerization.get_tags().randomness
trajectory = simulate(isomerization, until=5, solver=GillespieSolver(), random_state=0)
trajectory.values('A.n')[-1]
(['jump'], 'stochastic')
3.0
An incompatible system
In the default mode rate the same reactions are rate equations, which GillespieSolver does not draw, so simulate
names the law kind.
from skcomplex.core.components.mass_action import MassActionSystem
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import GillespieSolver
from skcomplex.core.errors import TagError
reactions = {'forth': ({'A': 1}, {'B': 1}, 0.3), 'back': ({'B': 1}, {'A': 1}, 0.1)}
isomerization = MassActionSystem(species={'A': 10.0, 'B': 0.0}, reactions=reactions)
try:
simulate(isomerization, until=5, solver=GillespieSolver())
except TagError as error:
message = str(error)
message
assert 'laws rate' in message
The solver GillespieSolver does not support the laws rate of the system. Pass a solver that supports them, or none for the default.
Find ready-made systems by tag
all_systems takes the values of capability tags, so it finds the ready-made systems that a solver or an analysis
accepts.
from skcomplex.systems import all_systems
stochastic = all_systems(field='biology/epidemiology', tags={'randomness': 'stochastic'})
[name for name, _ in stochastic][:3]
['ActivityDrivenEpidemicsSystem', 'AdaptiveSISSystem', 'AgentBasedSIRSystem']