Skip to content

Solvers

A solver steps a system through time, or solves it at once for a static system. get_supported_tags() of a solver class returns the times, spaces, and law kinds it supports. simulate compares them with the tags of the system before compiling, and rejects a solver that lacks one. Leave the solver out and the tags choose the default solver. The table lists the supported tags of every solver, grouped by the mathematical form it solves.

Solver Form Time Space Law kinds
MesaSolver agent-based system discrete any update
CoSimulationSolver co-simulation continuous, discrete any any
IterationSolver discrete map discrete any equation, jump, update
FractionalABMSolver fractional differential equations continuous any equation, rate, update
GrunwaldLetnikovSolver fractional differential equations continuous any equation, rate, update
L1Solver fractional differential equations continuous any equation, rate, update
GillespieSolver jump process continuous any jump, update
LatticeSolver lattice dynamics discrete cell complex, hypergraph, lattice, network, phase space update
GradientDescentSolver learning by gradient steps discrete none update
MonteCarloSolver Monte Carlo sampling discrete cell complex, hypergraph, lattice, network, phase space sampling
JumpTrajectoriesSolver operator dynamics continuous any rate
LindbladSolver operator dynamics continuous any rate
OperatorSolver operator dynamics continuous any rate
UnitarySolver operator dynamics continuous any rate
CollocationSolver ordinary differential equations continuous none equation, rate
CrankNicolsonSolver ordinary differential equations continuous any equation, rate, update
ETDRK4Solver ordinary differential equations continuous any equation, rate, update
EulerSolver ordinary differential equations continuous none rate, update
IMEX2Solver ordinary differential equations continuous any equation, rate, update
IMEXEulerSolver ordinary differential equations continuous any equation, rate, update
KineticSolver ordinary differential equations continuous lattice, phase space rate
LammpsSolver ordinary differential equations continuous any equation, noise, rate, update
PontryaginSolver ordinary differential equations continuous none equation, rate, update
RK4Solver ordinary differential equations continuous any equation, jump, rate, update
SSPRKSolver ordinary differential equations continuous any rate, update
ScipyODESolver ordinary differential equations continuous any equation, rate, update
SemiLagrangianSolver ordinary differential equations continuous lattice, phase space rate
SplitSolver ordinary differential equations continuous any equation, rate, update
StrangSplittingSolver ordinary differential equations continuous lattice, phase space rate
VelocityVerletSolver ordinary differential equations continuous any equation, rate, update
Yoshida4Solver ordinary differential equations continuous any equation, rate, update
RenewalSolver renewal process continuous any equation, jump, noise, rate, update
RewritingSolver rewriting system discrete any update
RootSolver static solution static any equation
EulerMaruyamaSolver stochastic differential equations continuous any equation, jump, noise, rate, update
FractionalEulerMaruyamaSolver stochastic differential equations continuous any equation, noise, rate, update
HeunSolver stochastic differential equations continuous any equation, noise, rate, update
MilsteinSolver stochastic differential equations continuous any equation, noise, rate, update

A compatible solver

A rate with a noise term returns a rate and a noise law, and EulerMaruyamaSolver supports both.

from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import RateInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import EulerMaruyamaSolver

tank = CompartmentElement('tank', n=10.0)
decay = RateInteraction('decay', target='tank', state='n', rate=lambda s: -0.5 * s.target.n, noise=0.1)
system = System(elements=[tank], interactions=[decay])
sorted(system.get_tags().laws), sorted(EulerMaruyamaSolver.get_supported_tags().laws)
trajectory = simulate(system, until=1, solver=EulerMaruyamaSolver(), random_state=0)
round(trajectory.values('tank.n')[-1], 2)
(['noise', 'rate'], ['equation', 'jump', 'noise', 'rate', 'update'])
6.15

An incompatible solver

RK4Solver integrates deterministic equations and does not support the noise law kind.

from skcomplex.core.components.elements import CompartmentElement
from skcomplex.core.components.interactions import RateInteraction
from skcomplex.core.components.system import System
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.engine.solvers import RK4Solver
from skcomplex.core.errors import TagError

tank = CompartmentElement('tank', n=10.0)
decay = RateInteraction('decay', target='tank', state='n', rate=lambda s: -0.5 * s.target.n, noise=0.1)
try:
    simulate(System(elements=[tank], interactions=[decay]), until=1, solver=RK4Solver())
except TagError as error:
    message = str(error)
message
assert 'laws noise' in message
The solver RK4Solver does not support the laws noise of the system. Pass a solver that supports them, or none for the default.