Skip to content

Solvers

A solver steps a system through time, or solves a static system at once. 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 it compiles the system, and raises a TagError when the solver 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 equation, jump, noise, rate, sampling, update
IterationSolver discrete map discrete any equation, 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
CollocationSolver ordinary differential equations continuous none equation, objective, 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, objective, 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
GradientFlowSolver static solution static any objective
MetropolisSolver static solution static any objective
MinimizeSolver static solution static any equation, objective
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, which together form a stochastic differential equation. EulerMaruyamaSolver supports both.

from skcomplex.core.components.elements import Element
from skcomplex.core.components.interactions import Interaction
from skcomplex.core.components.laws import NoiseLaw, RateLaw
from skcomplex.core.engine.solvers import EulerMaruyamaSolver
from skcomplex.core.systems import System

tank = Element('tank', values={'x': 10.0})
laws = lambda s: [RateLaw(s.target.x, -0.5 * s.target.x), NoiseLaw(s.target.x, 0.1)]
decay = Interaction('decay', roles={'target': 'tank'}, laws=laws)
system = System(elements=[tank], interactions=[decay], solver=EulerMaruyamaSolver()).prepare()
system.form_, sorted(EulerMaruyamaSolver.get_supported_tags().laws)
round(system.simulate(until=1, random_state=0).get_values('tank.x')[-1], 2)
('stochastic differential equations', ['equation', 'jump', 'noise', 'rate', 'update'])
6.15

The system is a stochastic differential equation, and the solver supports equation, jump, noise, rate, and update. With the seed 0 the tank holds 6.15 after one time unit, near the 6.07 of the decay without noise.

An incompatible solver

RK4Solver integrates deterministic equations and does not support noise laws, so prepare raises a SolverError.

from skcomplex.core.components.elements import Element
from skcomplex.core.components.interactions import Interaction
from skcomplex.core.components.laws import NoiseLaw, RateLaw
from skcomplex.core.engine.solvers import RK4Solver
from skcomplex.core.errors import SolverError
from skcomplex.core.systems import System

tank = Element('tank', values={'x': 10.0})
laws = lambda s: [RateLaw(s.target.x, -0.5 * s.target.x), NoiseLaw(s.target.x, 0.1)]
decay = Interaction('decay', roles={'target': 'tank'}, laws=laws)
try:
    System(elements=[tank], interactions=[decay], solver=RK4Solver()).prepare()
except SolverError as error:
    message = str(error)
message
assert 'does not support the laws NoiseLaw' in message
The system is not valid, with 2 error(s):
- system: The solver RK4Solver does not support the laws NoiseLaw. Pass a solver that supports the laws NoiseLaw. [solver-unsupported]
- decay: The NoiseLaw of decay needs diagonal noise, which the solver RK4Solver lacks. Pass a solver and a backend that support diagonal noise. [noise-unsupported] The laws make stochastic differential equations, which CoSimulationSolver, EulerMaruyamaSolver, FractionalEulerMaruyamaSolver, HeunSolver, LammpsSolver, MilsteinSolver, RenewalSolver support.

The message says that RK4Solver does not support the noise law, and names the solvers of stochastic differential equations.