Laws
A law is the mathematical object an interaction returns, such as a rate, a noise, a jump, or an update. Its kind is a tag, and so are the times and spaces it runs in and its randomness. The law kinds of a system are those of its interactions, and a solver or a backend runs a system only when it supports every one of them. The table lists what each law class declares.
| Law | Kind | Time | Space | Randomness |
|---|---|---|---|---|
BilinearLaw |
rate |
continuous |
lattice |
deterministic |
BoundaryLaw |
update |
any | any | deterministic |
CascadeLaw |
update |
discrete |
hypergraph, lattice, network |
deterministic |
CrossingLaw |
update |
continuous |
any | deterministic |
DissipatorLaw |
rate |
continuous |
any | deterministic |
DriveLaw |
update |
discrete |
hypergraph, lattice, network |
deterministic |
EmissionLaw |
jump |
discrete |
any | stochastic |
EncounterLaw |
rate |
continuous |
lattice |
deterministic |
EquationLaw |
equation |
continuous, static |
any | deterministic |
ExtremalLaw |
update |
discrete |
hypergraph, lattice, network |
stochastic |
FluxLaw |
rate |
continuous |
continuous, lattice |
deterministic |
FractionalNoiseLaw |
noise |
continuous |
any | stochastic |
GeneratorLaw |
rate |
continuous |
any | deterministic |
GradientStepLaw |
update |
discrete |
any | deterministic |
JumpLaw |
jump |
continuous |
any | stochastic |
LinearProgramLaw |
equation |
any | any | deterministic |
LocalRuleLaw |
update |
discrete |
hypergraph, lattice, network |
deterministic |
MatchLaw |
update |
discrete |
any | deterministic |
NoiseLaw |
noise |
continuous |
any | stochastic |
ProductionLaw |
update |
discrete |
any | deterministic |
RateLaw |
rate |
continuous |
any | deterministic |
RuleLaw |
update |
discrete |
any | deterministic |
SampleLaw |
sampling |
discrete |
hypergraph, lattice, network |
stochastic |
SubstitutionLaw |
update |
discrete |
any | deterministic |
TransferLaw |
update |
any | any | deterministic |
TransitionLaw |
jump |
discrete |
any | stochastic |
UpdateLaw |
update |
discrete |
any | deterministic |
A compatible law
An arrival that adds one unit at random times returns a jump law, which GillespieSolver supports.
from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import JumpInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import GillespieSolver
queue = CompartmentElement('queue', n=0.0)
arrive = JumpInteraction('arrive', target='queue', changes={'n': 1}, rate=lambda s: 2.0)
sorted(arrive.get_tags().laws)
system = System(elements=[queue], interactions=[arrive])
trajectory = simulate(system, until=5, solver=GillespieSolver(), random_state=0)
trajectory.values('queue.n')[-1]
['jump']
11.0
An incompatible law
EulerSolver integrates rates and does not draw jumps, so it rejects the system and names the law kind.
from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import JumpInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import EulerSolver
from skcomplex.core.errors import TagError
queue = CompartmentElement('queue', n=0.0)
arrive = JumpInteraction('arrive', target='queue', changes={'n': 1}, rate=lambda s: 2.0)
try:
simulate(System(elements=[queue], interactions=[arrive]), until=5, solver=EulerSolver())
except TagError as error:
message = str(error)
message
assert 'laws jump' in message
The solver EulerSolver does not support the laws jump of the system. Pass a solver that supports them, or none for the default.