Skip to content

Statistical mechanics

Statistical mechanics systems.

The package covers gases, fluids, spin systems, lattice processes, urns, master equations, and their measures.

ASEPSystem(n_sites=100, *, alpha=0.3, gamma=0.7, p=1.0, q=0.0, density=0.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The asymmetric simple exclusion process on an open line, in continuous time.

A particle hops to the empty right neighbour at rate p and to the empty left neighbour at rate q, enters the empty first site at rate alpha, and leaves the last site at rate gamma, the exit rate that Bertin writes gamma and others write beta. For p = 1 and q = 0 the current is alpha (1 - alpha) in the low-density phase alpha < 1/2, gamma > alpha, gamma (1 - gamma) in the high-density phase gamma < 1/2, gamma < alpha, and 1/4 in the maximal-current phase alpha, gamma > 1/2. The system has the occupations lane.n.

Parameters:

Name Type Description Default
n_sites int

The number of sites.

100
alpha float

The entry rate.

0.3
gamma float

The exit rate.

0.7
p float

The rate of hops to the right.

1.0
q float

The rate of hops to the left.

0.0
density float

The initial fraction of occupied sites.

0.0
random_state int | Generator | None

The seed or generator of the initial occupations.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ASEPSystem
>>> len(ASEPSystem(10).prepare().system_.interactions)
3
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
def __init__(
    self,
    n_sites: int = 100,
    *,
    alpha: float = 0.3,
    gamma: float = 0.7,
    p: float = 1.0,
    q: float = 0.0,
    density: float = 0.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_sites = n_sites
    self.alpha = alpha
    self.gamma = gamma
    self.p = p
    self.q = q
    self.density = density
    self.random_state = random_state

AbsorbingBirthDeathSystem(*, kappa=2.0, nu=1.0, lam=1.0, volume=100.0, density=1.0, epsilon=0.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The fully connected branching and annihilation process.

The process is active above kappa = nu until it dies out.

The deterministic density obeys d rho / dt = (kappa - nu) rho - lambda rho^2, with the active fixed point rho_0 = (kappa - nu) / lambda. With fluctuations the empty state absorbs every run, but above the transition the active state is metastable, with relative fluctuations sigma / rho_0 = (lambda / (kappa - nu)) sqrt(kappa / (lambda V)) and a lifetime that grows like exp(V phi(0)) / nu. Below the transition the particles die out in a time of order 1 / (nu - kappa). A small epsilon makes the empty state leave, as in exercise 3.3 of Bertin. The system has the number of particles particles.n.

Parameters:

Name Type Description Default
kappa float

The branching rate.

2.0
nu float

The decay rate.

1.0
lam float

The annihilation rate.

1.0
volume float

The volume V.

100.0
density float

The initial density, rounded to a whole number of particles.

1.0
epsilon float

The rate at which a particle appears in the empty state.

0.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import AbsorbingBirthDeathSystem
>>> AbsorbingBirthDeathSystem(volume=50.0).prepare().system_.elements[0].n
50.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_absorbing_processes.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def __init__(
    self,
    *,
    kappa: float = 2.0,
    nu: float = 1.0,
    lam: float = 1.0,
    volume: float = 100.0,
    density: float = 1.0,
    epsilon: float = 0.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.kappa = kappa
    self.nu = nu
    self.lam = lam
    self.volume = volume
    self.density = density
    self.epsilon = epsilon

BoltzmannAverageElement(label, log_partition=0.0, energy=0.0, entropy=0.0)

Bases: Element

Log partition function, mean energy, and entropy per spin of a group of levels.

Parameters:

Name Type Description Default
label str

The label of the element.

required
log_partition float

The initial guess of the log partition function, which the equations replace.

0.0
energy float

The initial guess of the mean energy, which the equations replace.

0.0
entropy float

The initial guess of the entropy per spin, which the equations replace.

0.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import BoltzmannAverageElement
>>> BoltzmannAverageElement('ensemble').entropy
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_random_energy.py
47
48
49
50
51
52
53
54
55
56
57
def __init__(
    self,
    label: str,
    log_partition: float = 0.0,
    energy: float = 0.0,
    entropy: float = 0.0,
) -> None:
    super().__init__(label)
    self.log_partition = log_partition
    self.energy = energy
    self.entropy = entropy

BoltzmannSumInteraction(label, *, target, levels, temperature=1.0, n_spins=1.0)

Bases: Interaction

Boltzmann sums over a group of levels.

The sums give the log partition function, mean energy, and entropy per spin.

The log partition function is ln Z = log sum_j exp(-E_j / T), the mean energy is U = sum_j E_j exp(-E_j / T - ln Z), and the entropy per spin is (ln Z + U / T) / N. The sums reduce in log space, so they do not overflow at any temperature.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the element that holds the averages.

required
levels Role

The path of the group of levels.

required
temperature Annotated[float, open(0, oo)]

The temperature.

1.0
n_spins Annotated[float, open(0, oo)]

The number of spins the entropy is divided by.

1.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import BoltzmannSumInteraction
>>> BoltzmannSumInteraction('sums', target='ensemble', levels='levels', temperature=0.5).temperature
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_random_energy.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def __init__(
    self,
    label: str,
    *,
    target: Role,
    levels: Role,
    temperature: Annotated[float, RealSet.open(0, oo)] = 1.0,
    n_spins: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.levels = levels
    self.temperature = temperature
    self.n_spins = n_spins

BondSamplingInteraction(label, *, target)

Bases: SpinSamplingInteraction

Metropolis sweeps of Ising spins with quenched couplings to their neighbours.

The local energy is -s (sum J_k s_k + h).

The couplings J_up, J_left, J_right, and J_down are constant states of every spin, in the order of the offsets of the von Neumann neighbourhood, and the field h and the temperature are its parameters.

Parameters:

Name Type Description Default
label str

The label of the interaction, unique among the components of its system.

required
target Role

The path of the lattice group of spins.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import BondSamplingInteraction
>>> BondSamplingInteraction('sampling', target='spins').state
'spin'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spin_glasses.py
193
194
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label, target=target, state='spin', energy=self._get_energy)

BondSpinElement(label, *, spin=1.0, J_up=1.0, J_left=1.0, J_right=1.0, J_down=1.0, h=0.0, temperature=1.0, space=None)

Bases: Element

Ising spin on a square lattice with quenched couplings to its four neighbours.

Its local energy is -s sum J_k s_k.

The couplings are constant states of every site, so a bond between two sites is stored at both of them with the same value. A BondSamplingInteraction flips the spins by Metropolis Monte Carlo at the temperature T, with the energy -sum_<ij> J_ij s_i s_j - h sum_i s_i.

Parameters:

Name Type Description Default
label str

The label of the spin or the lattice group.

required
spin object

The initial spin, 1 or -1.

1.0
J_up object

The coupling to the upper neighbour.

1.0
J_left object

The coupling to the left neighbour.

1.0
J_right object

The coupling to the right neighbour.

1.0
J_down object

The coupling to the lower neighbour.

1.0
h float

The external field.

0.0
temperature Annotated[float, open(0, oo)]

The temperature.

1.0
space BaseSpace | None

The lattice of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import BondSpinElement
>>> BondSpinElement('spin', J_left=-1.0).J_left
-1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spin_glasses.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def __init__(
    self,
    label: str,
    *,
    spin: object = 1.0,
    J_up: object = 1.0,
    J_left: object = 1.0,
    J_right: object = 1.0,
    J_down: object = 1.0,
    h: float = 0.0,
    temperature: Annotated[float, RealSet.open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.spin = spin
    self.J_up = J_up
    self.J_left = J_left
    self.J_right = J_right
    self.J_down = J_down
    self.h = h
    self.temperature = temperature

BranchingAnnihilationInteraction(label, *, target, kappa=2.0, nu=1.0, lam=1.0, volume=100.0, epsilon=0.0)

Bases: Interaction

Reactions A -> 2A, A -> 0, and 2A -> A of the particles in a volume V.

A particle branches at rate kappa, decays at rate nu, and every pair annihilates at rate lambda / V, so W(n + 1 | n) = kappa n + epsilon delta_n0 and W(n - 1 | n) = nu n + lambda n (n - 1) / V. The empty state absorbs when epsilon = 0.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the particles, whose value n counts them.

required
kappa Annotated[float, closed_open(0, oo)]

The branching rate.

2.0
nu Annotated[float, closed_open(0, oo)]

The decay rate.

1.0
lam Annotated[float, closed_open(0, oo)]

The annihilation rate.

1.0
volume Annotated[float, open(0, oo)]

The volume V.

100.0
epsilon Annotated[float, closed_open(0, oo)]

The rate at which a particle appears in the empty state.

0.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import BranchingAnnihilationInteraction
>>> BranchingAnnihilationInteraction('reactions', target='particles').kappa
2.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_absorbing_processes.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    label: str,
    *,
    target: Role,
    kappa: Annotated[float, RealSet.closed_open(0, oo)] = 2.0,
    nu: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    lam: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    volume: Annotated[float, RealSet.open(0, oo)] = 100.0,
    epsilon: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.kappa = kappa
    self.nu = nu
    self.lam = lam
    self.volume = volume
    self.epsilon = epsilon

ContactInfectionInteraction(label, *, target)

Bases: Interaction

Infection and recovery of the contact process.

A site infects a neighbour at the rate rate / 4 and recovers at rate 1. One step is a time slice tau, in which an infected site recovers with probability 1 - exp(-tau) and a healthy site is infected with probability 1 - exp(-rate tau f), where f is the fraction of its infected neighbours. It is an epidemic on a grid of villages, the spread of a plant across a field, or a rumour among neighbours.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose values are infected, rate, and tau.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ContactInfectionInteraction
>>> ContactInfectionInteraction('infection', target='lattice').target
'lattice'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
101
102
103
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

ContactProcessSystem(shape=(64, 64), *, rate=3.0, tau=0.1, infected=0.5, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The contact process on a periodic lattice.

The process survives above a critical infection rate near 1.65.

Below the critical rate the infection dies out and the lattice falls into the absorbing healthy state. The system has the infections lattice.infected.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of rows and columns.

(64, 64)
rate float

The infection rate.

3.0
tau float

The time slice of one step.

0.1
infected float

The initial fraction of infected sites.

0.5
random_state int | Generator | None

The seed or generator of the initial infections.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ContactProcessSystem
>>> ContactProcessSystem((10, 10), rate=1.0).prepare().system_.elements[0].rate
1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    rate: float = 3.0,
    tau: float = 0.1,
    infected: float = 0.5,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.shape = shape
    self.rate = rate
    self.tau = tau
    self.infected = infected
    self.random_state = random_state

ContactSiteElement(label, *, infected=0.0, rate=3.0, tau=0.1, space=None)

Bases: Element

Sites of the contact process.

Every site is infected at 1 or healthy at 0, and holds the infection rate rate and the time slice tau of one step, which ContactInfectionInteraction reads.

Parameters:

Name Type Description Default
label str

The label of the site or the lattice of sites.

required
infected object

The initial state, 1 for infected and 0 for healthy, or one state per site.

0.0
rate Annotated[float, closed_open(0, oo)]

The infection rate.

3.0
tau Annotated[float, open(0, oo)]

The time slice of one step.

0.1
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ContactSiteElement
>>> ContactSiteElement('site').rate
3.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
63
64
65
66
67
68
69
70
71
72
73
74
75
def __init__(
    self,
    label: str,
    *,
    infected: object = 0.0,
    rate: Annotated[float, RealSet.closed_open(0, oo)] = 3.0,
    tau: Annotated[float, RealSet.open(0, oo)] = 0.1,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.infected = infected
    self.rate = rate
    self.tau = tau

ContinuumPercolationSystem(filling=1.1, *, side=60.0, radius=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Overlapping disks at uniform positions in a square.

Their clusters percolate near a filling of 1.13.

The number of disks is filling side^2 / (pi radius^2). The clusters of touching disks are read by clusters(source, radius=radius), and a sweep varies filling and random_state for the spanning probability (Satz 2022 ch. 3). The system has the positions disks.x.

Parameters:

Name Type Description Default
filling float

The filling factor, the total area of the disks over the area of the square.

1.1
side float

The side of the square.

60.0
radius float

The radius of a disk.

1.0
random_state int | Generator | None

The seed or generator of the positions.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ContinuumPercolationSystem
>>> ContinuumPercolationSystem(1.0, side=10.0).prepare().system_.elements[0].size
32
Source code in src/skcomplex/systems/physics/statistical_mechanics/_percolation.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def __init__(
    self,
    filling: float = 1.1,
    *,
    side: float = 60.0,
    radius: float = 1.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.filling = filling
    self.side = side
    self.radius = radius
    self.random_state = random_state

CurieWeissSystem(n_spins=500, *, temperature=0.5, J=1.0, h=0.0, initial='random', random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The fully connected Ising system with Glauber dynamics.

The system orders below the critical temperature T_c = J.

The energy is -(J / N) sum_{i<j} s_i s_j - h sum_i s_i. In the large system limit the magnetization m solves m = tanh((J m + h) / T), which has a nonzero root below T_c when h = 0. One unit of time is one attempted flip per spin. The spins are drawn in a row, which orders the drawing only. The system has the spins spins.spin and the observable magnetization.

Parameters:

Name Type Description Default
n_spins int

The number of spins.

500
temperature float

The temperature, which can change during a run.

0.5
J float

The coupling.

1.0
h float

The external field.

0.0
initial str

'random' for random spins or 'up' for all spins up.

'random'
random_state int | Generator | None

The seed or generator of the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import CurieWeissSystem
>>> trajectory = CurieWeissSystem(10).prepare().simulate(until=0.2, random_state=0)
>>> trajectory.get_values('spins.spin').shape
(3, 10)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_fully_connected_spins.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def __init__(
    self,
    n_spins: int = 500,
    *,
    temperature: float = 0.5,
    J: float = 1.0,
    h: float = 0.0,
    initial: str = 'random',
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_spins = n_spins
    self.temperature = temperature
    self.J = J
    self.h = h
    self.initial = initial
    self.random_state = random_state

DephasingInteraction(label, *, target, gamma=0.1)

Bases: Interaction

Dephasing of every spin of a chain.

The dissipator has the collapse operator S^z_i at the rate gamma.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the spin chain.

required
gamma Annotated[float, closed_open(0, oo)]

The dephasing rate.

0.1

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import DephasingInteraction
>>> DephasingInteraction('dephasing', target='chain', gamma=0.1).gamma
0.1
Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
124
125
126
127
128
129
130
131
132
133
def __init__(
    self,
    label: str,
    *,
    target: Role,
    gamma: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
) -> None:
    super().__init__(label)
    self.target = target
    self.gamma = gamma

DiffusionLimitedAggregationSystem(n_walkers=400, *, size=41, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Diffusion-limited aggregation on a periodic grid.

Random walkers stick to a seed at the center.

Walkers that touch the aggregate join it, so the tips of the aggregate catch most walkers and it grows into a branched fractal of dimension about 1.7. The system has the agent group walkers.

Parameters:

Name Type Description Default
n_walkers int

The number of walkers, the seed included.

400
size int

The side of the grid.

41
random_state int | Generator | None

The seed or generator of the initial cells of the walkers.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import DiffusionLimitedAggregationSystem
>>> DiffusionLimitedAggregationSystem(10, size=11).prepare().system_.elements[0].size
10
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
949
950
951
952
953
954
955
956
957
958
959
960
961
962
def __init__(
    self,
    n_walkers: int = 400,
    *,
    size: int = 41,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_walkers = n_walkers
    self.size = size
    self.random_state = random_state

DiscreteMasterEquationSystem(n_states=50, *, beta=1.0, depth=2.0, w=0.5, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The discrete-time master equation of states on a ring.

The equation relaxes to the Boltzmann distribution.

The potential is U = depth cos(2 pi i / n_states), the probability starts on the state of highest potential, and moves to neighbouring states with Glauber probabilities, which satisfy detailed balance. The system has the probabilities states.P and potentials states.U.

Parameters:

Name Type Description Default
n_states int

The number of states.

50
beta float

The inverse temperature.

1.0
depth float

The amplitude of the potential.

2.0
w float

The attempt probability of a move to each neighbour, at most 1/2.

0.5
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import DiscreteMasterEquationSystem
>>> DiscreteMasterEquationSystem(10).prepare().system_.elements[0].space.prepare().size_
10
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
def __init__(
    self,
    n_states: int = 50,
    *,
    beta: float = 1.0,
    depth: float = 2.0,
    w: float = 0.5,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_states = n_states
    self.beta = beta
    self.depth = depth
    self.w = w

DiskElement(label, x=0.0, radius=1.0, *, size=None, space=None)

Bases: Element

Disk of the plane at a position that no law moves.

Parameters:

Name Type Description Default
label str

The label of the disk or the group.

required
x ArrayLike

The position of its centre.

0.0
radius Annotated[float, open(0, oo)]

The radius of the disk, which it is drawn with.

1.0
size int | None

The number of disks, or None for one.

None
space BaseSpace | None

The plane of the disks, or None for none.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import DiskElement
>>> DiskElement('disk', x=(1.0, 2.0)).x
(1.0, 2.0)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_percolation.py
49
50
51
52
53
54
55
56
57
58
59
60
def __init__(
    self,
    label: str,
    x: npt.ArrayLike = 0.0,
    radius: Annotated[float, RealSet.open(0, oo)] = 1.0,
    *,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, size=size, space=space)
    self.x = x
    self.radius = radius

DissipativeZeroRangeSystem(n_levels=5, *, branches=2, nu=1.0, alpha=0.5, beta_ext=1.0, epsilon0=1.0, dissipation=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The dissipative zero-range process on a tree.

Energy is injected at the root and lost at the leaves.

Level j of the tree has m^(j - 1) nodes, each with m branches to the next level. A quantum epsilon0 of energy crosses a branch between levels j and j + 1 at rate nu_j = nu k_j^alpha, k_j = m^(j - 1), in either direction from an occupied node. A reservoir at the inverse temperature beta_ext exchanges quanta with the root, adding one at rate nu exp(-beta_ext epsilon0) and removing one at rate nu, and every leaf loses a quantum at the rate dissipation. The stationary distribution is a product of geometric laws z_j^n, with z_j the solution of the linear balance of the currents nu_j (z_j - z_(j + 1)) at every level, and the injected flux is nu (exp(-beta_ext epsilon0) - z_1). The system has the quanta nodes.n of the nodes in breadth-first order, from the root to the leaves.

Parameters:

Name Type Description Default
n_levels int

The number of levels M.

5
branches int

The number m of branches of every node above the leaves.

2
nu float

The rate scale of transfers and of the exchange with the reservoir.

1.0
alpha float

The exponent of the growth of the transfer rate with the pseudo wave number k_j.

0.5
beta_ext float

The inverse temperature of the reservoir.

1.0
epsilon0 float

The quantum of energy.

1.0
dissipation float

The rate at which every leaf loses a quantum.

1.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import DissipativeZeroRangeSystem
>>> system = DissipativeZeroRangeSystem(3, branches=3).prepare().system_
>>> system.elements[0].size, len(system.interactions)
(13, 14)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
def __init__(
    self,
    n_levels: int = 5,
    *,
    branches: int = 2,
    nu: float = 1.0,
    alpha: float = 0.5,
    beta_ext: float = 1.0,
    epsilon0: float = 1.0,
    dissipation: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_levels = n_levels
    self.branches = branches
    self.nu = nu
    self.alpha = alpha
    self.beta_ext = beta_ext
    self.epsilon0 = epsilon0
    self.dissipation = dissipation

EdwardsAndersonSystem(size=48, *, temperature=0.8, J=1.0, h=0.0, disorder='bimodal', random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Edwards-Anderson spin glass on a periodic square lattice.

The bonds are quenched and random.

Every bond takes the coupling +J or -J with equal probability, or a Gaussian coupling of mean 0 and standard deviation J, drawn once. The magnetization stays near zero at every temperature, while at low temperature the spins freeze in random directions and the energy per spin approaches the ground-state energy, about -1.40 J for +J and -J bonds. One unit of time is one sweep of Metropolis updates. The system has the spins spins.spin, the couplings spins.J_right and spins.J_down of the bonds to the right and down, and the observable magnetization.

Parameters:

Name Type Description Default
size int | Sequence[int]

The side of the square lattice, or its two sides.

48
temperature float

The temperature, which can change during a run.

0.8
J float

The scale of the couplings.

1.0
h float

The external field.

0.0
disorder str

'bimodal' for couplings +J and -J, or 'gaussian' for Gaussian couplings.

'bimodal'
random_state int | Generator | None

The seed or generator of the couplings and of the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Raises:

Type Description
ValidationError

The disorder is neither 'bimodal' nor 'gaussian'.

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import EdwardsAndersonSystem
>>> sorted(set(EdwardsAndersonSystem(8).prepare().system_.elements[0].J_right.tolist()))
[-1.0, 1.0]
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spin_glasses.py
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def __init__(
    self,
    size: int | Sequence[int] = 48,
    *,
    temperature: float = 0.8,
    J: float = 1.0,
    h: float = 0.0,
    disorder: str = 'bimodal',
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.temperature = temperature
    self.J = J
    self.h = h
    self.disorder = disorder
    self.random_state = random_state

EhrenfestMoveInteraction(label, *, target, N=40)

Bases: Interaction

Move of one ball drawn at random between the two boxes of the Ehrenfest urn.

The count n of the first box falls by one with probability n / N and rises by one otherwise.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the urn, whose value n counts the balls of the first box.

required
N Annotated[float, open(0, oo)]

The number of balls.

40

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import EhrenfestMoveInteraction
>>> EhrenfestMoveInteraction('move', target='urn', N=10).N
10
Source code in src/skcomplex/systems/physics/statistical_mechanics/_urns.py
50
51
52
53
def __init__(self, label: str, *, target: Role, N: Annotated[float, RealSet.open(0, oo)] = 40) -> None:
    super().__init__(label)
    self.target = target
    self.N = N

EhrenfestUrnSystem(n_balls=40, *, in_first=None, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Ehrenfest urn system.

Balls move one at a time between two boxes, and the system relaxes to equal counts.

At every step one of the N numbered balls is drawn at random and moved to the other box, so the count n of the first box falls by one with probability n / N and rises by one otherwise. Started with all balls in the first box, the count relaxes to N / 2 with the exponential mean N / 2 + (n_0 - N / 2) (1 - 2 / N)^t, and then fluctuates around it: the chain is reversible, yet the relaxation looks irreversible. Its stationary distribution is the binomial distribution of N balls with probability one half. The system has the count urn.n of balls in the first box.

Parameters:

Name Type Description Default
n_balls int

The number of balls N.

40
in_first int | None

The initial number of balls in the first box, or None for all of them.

None
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import EhrenfestUrnSystem
>>> trajectory = EhrenfestUrnSystem(10).prepare().simulate(until=1, random_state=0)
>>> int(trajectory.get_values('urn.n')[0])
10
Source code in src/skcomplex/systems/physics/statistical_mechanics/_urns.py
108
109
110
111
112
113
114
115
116
117
118
119
def __init__(
    self,
    n_balls: int = 40,
    *,
    in_first: int | None = None,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_balls = n_balls
    self.in_first = in_first

EnergyLevelElement(label, energy=0.0, *, size=None)

Bases: Element

Energy level of a configuration, held fixed.

Parameters:

Name Type Description Default
label str

The label of the level or the group.

required
energy object

The energy of the level.

0.0
size int | None

The number of levels, or None for one.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import EnergyLevelElement
>>> EnergyLevelElement('level', energy=-1.5).energy
-1.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_random_energy.py
81
82
83
def __init__(self, label: str, energy: object = 0.0, *, size: int | None = None) -> None:
    super().__init__(label, size=size)
    self.energy = energy

ExclusionHopsInteraction(label, *, sites, p=1.0, q=0.0)

Bases: Interaction

Hops of a particle from every site of a line to an empty neighbour.

The particle hops to the right at rate p and to the left at q.

No particle hops past the ends of the line, where the site on the right reads as full. Every site moves one particle to the site on its right, JumpLaw(p n (1 - n'), {n: -1, n': 1}) with n' the site on the right, and back.

Parameters:

Name Type Description Default
label str

The label of the hops.

required
sites Role

The group of sites, in line order.

required
p Annotated[float, closed_open(0, oo)]

The rate of hops to the right.

1.0
q Annotated[float, closed_open(0, oo)]

The rate of hops to the left.

0.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ExclusionHopsInteraction
>>> ExclusionHopsInteraction('hops', sites='lane').p
1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
120
121
122
123
124
125
126
127
128
129
130
131
def __init__(
    self,
    label: str,
    *,
    sites: Role,
    p: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    q: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
) -> None:
    super().__init__(label)
    self.sites = sites
    self.p = p
    self.q = q

ExclusionSiteElement(label, *, occupied=0.0, space=None)

Bases: Element

Sites of the totally asymmetric simple exclusion process.

Every site is empty at 0 or holds one particle at 1.

Parameters:

Name Type Description Default
label str

The label of the site or the lane of sites.

required
occupied Annotated[object, FiniteEnumeratedSet([0, 1])]

The initial occupation, or one occupation per site.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ExclusionSiteElement
>>> ExclusionSiteElement('site').occupied
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
152
153
154
155
156
157
158
159
160
def __init__(
    self,
    label: str,
    *,
    occupied: Annotated[object, FiniteEnumeratedSet([0, 1])] = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.occupied = occupied

FireSpreadInteraction(label, *, target)

Bases: Interaction

Fire on a percolation lattice.

Fire spreads from burning sites to their occupied neighbours and burns out in one step, so a fire lit along one edge burns exactly the clusters that touch that edge.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose value cover is 0, 1, 2, or 3.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import FireSpreadInteraction
>>> FireSpreadInteraction('fire', target='lattice').target
'lattice'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
344
345
346
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

FullyConnectedSpinElement(label, *, spin=1.0, space=None)

Bases: Element

Ising spins of 1 or -1, each coupled to every other spin.

Parameters:

Name Type Description Default
label str

The label of the spin or the group.

required
spin object

The initial spin, 1 or -1, or one spin per site.

1.0
space BaseSpace | None

The row of sites of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import FullyConnectedSpinElement
>>> FullyConnectedSpinElement('spin').spin
1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_fully_connected_spins.py
52
53
54
def __init__(self, label: str, *, spin: object = 1.0, space: BaseSpace | None = None) -> None:
    super().__init__(label, space=space)
    self.spin = spin

GasMoleculeElement(label, x=0.0, *, m=1.0, values=None, size=None, space=None)

Bases: MassPointElement

Molecule of an ideal gas, drawn as a point coloured by its velocity.

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import GasMoleculeElement
>>> GasMoleculeElement('molecule', m=2.0).m
2.0
Source code in src/skcomplex/systems/physics/common/particles/_mass_point.py
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    label: str,
    x: npt.ArrayLike = 0.0,
    *,
    m: Annotated[float, RealSet.open(0, oo)] = 1.0,
    values: Mapping[str, object] | None = None,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, x=x, values=values, size=size, space=space)
    self.m = m

GlauberFlipInteraction(label, *, target, J=1.0, h=0.0, temperature=0.5, couplings=None)

Bases: Interaction

Glauber flips of fully connected Ising spins.

A spin flips at the rate 1 / (1 + exp(2 s h / T)). The local field is h = J (sum_{j != i} s_j) / N + h_ext of the Curie-Weiss energy -(J / N) sum_{i<j} s_i s_j, or h = J sum_j C_ij s_j + h_ext with a symmetric coupling matrix C of zero diagonal. The rate satisfies detailed balance with the Boltzmann distribution at the temperature T.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the spins.

required
J float

The scale of the couplings.

1.0
h float

The external field.

0.0
temperature Annotated[float, open(0, oo)]

The temperature.

0.5
couplings ArrayLike | None

The coupling matrix C, one row and one column per spin, or None for the uniform couplings 1 / N.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import GlauberFlipInteraction
>>> GlauberFlipInteraction('flips', target='spins').temperature
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_fully_connected_spins.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def __init__(
    self,
    label: str,
    *,
    target: Role,
    J: float = 1.0,
    h: float = 0.0,
    temperature: Annotated[float, RealSet.open(0, oo)] = 0.5,
    couplings: npt.ArrayLike | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.J = J
    self.h = h
    self.temperature = temperature
    self.couplings = couplings

GlauberMasterInteraction(label, *, target, beta=1.0, w=0.5)

Bases: Interaction

Discrete master equation of states on a ring with Glauber moves between neighbours.

Every step the probability moves to each neighbouring state B from a state A with the Glauber probability w / (1 + exp(beta (U_B - U_A))), so P_A(t + 1) = P_A + sum_B T_AB P_B - sum_B T_BA P_A, and the stationary distribution is exp(-beta U) / Z. It is a molecule hopping between conformations, a walker in a landscape, or a queue whose length changes by one.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the ring of states.

required
beta Annotated[float, closed_open(0, oo)]

The inverse temperature.

1.0
w Annotated[float, closed_open(0, oo)]

The attempt probability of a move to each neighbour, at most 1/2.

0.5

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import GlauberMasterInteraction
>>> GlauberMasterInteraction('moves', target='states').w
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(
    self,
    label: str,
    *,
    target: Role,
    beta: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    w: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
) -> None:
    super().__init__(label)
    self.target = target
    self.beta = beta
    self.w = w

GraphIsingSystem(graph=None, *, temperature=2.0, J=1.0, h=0.0, initial='random', sampler='metropolis', random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Ising system on a graph.

The system orders below a critical temperature set by the degrees of the nodes.

On a random 4-regular graph the Bethe approximation gives the critical temperature 2 / ln 2. One unit of time is one sweep of colored updates. The system has the spins spins.spin in node order.

Parameters:

Name Type Description Default
graph Graph | None

The graph whose nodes hold the spins, or None for a random 4-regular graph of 400 nodes.

None
temperature float

The temperature in units of the coupling, which can change during a run.

2.0
J float

The coupling between neighbouring spins.

1.0
h float

The external field.

0.0
initial str

'random' for random spins or 'up' for all spins up.

'random'
sampler str

The acceptance rule, 'metropolis', 'glauber', or 'heat-bath'.

'metropolis'
random_state int | Generator | None

The seed or generator of the default graph and the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> import networkx as nx
>>> from skcomplex.systems.physics.statistical_mechanics import GraphIsingSystem
>>> GraphIsingSystem(nx.cycle_graph(10)).prepare().system_.elements[0].space.prepare().size_
10
Source code in src/skcomplex/systems/physics/statistical_mechanics/_graph_spins.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    graph: nx.Graph | None = None,
    *,
    temperature: float = 2.0,
    J: float = 1.0,
    h: float = 0.0,
    initial: str = 'random',
    sampler: str = 'metropolis',
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.graph = graph
    self.temperature = temperature
    self.J = J
    self.h = h
    self.initial = initial
    self.sampler = sampler
    self.random_state = random_state

IdealGasSystem(n_molecules=500, *, kT=1.0, size=1.0, n_dim=2, mass=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

An ideal gas of non-interacting molecules in a reflecting box.

Positions are uniform in the box and velocity components are normal with variance kT / mass, with the mean velocity removed. The molecules need no law: given their starting velocities x', they keep them between the walls, as Newton's first law says. The molecules are drawn as points colored by speed. NOTE-RETURNS: The gas.

Parameters:

Name Type Description Default
n_molecules int

The number of molecules.

500
kT float

The temperature in energy units.

1.0
size float

The side of the box.

1.0
n_dim int

The number of dimensions.

2
mass float

The mass of every molecule.

1.0
random_state int | Generator | None

The seed or generator of the initial positions and velocities.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import IdealGasSystem
>>> gas = IdealGasSystem(1000, random_state=0).prepare().system_.elements[0]
>>> gas.label, type(gas).__name__, gas.size
('gas', 'GasMoleculeElement', 1000)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_gases.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    n_molecules: int = 500,
    *,
    kT: float = 1.0,
    size: float = 1.0,
    n_dim: int = 2,
    mass: float = 1.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_molecules = n_molecules
    self.kT = kT
    self.size = size
    self.n_dim = n_dim
    self.mass = mass
    self.random_state = random_state

IsingSpinElement(label, *, spin=1.0, J=1.0, h=0.0, temperature=2.0, space=None)

Bases: Element

Ising spins, up at 1 or down at -1.

Every spin has its coupling J, its field h, and its temperature.

An IsingSamplingInteraction flips the spins by Monte Carlo sweeps at the temperature of the spins.

Parameters:

Name Type Description Default
label str

The label of the spin or the lattice of spins.

required
spin object

The initial spin, 1 or -1, or one spin per site.

1.0
J float

The coupling between neighbouring spins.

1.0
h float

The external field.

0.0
temperature Annotated[float, open(0, oo)]

The temperature in units of the coupling.

2.0
space BaseSpace | None

The lattice or network of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.common.spins import IsingSpinElement
>>> IsingSpinElement('spin').temperature
2.0
Source code in src/skcomplex/systems/physics/common/spins/_ising_spin.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def __init__(
    self,
    label: str,
    *,
    spin: object = 1.0,
    J: float = 1.0,
    h: float = 0.0,
    temperature: Annotated[float, RealSet.open(0, oo)] = 2.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.spin = spin
    self.J = J
    self.h = h
    self.temperature = temperature

IsingSystem(size=64, *, temperature=2.0, J=1.0, h=0.0, initial='random', sampler='metropolis', random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The two-dimensional Ising system on a torus.

The system orders below the critical temperature 2 / ln(1 + sqrt 2).

One unit of time is one sweep of checkerboard updates. The system has the spins spins.spin.

Parameters:

Name Type Description Default
size int | Sequence[int]

The side of the square lattice, or its shape.

64
temperature float

The temperature in units of the coupling, which can change during a run.

2.0
J float

The coupling between neighbouring spins.

1.0
h float

The external field.

0.0
initial str

'random' for random spins or 'up' for all spins up.

'random'
sampler str

The acceptance rule, 'metropolis', 'glauber', or 'heat-bath'.

'metropolis'
random_state int | Generator | None

The seed or generator of the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import IsingSystem
>>> IsingSystem(8, temperature=1.5).prepare().system_.elements[0].temperature
1.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spins.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
def __init__(
    self,
    size: int | Sequence[int] = 64,
    *,
    temperature: float = 2.0,
    J: float = 1.0,
    h: float = 0.0,
    initial: str = 'random',
    sampler: str = 'metropolis',
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.temperature = temperature
    self.J = J
    self.h = h
    self.initial = initial
    self.sampler = sampler
    self.random_state = random_state

KineticTemperatureResult(values, temperature) dataclass

Kinetic temperature of the agents of every frame.

Parameters:

Name Type Description Default
values Array

The velocities, frames by agents by dimensions.

required
temperature Array

The kinetic temperature of every frame.

required

LandauRelaxationInteraction(label, *, target, T=0.5, Tc=1.0, a=1.0, b=1.0, h=0.0, Gamma=1.0)

Bases: Interaction

Relaxation of an order parameter down the gradient of the Landau free energy.

The order parameter follows phi' = -Gamma (a (T - Tc) phi + b phi^3 - h).

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the magnet, whose value phi is the order parameter.

required
T Annotated[float, closed_open(0, oo)]

The temperature.

0.5
Tc Annotated[float, open(0, oo)]

The critical temperature.

1.0
a Annotated[float, open(0, oo)]

The coefficient of the quadratic term per unit temperature.

1.0
b Annotated[float, open(0, oo)]

The coefficient of the quartic term.

1.0
h float

The external field.

0.0
Gamma Annotated[float, open(0, oo)]

The kinetic coefficient.

1.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import LandauRelaxationInteraction
>>> LandauRelaxationInteraction('relaxation', target='magnet', T=2.0).T
2.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def __init__(
    self,
    label: str,
    *,
    target: Role,
    T: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    Tc: Annotated[float, RealSet.open(0, oo)] = 1.0,
    a: Annotated[float, RealSet.open(0, oo)] = 1.0,
    b: Annotated[float, RealSet.open(0, oo)] = 1.0,
    h: float = 0.0,
    Gamma: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.T = T
    self.Tc = Tc
    self.a = a
    self.b = b
    self.h = h
    self.Gamma = Gamma

LandauRelaxationSystem(phi=0.1, *, T=0.5, Tc=1.0, a=1.0, b=1.0, h=0.0, Gamma=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The relaxation of a Landau order parameter.

The order parameter relaxes to sqrt(a (Tc - T) / b) below Tc and to 0 above it.

The relaxation time 1 / (Gamma a |T - Tc|) diverges at the critical temperature, which is critical slowing down. The system has the order parameter magnet.phi.

Parameters:

Name Type Description Default
phi float

The initial order parameter.

0.1
T float

The temperature.

0.5
Tc float

The critical temperature.

1.0
a float

The coefficient of the quadratic term per unit temperature.

1.0
b float

The coefficient of the quartic term.

1.0
h float

The external field.

0.0
Gamma float

The kinetic coefficient.

1.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import LandauRelaxationSystem
>>> LandauRelaxationSystem(T=2.0).prepare().system_.interactions[0].T
2.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def __init__(
    self,
    phi: float = 0.1,
    *,
    T: float = 0.5,
    Tc: float = 1.0,
    a: float = 1.0,
    b: float = 1.0,
    h: float = 0.0,
    Gamma: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.phi = phi
    self.T = T
    self.Tc = Tc
    self.a = a
    self.b = b
    self.h = h
    self.Gamma = Gamma

LaneEntryInteraction(label, *, target, alpha=0.3)

Bases: Interaction

Entry of particles at the first site of an open lane.

In one step a particle enters the empty first site with probability alpha, as cars join a road from a ramp.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the first site, whose value is occupied.

required
alpha Annotated[float, closed(0, 1)]

The probability of an entry.

0.3

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import LaneEntryInteraction
>>> LaneEntryInteraction('entry', target='lane[0]', alpha=0.4).alpha
0.4
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
240
241
242
243
def __init__(self, label: str, *, target: Role, alpha: Annotated[float, RealSet.closed(0, 1)] = 0.3) -> None:
    super().__init__(label)
    self.target = target
    self.alpha = alpha

LaneExitInteraction(label, *, target, beta=0.7)

Bases: Interaction

Exit of particles at the last site of an open lane.

In one step the particle on the last site leaves with probability beta, as cars leave a road by an exit.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the last site, whose value is occupied.

required
beta Annotated[float, closed(0, 1)]

The probability of an exit.

0.7

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import LaneExitInteraction
>>> LaneExitInteraction('exit', target='lane[9]', beta=0.6).beta
0.6
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
279
280
281
282
def __init__(self, label: str, *, target: Role, beta: Annotated[float, RealSet.closed(0, 1)] = 0.7) -> None:
    super().__init__(label)
    self.target = target
    self.beta = beta

LennardJonesFluidSystem(n_particles=400, *, density=0.5, temperature=None, cutoff=2.5, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Lennard-Jones particles in a periodic square box.

A thermostat optionally holds the particles at a temperature.

The system has the particle group fluid in two dimensions.

Parameters:

Name Type Description Default
n_particles int

The number of particles.

400
density float

The number of particles per unit area.

0.5
temperature float | None

The temperature of the Langevin thermostat, or None for constant energy. A thermostat makes the system stochastic, so it runs with the Euler-Maruyama solver instead of the default velocity Verlet.

None
cutoff float

The distance beyond which pairs do not interact.

2.5
random_state int | Generator | None

The seed or generator of the initial jitter and velocities.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import LennardJonesFluidSystem
>>> LennardJonesFluidSystem(100).prepare().system_.elements[0].size
100
Source code in src/skcomplex/systems/physics/statistical_mechanics/_gases.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __init__(
    self,
    n_particles: int = 400,
    *,
    density: float = 0.5,
    temperature: float | None = None,
    cutoff: float = 2.5,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_particles = n_particles
    self.density = density
    self.temperature = temperature
    self.cutoff = cutoff
    self.random_state = random_state

MattisSpinElement(label, *, spin=1.0, J_up=1.0, J_left=1.0, J_right=1.0, J_down=1.0, h=0.0, temperature=1.0, pattern=1.0, space=None)

Bases: BondSpinElement

Spin of the Mattis system.

The bond spin also holds its quenched pattern xi, with couplings J xi_i xi_j.

Parameters:

Name Type Description Default
label str

The label of the spin or the lattice group.

required
spin object

The initial spin, 1 or -1.

1.0
J_up object

The coupling to the upper neighbour.

1.0
J_left object

The coupling to the left neighbour.

1.0
J_right object

The coupling to the right neighbour.

1.0
J_down object

The coupling to the lower neighbour.

1.0
h float

The external field.

0.0
temperature float

The temperature.

1.0
pattern object

The quenched pattern xi, 1 or -1.

1.0
space BaseSpace | None

The lattice of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import MattisSpinElement
>>> MattisSpinElement('spin', pattern=-1.0).pattern
-1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spin_glasses.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def __init__(
    self,
    label: str,
    *,
    spin: object = 1.0,
    J_up: object = 1.0,
    J_left: object = 1.0,
    J_right: object = 1.0,
    J_down: object = 1.0,
    h: float = 0.0,
    temperature: float = 1.0,
    pattern: object = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(
        label,
        spin=spin,
        J_up=J_up,
        J_left=J_left,
        J_right=J_right,
        J_down=J_down,
        h=h,
        temperature=temperature,
        space=space,
    )
    self.pattern = pattern

MattisSpinGlassSystem(size=48, *, temperature=1.5, J=1.0, h=0.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Mattis spin glass on a periodic square lattice.

The couplings are J_ij = J xi_i xi_j of a pattern xi.

The gauge change sigma_i = xi_i s_i maps the system at h = 0 to the Ising system, so the overlap m_xi = sum_i xi_i s_i / N orders below the Ising critical temperature 2 J / ln(1 + sqrt 2) while the magnetization averages to zero over the disorder. One unit of time is one sweep of Metropolis updates. The system has the spins spins.spin, the pattern spins.pattern, and the observables magnetization and overlap.

Parameters:

Name Type Description Default
size int | Sequence[int]

The side of the square lattice, or its two sides.

48
temperature float

The temperature, which can change during a run.

1.5
J float

The coupling.

1.0
h float

The external field.

0.0
random_state int | Generator | None

The seed or generator of the pattern and of the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> import numpy as np
>>> from skcomplex.systems.physics.statistical_mechanics import MattisSpinGlassSystem
>>> spins = MattisSpinGlassSystem(8).prepare().system_.elements[0]
>>> pattern = spins.pattern.reshape(8, 8)
>>> bool(np.array_equal(spins.J_right.reshape(8, 8), pattern * np.roll(pattern, -1, axis=1)))
True
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spin_glasses.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def __init__(
    self,
    size: int | Sequence[int] = 48,
    *,
    temperature: float = 1.5,
    J: float = 1.0,
    h: float = 0.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.temperature = temperature
    self.J = J
    self.h = h
    self.random_state = random_state

MaxwellBoltzmannResult(values, temperature, statistic, p_value) dataclass

Kolmogorov-Smirnov test of the speeds of every frame.

The test compares the speeds with the Maxwell-Boltzmann law.

Parameters:

Name Type Description Default
values Array

The velocities, frames by agents by dimensions.

required
temperature Array

The temperature of the tested law at every frame.

required
statistic Array

The Kolmogorov-Smirnov statistic of every frame.

required
p_value Array

The p-value of every frame.

required

MicrostateElement(label, *, P=0.0, U=0.0, space=None)

Bases: Element

State of a discrete master equation on a ring, with the probability P and the potential U.

Parameters:

Name Type Description Default
label str

The label of the state or the ring of states.

required
P Annotated[object, closed_open(0, oo)]

The initial probability.

0.0
U object

The potential.

0.0
space BaseSpace | None

The ring whose sites hold one state each, or None for one state.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import MicrostateElement
>>> MicrostateElement('state', U=1.5).U
1.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self,
    label: str,
    *,
    P: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    U: object = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.P = P
    self.U = U

ParallelHopInteraction(label, *, target, p=0.5, boundary='periodic')

Bases: Interaction

Hops of particles to the next site of a lane, all at once.

In one step every particle whose next site is empty hops to it with probability p. One draw decides the hop between two sites, and both sites read it, so particles are never lost or doubled. On a fixed boundary the last site has no next site. It is the parallel update of cars on a road, ribosomes on a messenger RNA, or molecular motors on a filament.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose value is occupied.

required
p Annotated[float, closed(0, 1)]

The probability of a hop.

0.5
boundary str

'periodic' for a ring, or 'fixed' for an open line.

'periodic'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ParallelHopInteraction
>>> ParallelHopInteraction('hops', target='lane', p=0.75).p
0.75
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
190
191
192
193
194
195
196
197
198
199
200
201
def __init__(
    self,
    label: str,
    *,
    target: Role,
    p: Annotated[float, RealSet.closed(0, 1)] = 0.5,
    boundary: str = 'periodic',
) -> None:
    super().__init__(label)
    self.target = target
    self.p = p
    self.boundary = boundary

ParticleSiteElement(label, *, n=0.0)

Bases: Element

Site of a lattice of particles, holding the number n of particles or quanta.

Parameters:

Name Type Description Default
label str

The label of the site or the group.

required
n Annotated[float, NN]

The initial number of particles.

0.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ParticleSiteElement
>>> ParticleSiteElement('site', n=3.0).n
3.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
47
48
49
50
51
52
53
54
def __init__(
    self,
    label: str,
    *,
    n: Annotated[float, NN] = 0.0,
) -> None:
    super().__init__(label)
    self.n = n

PercolationSiteElement(label, *, cover=0.0, space=None)

Bases: Element

Sites of a percolation lattice.

Every site is empty at 0, occupied at 1, burning at 2, or burnt at 3.

Parameters:

Name Type Description Default
label str

The label of the site or the lattice of sites.

required
cover object

The initial cover, 0, 1, 2, or 3, or one cover per site.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import PercolationSiteElement
>>> PercolationSiteElement('site').cover
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
318
319
320
def __init__(self, label: str, *, cover: object = 0.0, space: BaseSpace | None = None) -> None:
    super().__init__(label, space=space)
    self.cover = cover

PottsSpinElement(label, *, color=0.0, J=1.0, temperature=1.0, space=None)

Bases: Element

Spins of the q-state Potts system, each in a state from 0 to q - 1.

Every spin has its coupling J and its temperature.

A PottsSamplingInteraction redraws the states by Monte Carlo sweeps at the temperature of the spins.

Parameters:

Name Type Description Default
label str

The label of the spin or the lattice of spins.

required
color object

The initial state, or one state per site.

0.0
J float

The coupling between neighbouring spins.

1.0
temperature Annotated[float, open(0, oo)]

The temperature in units of the coupling.

1.0
space BaseSpace | None

The lattice of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import PottsSpinElement
>>> PottsSpinElement('spin').temperature
1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spins.py
58
59
60
61
62
63
64
65
66
67
68
69
70
def __init__(
    self,
    label: str,
    *,
    color: object = 0.0,
    J: float = 1.0,
    temperature: Annotated[float, RealSet.open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.color = color
    self.J = J
    self.temperature = temperature

PottsSystem(size=64, *, q=3, temperature=1.0, J=1.0, sampler='heat-bath', random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The q-state Potts system on a torus.

The system orders below the critical temperature 1 / ln(1 + sqrt q).

The system has the states spins.color.

Parameters:

Name Type Description Default
size int | Sequence[int]

The side of the square lattice, or its shape.

64
q int

The number of states.

3
temperature float

The temperature in units of the coupling.

1.0
J float

The coupling between neighbouring spins.

1.0
sampler str

The acceptance rule, 'metropolis', 'glauber', or 'heat-bath'.

'heat-bath'
random_state int | Generator | None

The seed or generator of the random initial states.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import PottsSystem
>>> PottsSystem(8, q=4).prepare().system_.interactions[0].q
4
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spins.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
def __init__(
    self,
    size: int | Sequence[int] = 64,
    *,
    q: int = 3,
    temperature: float = 1.0,
    J: float = 1.0,
    sampler: str = 'heat-bath',
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.q = q
    self.temperature = temperature
    self.J = J
    self.sampler = sampler
    self.random_state = random_state

Q2RFlipInteraction(label, *, target)

Bases: Interaction

Flips of the Q2R automaton.

The local rule of Q2R flips the spins of the updating sites whose neighbours sum to zero, which leaves the Ising energy unchanged, and swaps the phase of every site, so the two sublattices update in turn and the dynamics is reversible.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose values are the spins spin and the phases phase.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import Q2RFlipInteraction
>>> Q2RFlipInteraction('flip', target='spins').target
'spins'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
427
428
429
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

Q2RSpinElement(label, *, spin=1.0, phase=0.0, space=None)

Bases: Element

Sites of the Q2R automaton.

Every site holds a spin and a phase that says whether the site updates in the current step.

Parameters:

Name Type Description Default
label str

The label of the site or the lattice of sites.

required
spin object

The initial spin, 1 or -1, or one spin per site.

1.0
phase object

The initial phase, 1 for updating and 0 for quiescent, or one phase per site.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import Q2RSpinElement
>>> Q2RSpinElement('site').phase
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
392
393
394
395
396
397
398
399
400
401
402
def __init__(
    self,
    label: str,
    *,
    spin: object = 1.0,
    phase: object = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.spin = spin
    self.phase = phase

Q2rSystem(shape=(64, 64), *, up=0.3, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Q2R automaton.

It is a reversible, energy-conserving Ising dynamics on a periodic lattice of even sides.

The spins start uncorrelated with a fraction up of spins up, and the sites of even coordinate sum update first. The system has the spins spins.spin and phases spins.phase.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of sites along each axis, all even.

(64, 64)
up float

The probability that an initial spin is up.

0.3
random_state int | Generator | None

The seed or generator of the initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import Q2rSystem
>>> trajectory = Q2rSystem((8,)).prepare().simulate(until=1)
>>> trajectory.get_values('spins.spin').shape
(2, 8)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
615
616
617
618
619
620
621
622
623
624
625
626
627
628
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    up: float = 0.3,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.shape = shape
    self.up = up
    self.random_state = random_state

QuantumHeisenbergSystem(n_sites=12, *, J=1.0, delta=1.0, h=0.0, gamma=0.0, boundary='periodic', initial='flip', label='system', solver='auto', backend='auto')

Bases: BaseSystem

A chain of spins one half with the XXZ Hamiltonian.

The chain has a field and optional dephasing.

The Hamiltonian is J Σ (S^x_i S^x_j + S^y_i S^y_j + Δ S^z_i S^z_j) - h Σ S^z_i over neighbouring pairs, with ħ = 1. A dephasing rate gamma > 0 adds the dissipator S^z_i on every site, so the state is a density matrix that loses its coherence. One flipped spin in a ferromagnetic background spreads as a magnon, whose probability at distance d is J_d(J t)² in the XX chain, a light cone in the space-time image of S^z. The total magnetisation is conserved. The system has the observables sz of every site, magnetization, and the energy.

Parameters:

Name Type Description Default
n_sites int

The number of spins.

12
J float

The exchange coupling, antiferromagnetic when positive.

1.0
delta float

The anisotropy Δ.

1.0
h float

The field.

0.0
gamma float

The dephasing rate.

0.0
boundary str

'periodic' for a ring, or 'open' for a chain with two ends.

'periodic'
initial str

'flip' for one flipped spin at site n_sites // 2, 'neel' for alternating spins, 'domain_wall' for the left half up and the right half down, or 'ground' for the ground state, which the tuned run settings start from as initial_state={'<label>.state': 'ground'}.

'flip'
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Raises:

Type Description
ValidationError

The boundary or the initial state is unknown.

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import QuantumHeisenbergSystem
>>> len(QuantumHeisenbergSystem(6).prepare().system_.elements[0].psi)
6
Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def __init__(
    self,
    n_sites: int = 12,
    *,
    J: float = 1.0,
    delta: float = 1.0,
    h: float = 0.0,
    gamma: float = 0.0,
    boundary: str = 'periodic',
    initial: str = 'flip',
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_sites = n_sites
    self.J = J
    self.delta = delta
    self.h = h
    self.gamma = gamma
    self.boundary = boundary
    self.initial = initial

RandomEnergySystem(n_spins=10, *, temperature=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The random energy system.

It has 2^N quenched Gaussian energies of variance N / 2 at a temperature.

The entropy per spin follows ln 2 - 1 / (4 T^2) above the glass temperature T_g = 1 / (2 sqrt(ln 2)) and freezes below it, where the Boltzmann weight falls on the few lowest levels (Bertin 2021 §1.5.3). The energies are drawn from random_state, so a disorder average sweeps it with sweep. The system has the states ensemble.log_partition, ensemble.energy, and ensemble.entropy.

Parameters:

Name Type Description Default
n_spins int

The number of spins N.

10
temperature float

The temperature.

1.0
random_state int | Generator | None

The seed or generator of the energies.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import RandomEnergySystem
>>> trajectory = RandomEnergySystem(12, temperature=2.0).prepare().simulate(until=1.0)
>>> bool(abs(trajectory.get_values('ensemble.entropy')[0] - (np.log(2) - 1 / 16)) < 0.05)
True
Source code in src/skcomplex/systems/physics/statistical_mechanics/_random_energy.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def __init__(
    self,
    n_spins: int = 10,
    *,
    temperature: float = 1.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_spins = n_spins
    self.temperature = temperature
    self.random_state = random_state

ReactingParticlesElement(label, *, n=100.0)

Bases: Element

Number n of particles in a volume.

Parameters:

Name Type Description Default
label str

The label of the particles.

required
n Annotated[float, NN]

The initial number of particles.

100.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ReactingParticlesElement
>>> ReactingParticlesElement('particles').n
100.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_absorbing_processes.py
43
44
45
def __init__(self, label: str, *, n: Annotated[float, NN] = 100.0) -> None:
    super().__init__(label)
    self.n = n

ReservoirInteraction(label, *, sites, inflow=0.0, outflow=0.0, exclusion=False)

Bases: Interaction

Reservoir that adds and removes particles at its sites.

The reservoir adds one particle to each of its sites at rate inflow and removes one at rate outflow.

A particle leaves only an occupied site. With exclusion a particle enters only an empty site. It is a transfer of one particle from the environment into every site, with jumps back to the environment at the outflow rate.

Parameters:

Name Type Description Default
label str

The label of the reservoir.

required
sites tuple[Role, ...]

The sites in contact with the reservoir.

required
inflow Annotated[float, closed_open(0, oo)]

The rate at which a particle enters a site.

0.0
outflow Annotated[float, closed_open(0, oo)]

The rate at which a particle leaves an occupied site.

0.0
exclusion bool

Whether a site holds at most one particle.

False

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ReservoirInteraction
>>> ReservoirInteraction('bath', sites=('lane[0]',), inflow=0.5).outflow
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def __init__(
    self,
    label: str,
    *,
    sites: tuple[Role, ...],
    inflow: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    outflow: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    exclusion: bool = False,
) -> None:
    super().__init__(label)
    self.sites = sites
    self.inflow = inflow
    self.outflow = outflow
    self.exclusion = exclusion

SherringtonKirkpatrickSystem(n_spins=200, *, temperature=0.5, J=1.0, h=0.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Sherrington-Kirkpatrick spin glass with Glauber dynamics.

The glass freezes below the temperature T_c = J.

The energy is -sum_{i<j} J_ij s_i s_j - h sum_i s_i with quenched Gaussian couplings J_ij of mean 0 and variance J^2 / N, drawn once. Above T_c the energy per spin is -J^2 / (2 T), and below it the spins freeze in random directions, with no magnetization. The spins are drawn in a row, which orders the drawing only. The system has the spins spins.spin, the coupling matrix of unit scale in the interaction flips, and the observable magnetization.

Parameters:

Name Type Description Default
n_spins int

The number of spins.

200
temperature float

The temperature, which can change during a run.

0.5
J float

The standard deviation of the couplings times the square root of the number of spins.

1.0
h float

The external field.

0.0
random_state int | Generator | None

The seed or generator of the couplings and of the random initial spins.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import SherringtonKirkpatrickSystem
>>> couplings = SherringtonKirkpatrickSystem(10).prepare().system_.interactions[0].couplings
>>> bool((couplings == couplings.T).all()), float(couplings.trace())
(True, 0.0)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_fully_connected_spins.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
def __init__(
    self,
    n_spins: int = 200,
    *,
    temperature: float = 0.5,
    J: float = 1.0,
    h: float = 0.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_spins = n_spins
    self.temperature = temperature
    self.J = J
    self.h = h
    self.random_state = random_state

SitePercolationSystem(shape=(64, 64), *, p=0.6, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Site percolation probed by a fire lit along the top row.

The fire spans the lattice above p_c = 0.5927.

Sites are occupied with probability p, and the fire burns the clusters connected to the top row, one layer of sites per step. The system has the covers lattice.cover.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of rows and columns.

(64, 64)
p float

The occupation probability.

0.6
random_state int | Generator | None

The seed or generator of the occupations.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import SitePercolationSystem
>>> trajectory = SitePercolationSystem((10, 10)).prepare().simulate(until=1)
>>> trajectory.get_values('lattice.cover').shape
(2, 100)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
694
695
696
697
698
699
700
701
702
703
704
705
706
707
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    p: float = 0.6,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.shape = shape
    self.p = p
    self.random_state = random_state

StickingWalkInteraction(label, *, target)

Bases: Interaction

Random walk of walkers that stick when they reach the aggregate.

Every free walker joins the aggregate when a stuck walker is on a neighbouring cell, and otherwise steps to a random neighbouring cell. It is a particle of soot that joins a cluster, a metal ion that deposits on an electrode, or a bacterium that settles on a colony.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the walkers.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import StickingWalkInteraction
>>> StickingWalkInteraction('walk', target='walkers').target
'walkers'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
542
543
544
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

walk(agent, system)

Stick next to the aggregate, or step to a random neighbouring cell.

Parameters:

Name Type Description Default
agent WalkerView

The walker.

required
system SystemView

The system.

required
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
def walk(self, agent: WalkerView, system: SystemView) -> None:
    """Stick next to the aggregate, or step to a random neighbouring cell.

    Args:
        agent:
            The walker.

        system:
            The system.
    """
    if agent.stuck:
        return
    if any(isinstance(other, WalkerView) and other.stuck for other in agent.get_neighbors()):
        agent.stuck = 1.0
        return
    cells = agent.get_neighbor_cells()
    agent.move_to(cells[int(system.rng.integers(len(cells)))])

SusceptibilityResult(values, labels, mean, variance, skewness, kurtosis, susceptibility, peak) dataclass

Susceptibility of every series of samples of an order parameter.

There is one series per control value.

Parameters:

Name Type Description Default
values Array

The samples, one per column.

required
labels list[str]

The label of every series.

required
mean Array

The mean absolute order parameter of every series.

required
variance Array

The variance of the absolute order parameter of every series.

required
skewness Array

The skewness of the absolute order parameter of every series.

required
kurtosis Array

The excess kurtosis of the absolute order parameter of every series.

required
susceptibility Array

The susceptibility of every series.

required
peak float | None

The control parameter value of the largest susceptibility, refined by a parabola through its neighbours, or None without control parameter values.

required

TASEPSystem(n_sites=200, *, p=0.5, alpha=0.3, beta=0.7, ring=False, density=0.5, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The totally asymmetric simple exclusion process with parallel update.

The process runs on an open line or a ring.

Every step all particles whose right neighbour is empty hop to it with probability p at once, with one draw for every pair of neighbouring sites. On an open line particles enter the first site with probability alpha and leave the last site with probability beta. On a ring at density rho the current is (1 - sqrt(1 - 4 p rho (1 - rho))) / 2. On an open line the entry and exit probabilities select the low-density, high-density, or maximal-current phase. The system has the occupations lane.occupied, and on an open line the expected entries lane.entry and exits lane.exit of every step.

Parameters:

Name Type Description Default
n_sites int

The number of sites.

200
p float

The probability of a hop.

0.5
alpha float

The probability of an entry at the left end of an open line.

0.3
beta float

The probability of an exit at the right end of an open line.

0.7
ring bool

Whether the line is a ring instead of an open line.

False
density float

The initial fraction of occupied sites.

0.5
random_state int | Generator | None

The seed or generator of the initial occupations.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TASEPSystem
>>> [interaction.label for interaction in TASEPSystem(20).prepare().system_.interactions]
['hops', 'entry', 'exit']
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
def __init__(
    self,
    n_sites: int = 200,
    *,
    p: float = 0.5,
    alpha: float = 0.3,
    beta: float = 0.7,
    ring: bool = False,
    density: float = 0.5,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_sites = n_sites
    self.p = p
    self.alpha = alpha
    self.beta = beta
    self.ring = ring
    self.density = density
    self.random_state = random_state

TrapEscapeInteraction(label, *, target)

Bases: Interaction

Escape of walkers from their traps after activated waiting times.

A walker in a trap of depth E escapes after an exponential time of mean tau0 exp(E / T) and falls into a new trap of the fully connected landscape, at a uniformly random place in the unit square, whose depth is drawn from the density exp(-E). It is a carrier hopping between the defects of a glass, or a protein between its folds.

Parameters:

Name Type Description Default
label str

The label of the interaction, which names the count of escapes.

required
target Role

The path of the walkers.

required

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TrapEscapeInteraction
>>> TrapEscapeInteraction('escapes', target='walkers').target
'walkers'
Source code in src/skcomplex/systems/physics/statistical_mechanics/_traps.py
105
106
107
def __init__(self, label: str, *, target: Role) -> None:
    super().__init__(label)
    self.target = target

TrapSystem(n_walkers=500, *, T=0.5, tau0=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Bouchaud trap system.

Walkers escape from traps of exponentially distributed depths.

The escape times tau0 exp(E / T) of depths with the density exp(-E) have the tail tau^(-1 - T). Below the glass temperature T = 1 their mean diverges, so the walkers fall into ever deeper traps, the number of escapes grows as t^T instead of linearly, and the system ages without reaching equilibrium. The system has the places walkers.x, the depths walkers.E, and the escape count escapes.renewals.

Parameters:

Name Type Description Default
n_walkers int

The number of independent walkers.

500
T float

The temperature, in units of the mean depth.

0.5
tau0 float

The escape time from a trap of zero depth.

1.0
random_state int | Generator | None

The seed or generator of the first traps.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TrapSystem
>>> TrapSystem(10, T=0.8).prepare().system_.elements[0].T
0.8
Source code in src/skcomplex/systems/physics/statistical_mechanics/_traps.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def __init__(
    self,
    n_walkers: int = 500,
    *,
    T: float = 0.5,
    tau0: float = 1.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_walkers = n_walkers
    self.T = T
    self.tau0 = tau0
    self.random_state = random_state

TrapWalkerElement(label, *, x=0.5, E=1.0, T=0.5, tau0=1.0, size=None, space=None)

Bases: Element

Walker in a trap of depth E at the place x.

A TrapEscapeInteraction makes the walker escape after an exponential time of mean tau0 exp(E / T).

Parameters:

Name Type Description Default
label str

The label of the walker or the group.

required
x ArrayLike

The place of the trap.

0.5
E Annotated[object, closed_open(0, oo)]

The depth of the trap.

1.0
T Annotated[float, open(0, oo)]

The temperature, in units of the mean depth.

0.5
tau0 Annotated[float, open(0, oo)]

The escape time from a trap of zero depth.

1.0
size int | None

The number of walkers, or None for one.

None
space BaseSpace | None

The square of the traps, or None for none.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TrapWalkerElement
>>> TrapWalkerElement('walker', T=0.5).T
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_traps.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def __init__(
    self,
    label: str,
    *,
    x: npt.ArrayLike = 0.5,
    E: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    T: Annotated[float, RealSet.open(0, oo)] = 0.5,
    tau0: Annotated[float, RealSet.open(0, oo)] = 1.0,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, size=size, space=space)
    self.x = x
    self.E = E
    self.T = T
    self.tau0 = tau0

TreeNodeElement(label, *, n=0.0, x=0.0, size=None)

Bases: Element

Nodes of a tree that hold a number n of energy quanta each.

Every node is drawn at a fixed position.

Parameters:

Name Type Description Default
label str

The label of the node or the group.

required
n object

The initial number of quanta, or one number per node.

0.0
x object

The position of the node in the drawing of the tree, or one position per node.

0.0
size int | None

The number of nodes, or None for one.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TreeNodeElement
>>> TreeNodeElement('root').n
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
86
87
88
89
def __init__(self, label: str, *, n: object = 0.0, x: object = 0.0, size: int | None = None) -> None:
    super().__init__(label, size=size)
    self.n = n
    self.x = x

TwoPhaseZoneExchangeSystem(n_zones=100, *, Na=100.0, p=0.1, k=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Independent zones of a two-phase apparatus.

Each zone exchanges particles with the rest of the apparatus.

The zones start empty and their numbers of particles settle on the binomial distribution of mean Na p and variance Na p (1 - p). The system has the numbers zones.N.

Parameters:

Name Type Description Default
n_zones int

The number of independent zones.

100
Na float

The number of particles in the apparatus and a zone.

100.0
p float

The volume fraction of a zone.

0.1
k float

The rate of exchange.

1.0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import TwoPhaseZoneExchangeSystem
>>> TwoPhaseZoneExchangeSystem(5).prepare().system_.elements[0].size
5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
def __init__(
    self,
    n_zones: int = 100,
    *,
    Na: float = 100.0,
    p: float = 0.1,
    k: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_zones = n_zones
    self.Na = Na
    self.p = p
    self.k = k

WalkerElement(label, *, stuck=0.0, x=0, y=0, size=None, space=None)

Bases: Element

Random walkers of diffusion-limited aggregation at the cells (x, y).

A StickingWalkInteraction moves the walkers and sticks them to the aggregate.

Parameters:

Name Type Description Default
label str

The label of the agent or group.

required
stuck Annotated[object, FiniteEnumeratedSet([0, 1])]

Whether the walker belongs to the aggregate.

0.0
x object

The first coordinate of the cell of the walker.

0
y object

The second coordinate of the cell of the walker.

0
size int | None

The number of walkers, or None for one.

None
space BaseSpace | None

The grid of the walkers, or None for none.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import WalkerElement
>>> WalkerElement('walker').stuck
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_processes.py
504
505
506
507
508
509
510
511
512
513
514
515
516
517
def __init__(
    self,
    label: str,
    *,
    stuck: Annotated[object, FiniteEnumeratedSet([0, 1])] = 0.0,
    x: object = 0,
    y: object = 0,
    size: int | None = None,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, size=size, space=space)
    self.stuck = stuck
    self.x = x
    self.y = y

WalkerView

Bases: AgentViewProtocol, Protocol

Walker of diffusion-limited aggregation as rules see it.

The walker holds whether it belongs to the aggregate.

Parameters:

Name Type Description Default
agent

The Mesa agent.

required
stepper

The stepper that runs the system.

required

XXZExchangeInteraction(label, *, among, J=1.0, delta=1.0, along=True)

Bases: Interaction

Exchange between neighbouring spins.

The exchange is J (S^x_i S^x_j + S^y_i S^y_j + Δ S^z_i S^z_j) on every pair of neighbours of the space of the spins.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
among Role

The path of the spins.

required
J float

The exchange coupling, antiferromagnetic when positive.

1.0
delta float

The anisotropy Δ, 1 for the isotropic chain and 0 for the XX chain.

1.0
along bool | str

The pairs the exchange couples, True for the neighbours of the space of the spins.

True

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import XXZExchangeInteraction
>>> XXZExchangeInteraction('exchange', among='chain', delta=0.5).delta
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
176
177
178
179
180
181
182
183
184
185
186
187
def __init__(
    self,
    label: str,
    *,
    among: Role,
    J: float = 1.0,
    delta: float = 1.0,
    along: bool | str = True,
) -> None:
    super().__init__(label, among=among, along=along)
    self.J = J
    self.delta = delta

XYSpinElement(label, *, theta=0.0, J=1.0, temperature=0.5, space=None)

Bases: Element

Planar spin of the XY system, an angle theta.

The spin has its coupling J and its temperature.

An XYSamplingInteraction rotates the angles by Monte Carlo sweeps at the temperature of the spins.

Parameters:

Name Type Description Default
label str

The label of the spin or the lattice group.

required
theta Annotated[object, Period(2 * pi)]

The initial angle.

0.0
J float

The coupling between neighbouring spins.

1.0
temperature Annotated[float, open(0, oo)]

The temperature in units of the coupling.

0.5
space BaseSpace | None

The lattice of the spins, or None for one spin.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import XYSpinElement
>>> XYSpinElement('spin').temperature
0.5
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spins.py
102
103
104
105
106
107
108
109
110
111
112
113
114
def __init__(
    self,
    label: str,
    *,
    theta: Annotated[object, Period(2 * math.pi)] = 0.0,
    J: float = 1.0,
    temperature: Annotated[float, RealSet.open(0, oo)] = 0.5,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.theta = theta
    self.J = J
    self.temperature = temperature

XYSystem(size=64, *, temperature=0.5, J=1.0, width=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The XY system of planar spins on a torus.

Its vortices bind below the Kosterlitz-Thouless point.

The system has the angles spins.theta.

Parameters:

Name Type Description Default
size int | Sequence[int]

The side of the square lattice, or its shape.

64
temperature float

The temperature in units of the coupling.

0.5
J float

The coupling between neighbouring spins.

1.0
width float

The largest change of a proposed rotation.

1.0
random_state int | Generator | None

The seed or generator of the random initial angles.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import XYSystem
>>> XYSystem(8).prepare().system_.solver.width
1.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_spins.py
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def __init__(
    self,
    size: int | Sequence[int] = 64,
    *,
    temperature: float = 0.5,
    J: float = 1.0,
    width: float = 1.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.size = size
    self.temperature = temperature
    self.J = J
    self.width = width
    self.random_state = random_state

ZeemanFieldInteraction(label, *, target, h=0.0)

Bases: Interaction

Uniform field -h Σ S^z_i on the spins of a chain.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the spin chain.

required
h float

The field.

0.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZeemanFieldInteraction
>>> ZeemanFieldInteraction('field', target='chain', h=0.2).h
0.2
Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
227
228
229
230
def __init__(self, label: str, *, target: Role, h: float = 0.0) -> None:
    super().__init__(label)
    self.target = target
    self.h = h

ZeroRangeHopInteraction(label, *, link, p=1.0, q=0.0, b=4.0)

Bases: Interaction

Hop of one particle along a link.

The particle hops forward at rate p u(n) and backward at rate q u(n').

The rate depends only on the occupation of the departure site, through u(n) = 1 + b / n. It is a transfer of one particle from the first site to the second, with jumps back at the reverse rate.

Parameters:

Name Type Description Default
label str

The label of the link.

required
link tuple[Role, ...]

The departure and the arrival site of a forward hop.

required
p Annotated[float, closed_open(0, oo)]

The forward rate scale.

1.0
q Annotated[float, closed_open(0, oo)]

The backward rate scale.

0.0
b Annotated[float, closed_open(0, oo)]

The strength of the decrease of u(n) with the occupation, 0 for a constant rate.

4.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZeroRangeHopInteraction
>>> ZeroRangeHopInteraction('hop', link=['sites[0]', 'sites[1]']).b
4.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
def __init__(
    self,
    label: str,
    *,
    link: tuple[Role, ...],
    p: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    q: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    b: Annotated[float, RealSet.closed_open(0, oo)] = 4.0,
) -> None:
    super().__init__(label)
    self.link = link
    self.p = p
    self.q = q
    self.b = b

ZeroRangeHopsInteraction(label, *, sites, p=1.0, q=0.0, b=4.0)

Bases: Interaction

Hops of one particle from every site of a ring.

The particle hops to the right at rate p u(n) and to the left at rate q u(n).

The rate depends only on the occupation n of the departure site, through u(n) = 1 + b / n. Every site moves one particle to the site on its right, JumpLaw(p u(n), {n: -1, n': 1}) with n' the site on the right, and the site on the right moves one back at the rate q u(n').

Parameters:

Name Type Description Default
label str

The label of the hops.

required
sites Role

The group of sites, in ring order.

required
p Annotated[float, closed_open(0, oo)]

The rate scale of hops to the right.

1.0
q Annotated[float, closed_open(0, oo)]

The rate scale of hops to the left.

0.0
b Annotated[float, closed_open(0, oo)]

The strength of the decrease of u(n) with the occupation, 0 for a constant rate.

4.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZeroRangeHopsInteraction
>>> ZeroRangeHopsInteraction('hops', sites='sites').b
4.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
def __init__(
    self,
    label: str,
    *,
    sites: Role,
    p: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    q: Annotated[float, RealSet.closed_open(0, oo)] = 0.0,
    b: Annotated[float, RealSet.closed_open(0, oo)] = 4.0,
) -> None:
    super().__init__(label)
    self.sites = sites
    self.p = p
    self.q = q
    self.b = b

ZeroRangeProcessSystem(n_sites=50, *, density=3.0, b=4.0, p=1.0, q=0.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The zero-range process on a ring.

The process condenses above the critical density 1 / (b - 2) for b > 2.

A particle leaves a site with n particles at rate u(n) = 1 + b / n, to the right with weight p and to the left with weight q. The stationary distribution factorizes with the weights f(n) = prod_k 1 / u(k), which decay as n^-b. Above the critical density a fluid at density 1 / (b - 2) coexists with one site that holds the excess particles. The system has the occupations sites.n.

Parameters:

Name Type Description Default
n_sites int

The number of sites.

50
density float

The number of particles per site.

3.0
b float

The strength of the decrease of the departure rate with the occupation.

4.0
p float

The rate scale of hops to the right.

1.0
q float

The rate scale of hops to the left.

0.0
random_state int | Generator | None

The seed or generator of the initial sites of the particles.

0
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZeroRangeProcessSystem
>>> system = ZeroRangeProcessSystem(10, density=2.0).prepare().system_
>>> float(system.elements[0].values['n'].sum()), len(system.interactions)
(20.0, 1)
Source code in src/skcomplex/systems/physics/statistical_mechanics/_driven_particles.py
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
def __init__(
    self,
    n_sites: int = 50,
    *,
    density: float = 3.0,
    b: float = 4.0,
    p: float = 1.0,
    q: float = 0.0,
    random_state: int | np.random.Generator | None = 0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n_sites = n_sites
    self.density = density
    self.b = b
    self.p = p
    self.q = q
    self.random_state = random_state

ZoneElement(label, *, N=0.0, size=None)

Bases: Element

Small zones of a two-phase apparatus, with the number N of particles in each.

Parameters:

Name Type Description Default
label str

The label of the zone or the group.

required
N object

The initial number of particles in the zone, or one number per zone.

0.0
size int | None

The number of zones, or None for one.

None

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZoneElement
>>> ZoneElement('zone').N
0.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
163
164
165
def __init__(self, label: str, *, N: object = 0.0, size: int | None = None) -> None:
    super().__init__(label, size=size)
    self.N = N

ZoneExchangeInteraction(label, *, target, Na=100.0, p=0.1, k=1.0)

Bases: Interaction

Exchange of particles between a small zone and the rest of a two-phase apparatus.

Every one of the Na particles enters the zone at the rate k p and leaves it at the rate k (1 - p), where p = dV / V is the volume fraction of the zone, so the number in the zone is binomial with mean Na p.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the zones, whose value N counts their particles.

required
Na Annotated[float, closed_open(0, oo)]

The number of particles in the apparatus and the zone.

100.0
p Annotated[float, closed_open(0, oo)]

The volume fraction of the zone.

0.1
k Annotated[float, open(0, oo)]

The rate of exchange.

1.0

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import ZoneExchangeInteraction
>>> ZoneExchangeInteraction('exchange', target='zones').Na
100.0
Source code in src/skcomplex/systems/physics/statistical_mechanics/_master_equations.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def __init__(
    self,
    label: str,
    *,
    target: Role,
    Na: Annotated[float, RealSet.closed_open(0, oo)] = 100.0,
    p: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
    k: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.Na = Na
    self.p = p
    self.k = k

kinetic_temperature(source, *, group=None, mass=1.0)

Return the kinetic temperature m <|v|²> / d of the agents of every frame.

The agents move in d dimensions, with k_B = 1.

It is the second moment of the speeds of the agents scaled by the mass over the dimension, as equipartition gives k_B T / 2 per degree of freedom. It reads the velocities of the agents or particles of a trajectory, as the alignment of the agents reads them, or an array of velocities of one snapshot, one row per agent, or of one snapshot per frame along its first axis.

Parameters:

Name Type Description Default
source DataSource

The trajectory, or an array of velocities.

required
group str | None

The path of the agent or particle group of a trajectory, or None for the first one.

None
mass float

The mass of every agent.

1.0

Returns:

Name Type Description
result KineticTemperatureResult

The velocities and the kinetic temperature of every frame.

Raises:

Type Description
AnalysisError

The mass is not positive, the source is neither a trajectory nor an array, or the agents have no velocities.

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import kinetic_temperature
>>> kinetic_temperature([[1.0, 0.0], [0.0, 1.0]]).temperature
array([0.5])
Source code in src/skcomplex/systems/physics/statistical_mechanics/_kinetic_temperature.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def kinetic_temperature(source: DataSource, *, group: str | None = None, mass: float = 1.0) -> KineticTemperatureResult:
    """Return the kinetic temperature `m <|v|²> / d` of the agents of every frame.

    The agents move in `d` dimensions, with `k_B = 1`.

    It is the second moment of the speeds of the agents scaled by the mass over the dimension, as equipartition gives
    `k_B T / 2` per degree of freedom. It reads the velocities of the agents or particles of a trajectory, as the
    alignment of the agents reads them, or an array of velocities of one snapshot, one row per agent, or of one
    snapshot per frame along its first axis.

    Args:
        source:
            The trajectory, or an array of velocities.

        group:
            The path of the agent or particle group of a trajectory, or `None` for the first one.

        mass:
            The mass of every agent.

    Returns:
        result:
            The velocities and the kinetic temperature of every frame.

    Raises:
        AnalysisError:
            The mass is not positive, the source is neither a trajectory nor an array, or the agents have no
            velocities.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics import kinetic_temperature
        >>> kinetic_temperature([[1.0, 0.0], [0.0, 1.0]]).temperature
        array([0.5])
    """
    if mass <= 0:
        error_msg = f'kinetic_temperature has mass={mass!r}. Use a positive mass.'
        raise AnalysisError(error_msg)
    velocities = _read_velocities(source, group, 'kinetic_temperature')
    return KineticTemperatureResult(velocities, _kinetic_temperature(velocities, mass))

local_magnetization(member)

Return the z component of one spin.

Parameters:

Name Type Description Default
member SimpleNamespace

The namespace of one spin.

required

Returns:

Name Type Description
operator Expression

The local magnetisation.

Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
243
244
245
246
247
248
249
250
251
252
253
254
def local_magnetization(member: SimpleNamespace) -> Expression:
    """Return the `z` component of one spin.

    Args:
        member:
            The namespace of one spin.

    Returns:
        operator:
            The local magnetisation.
    """
    return local_operator(member.psi, 'z')

maxwell_boltzmann(source, *, group=None, mass=1.0, temperature=None)

Return the Kolmogorov-Smirnov test of the speeds of every frame.

The test compares the speeds with the Maxwell-Boltzmann law.

It is the test of the named law 'maxwell' of fit_law, generalized to d dimensions: the speeds of an ideal gas at temperature T follow a chi law of d degrees of freedom and scale sqrt(T / m), the Maxwell law in three dimensions and the Rayleigh law in two. The temperature is the kinetic temperature of every frame unless it is given. It reads the velocities of the agents or particles of a trajectory, or an array of velocities of one snapshot, one row per agent, or of one snapshot per frame along its first axis.

Parameters:

Name Type Description Default
source DataSource

The trajectory, or an array of velocities.

required
group str | None

The path of the agent or particle group of a trajectory, or None for the first one.

None
mass float

The mass of every agent.

1.0
temperature float | None

The temperature of the law, or None for the kinetic temperature of every frame.

None

Returns:

Name Type Description
result MaxwellBoltzmannResult

The velocities, the temperature of the law, and the test of every frame.

Raises:

Type Description
AnalysisError

The mass or the temperature is not positive, the source is neither a trajectory nor an array, or the agents have no velocities.

Examples:

>>> import numpy as np
>>> from skcomplex.systems.physics.statistical_mechanics import maxwell_boltzmann
>>> velocities = np.random.default_rng(0).standard_normal((2000, 3))
>>> bool(maxwell_boltzmann(velocities).p_value[0] > 0.05)
True
Source code in src/skcomplex/systems/physics/statistical_mechanics/_maxwell_boltzmann.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def maxwell_boltzmann(
    source: DataSource,
    *,
    group: str | None = None,
    mass: float = 1.0,
    temperature: float | None = None,
) -> MaxwellBoltzmannResult:
    """Return the Kolmogorov-Smirnov test of the speeds of every frame.

    The test compares the speeds with the Maxwell-Boltzmann law.

    It is the test of the named law `'maxwell'` of `fit_law`, generalized to `d` dimensions: the speeds of an ideal gas
    at temperature `T` follow a chi law of `d` degrees of freedom and scale `sqrt(T / m)`, the Maxwell law in three
    dimensions and the Rayleigh law in two. The temperature is the kinetic temperature of every frame unless it is
    given. It reads the velocities of the agents or particles of a trajectory, or an array of velocities of one
    snapshot, one row per agent, or of one snapshot per frame along its first axis.

    Args:
        source:
            The trajectory, or an array of velocities.

        group:
            The path of the agent or particle group of a trajectory, or `None` for the first one.

        mass:
            The mass of every agent.

        temperature:
            The temperature of the law, or `None` for the kinetic temperature of every frame.

    Returns:
        result:
            The velocities, the temperature of the law, and the test of every frame.

    Raises:
        AnalysisError:
            The mass or the temperature is not positive, the source is neither a trajectory nor an array, or the agents
            have no velocities.

    Examples:
        >>> import numpy as np
        >>> from skcomplex.systems.physics.statistical_mechanics import maxwell_boltzmann
        >>> velocities = np.random.default_rng(0).standard_normal((2000, 3))
        >>> bool(maxwell_boltzmann(velocities).p_value[0] > 0.05)
        True
    """
    if mass <= 0 or (temperature is not None and temperature <= 0):
        error_msg = f'maxwell_boltzmann has mass={mass!r} and temperature={temperature!r}. Use positive values.'
        raise AnalysisError(error_msg)
    velocities = _read_velocities(source, group, 'maxwell_boltzmann')
    tests = [_maxwell_boltzmann(frame, mass, temperature) for frame in velocities]
    temperatures, statistics, p_values = np.asarray(tests).T
    return MaxwellBoltzmannResult(velocities, temperatures, statistics, p_values)

susceptibility(source, *, variables=None, group=None, size=1.0, temperatures=None, parameters=None)

Return the susceptibility N (<m²> - <|m|>²) of every series of samples.

The samples are those of an order parameter.

It is the distribution of kind 'moments' of the absolute samples, whose variance it scales by the system size N and divides by the temperature when temperatures are given. Over a sweep of a control parameter, one series per control value, the susceptibility peaks near the transition, and the peak is refined by a parabola through its neighbours.

Parameters:

Name Type Description Default
source DataSource

The trajectory, or an array with one column per series of samples.

required
variables Sequence[str] | None

The variables of a trajectory to read, or None for every scalar series.

None
group str | None

The path of the agent or particle group whose speeds are read, or None for the series of a trajectory.

None
size float

The system size N that scales the variance.

1.0
temperatures Sequence[float] | None

The temperature of every series that divides the susceptibility, or None to leave it undivided.

None
parameters Sequence[float] | None

The control parameter value of every series, or None without a peak.

None

Returns:

Name Type Description
result SusceptibilityResult

The moments of the absolute samples, the susceptibility, and its peak.

Raises:

Type Description
AnalysisError

The system size is not positive.

Examples:

>>> from skcomplex.systems.physics.statistical_mechanics import susceptibility
>>> susceptibility([0.5, -1.0, 0.5, -1.0], size=4).susceptibility.tolist()
[0.25]
Source code in src/skcomplex/systems/physics/statistical_mechanics/_susceptibility.py
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def susceptibility(
    source: DataSource,
    *,
    variables: Sequence[str] | None = None,
    group: str | None = None,
    size: float = 1.0,
    temperatures: Sequence[float] | None = None,
    parameters: Sequence[float] | None = None,
) -> SusceptibilityResult:
    """Return the susceptibility `N (<m²> - <|m|>²)` of every series of samples.

    The samples are those of an order parameter.

    It is the distribution of kind `'moments'` of the absolute samples, whose variance it scales by the system size `N`
    and divides by the temperature when `temperatures` are given. Over a sweep of a control parameter, one series per
    control value, the susceptibility peaks near the transition, and the peak is refined by a parabola through its
    neighbours.

    Args:
        source:
            The trajectory, or an array with one column per series of samples.

        variables:
            The variables of a trajectory to read, or `None` for every scalar series.

        group:
            The path of the agent or particle group whose speeds are read, or `None` for the series of a trajectory.

        size:
            The system size `N` that scales the variance.

        temperatures:
            The temperature of every series that divides the susceptibility, or `None` to leave it undivided.

        parameters:
            The control parameter value of every series, or `None` without a peak.

    Returns:
        result:
            The moments of the absolute samples, the susceptibility, and its peak.

    Raises:
        AnalysisError:
            The system size is not positive.

    Examples:
        >>> from skcomplex.systems.physics.statistical_mechanics import susceptibility
        >>> susceptibility([0.5, -1.0, 0.5, -1.0], size=4).susceptibility.tolist()
        [0.25]
    """
    if size <= 0:
        error_msg = f'susceptibility has size={size!r}. Use a positive size.'
        raise AnalysisError(error_msg)
    moments = distribution(source, kind='moments', variables=variables, group=group, absolute=True)
    if moments.mean is None or moments.variance is None or moments.skewness is None or moments.kurtosis is None:
        error_msg = 'The distribution of kind moments returned no moments.'
        raise AnalysisError(error_msg)
    values = size * moments.variance
    if temperatures is not None:
        values = values / np.asarray(temperatures, dtype=float)
    peak = None if parameters is None else _refined_peak(np.asarray(parameters, dtype=float), values)
    return SusceptibilityResult(
        moments.values,
        moments.labels,
        moments.mean,
        moments.variance,
        moments.skewness,
        moments.kurtosis,
        values,
        peak,
    )

total_magnetization(s)

Return the sum of the z components of the spins of the chain.

Parameters:

Name Type Description Default
s SimpleNamespace

The namespace of the system.

required

Returns:

Name Type Description
operator Expression

The total magnetisation.

Source code in src/skcomplex/systems/physics/statistical_mechanics/_quantum_spins.py
257
258
259
260
261
262
263
264
265
266
267
268
def total_magnetization(s: SimpleNamespace) -> Expression:
    """Return the sum of the `z` components of the spins of the chain.

    Args:
        s:
            The namespace of the system.

    Returns:
        operator:
            The total magnetisation.
    """
    return sum(local_operator(member.psi, 'z') for member in s.chain)