Static systems
This page solves a system of equations that has no time axis, such as a dose-response curve, and sweeps its
parameters. A system whose laws are only ConstraintLaws is static: each
equation names its target, the state it solves for, and a run solves them once and gives one frame.
Equations and sweeps
This section computes the surviving fraction of cells after a dose of radiation, by the linear-quadratic model
exp(-0.3 D - 0.03 D^2), and sweeps the dose. The Element holds the
survival and the dose, and the interaction radiation sets the equation of the survival, so the survival is a state
and the dose a parameter. A function builds the System from the dose, so the
experiment sweep can run it once per value.
from sage.all__sagemath_symbolics import exp
from skcomplex.core.components.elements import Element
from skcomplex.core.components.interactions import Interaction
from skcomplex.core.components.laws import ConstraintLaw
from skcomplex.core.experiments import sweep
from skcomplex.core.systems import System
def survive(s):
survival, dose = s.target.survival, s.target.dose
return [ConstraintLaw(survival == exp(-0.3 * dose - 0.03 * dose**2), target=survival)]
def dose_response(dose=2.0):
cells = Element('cells', values={'survival': 0.0, 'dose': dose})
return System(elements=[cells], interactions=[Interaction('radiation', roles={'target': 'cells'}, laws=survive)])
result = sweep(dose_response, {'dose': [0.0, 2.0]}, until=0.0, outputs=['cells.survival'])
[round(float(row['cells.survival']), 4) for row in result.rows]
[1.0, 0.4868]
The survival is 1.0 without a dose and 0.4868 after a dose of 2. Each static run gives one row of the sweep. The equations are solved in one of two ways.
- The compiler solves the equations with Sage when it finds a unique explicit solution, and
problem.equationsholds it. - Otherwise
RootSolversolves them withscipy.optimize.rootand their exact Jacobian, from the initial state as the guess. It raises aSolverErrorthat names the equations and the largest residual when the solve does not converge.
Equations combine across the components of a system.
- A target on a group gives one unknown per member, and reductions such as
totalcouple the members. - The equations of one target from every element and interaction add.
- A system without equations solves to its initial state, so its observables run on quenched states in one frame.
prepare raises a ValidationError with the code equation-target for an equation with no target, or with a target
that is not a state.
Log-sum-exp
This section reduces over a group without overflow. log_sum_exp(expression, over=None) reduces over the members of a
group like total, as log sum_j exp(a_j), without overflow for values of any size. A system-level observable cannot
reach a group from another element. So a quantity built on it is an ConstraintLaw on a scalar element, read by an
interaction that binds the group. The random energy system of Derrida, RandomEnergySystem of the catalog, computes
its entropy this way, from the energies of all the configurations of its spins.
from skcomplex.systems.physics.statistical_mechanics import RandomEnergySystem
trajectory = RandomEnergySystem(n_spins=12, temperature=2.0).prepare().simulate(until=1.0)
round(float(trajectory.get_values('ensemble.entropy')[0]), 4)
0.6309
With 12 spins at temperature 2.0, the entropy per spin is 0.6309.
Quenched disorder, randomness drawn once and then held fixed, is drawn when the system builds its components. So a
disorder average sweeps its random_state as an axis of sweep. The replicates of ensemble share one draw of the
disorder and vary only the dynamics.
Contact clusters
This section measures the clusters that points form when they touch. The analysis clusters(points, kind=...,
radius=...) reads the positions of points, joins those closer than twice the radius, and measures their clusters. A
cluster spans along axis when it holds points within the radius of both faces of the space.
from skcomplex.core.analysis import clusters
clusters([[0, 0], [1, 0], [5, 5]], kind='sizes', radius=0.6).sizes.tolist()
[2, 1]
The first two points lie one apart, less than twice the radius 0.6, so they form a cluster of size 2. The third point stands alone.