Fixed-energy sandpile
The fixed-energy sandpile.
- Class:
FixedEnergySandpileSystem - Import:
from skcomplex.systems.physics.criticality import FixedEnergySandpileSystem - Field:
physics/criticality - Topics:
lattice,absorbing states,phase transition,conservation,sandpile - References:
- Dickman, Vespignani, and Zapperi 1998
- Vespignani et al. 2000
- Gros 2015
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.criticality import FixedEnergySandpileSystem
trajectory = FixedEnergySandpileSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
shape |
(32, 32) |
density |
2.3 |
random_state |
0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | lattice |
| Laws | update |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class FixedEnergySandpileSystem(BaseSystem):
"""The fixed-energy sandpile.
It is a Bak-Tang-Wiesenfeld pile with no drive and no loss on a periodic lattice.
Every step, every site with at least four grains gives one grain to each of its four neighbours, all at once. The
lattice is periodic, so the density of grains `density` is conserved, and it controls an absorbing phase transition.
Below the critical density, about 2.125 on the square lattice, the topplings stop in an absorbing configuration, and
above it the pile stays active forever. The density of active sites, the observable `activity`, is the order
parameter. The grains start scattered uniformly at random over the sites. The system has the heights `pile.height`
and the observable `activity`, the density of active sites.
Args:
shape:
The number of rows and columns.
density:
The mean number of grains per site.
random_state:
The seed or generator of the initial grains.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.criticality import FixedEnergySandpileSystem
>>> trajectory = FixedEnergySandpileSystem((8, 8), density=2.0).prepare().simulate(until=2)
>>> trajectory.get_values('pile.height').shape
(3, 64)
"""
field = 'physics/criticality'
topics = ('lattice', 'absorbing states', 'phase transition', 'conservation', 'sandpile')
references = ('Dickman, Vespignani, and Zapperi 1998', 'Vespignani et al. 2000', 'Gros 2015')
until = 500
dt = 1
observables = (Observable('activity', _get_active, group='pile'),)
def __init__(
self,
shape: Sequence[int] = (32, 32),
*,
density: float = 2.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.density = density
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the pile, built from its model parameters.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
size = int(np.prod(self.shape))
rng = np.random.default_rng(self.random_state)
grains = rng.integers(size, size=round(self.density * size))
heights = np.bincount(grains, minlength=size).astype(float)
space = LatticeSpace(tuple(self.shape), boundary='periodic')
self.system_ = System(
self.label,
elements=[GrainSiteElement('pile', height=heights, space=space)],
interactions=[ToppleInteraction('topple', target='pile', threshold=THRESHOLD)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
GrainSiteElement, fromElement
Interactions:
ToppleInteraction, fromInteraction
class GrainSiteElement(Element):
"""Sites of a sandpile.
Every site holds a number of grains.
Args:
label:
The label of the site or the lattice of sites.
height:
The initial number of grains, or one number per site.
space:
The lattice of the sites, or `None` for one site.
Examples:
>>> from skcomplex.systems.physics.criticality import GrainSiteElement
>>> GrainSiteElement('site').height
0.0
"""
def __init__(self, label: str, *, height: object = 0.0, space: BaseSpace | None = None) -> None:
super().__init__(label, space=space)
self.height = height
class ToppleInteraction(Interaction):
"""Parallel toppling of a sandpile without drive.
Every site at or above the threshold topples once a step.
Every step, every site that holds at least `threshold` grains loses `threshold` grains, and every site gains one
grain from each toppling neighbour, all at once. On a periodic lattice no grain is lost, so the number of grains is
conserved, and the activity either dies out in an absorbing configuration or lasts forever.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the lattice group of sites.
threshold:
The number of grains at which a site topples, the number of its neighbours.
Examples:
>>> from skcomplex.systems.physics.criticality import ToppleInteraction
>>> ToppleInteraction('topple', target='pile').threshold
4
"""
law_classes = (UpdateLaw,)
def __init__(self, label: str, *, target: Role, threshold: int = 4) -> None:
super().__init__(label)
self.target = target
self.threshold = threshold
def _get_topple(self, height: Array, *around: Array, **kwargs: object) -> Array:
"""Return the heights after every site at or above the threshold topples once."""
gained = np.sum([neighbor >= self.threshold for neighbor in around], axis=0)
return height - self.threshold * (height >= self.threshold) + gained
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the toppling of the heights of the target.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
neighborhood = RadiusNeighborhood(1, metric='manhattan', center=True)
self.laws_ = [
UpdateLaw(context.target.height, self._get_topple, neighborhood=neighborhood, label=self.label),
]