Forest fire on hexagonal lattices and graphs
The Drossel-Schwabl forest fire on a hexagonal lattice or on a graph.
- Class:
HexagonalForestFireSystem - Import:
from skcomplex.systems.physics.criticality import HexagonalForestFireSystem - Field:
physics/criticality - Topics:
lattice,network,fire,stochastic,power law - References:
- Drossel and Schwabl 1992
- Argun et al. 2021
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 HexagonalForestFireSystem
trajectory = HexagonalForestFireSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
shape |
(80, 80) |
graph |
None |
growth |
0.02 |
lightning |
1e-05 |
density |
0.5 |
cover |
None |
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 HexagonalForestFireSystem(BaseSystem):
"""The Drossel-Schwabl forest fire on a hexagonal lattice or on a graph.
The hexagonal cells form a triangular lattice, and on a graph the sites are its nodes.
Every site of the periodic triangular lattice has six neighbours, and every node of a graph has the neighbours along
its edges. Slow growth and rare lightning give fires of every size. The system has the covers `forest.cover`.
Args:
shape:
The number of rows and columns of the triangular lattice, unused on a graph.
graph:
The graph whose nodes are the sites, or `None` for the triangular lattice.
growth:
The probability that a tree grows on an empty site per step.
lightning:
The probability that lightning strikes a tree per step.
density:
The initial fraction of sites with a tree.
cover:
The initial cover of every site, 0 for empty, 1 for a tree, and 2 for burning, in lattice shape or node
order, or `None` for random trees at the given density.
random_state:
The seed or generator of the initial forest.
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:
>>> import networkx as nx
>>> from skcomplex.systems.physics.criticality import HexagonalForestFireSystem
>>> HexagonalForestFireSystem((10, 10)).prepare().system_.elements[0].space.prepare().size_
100
>>> HexagonalForestFireSystem(graph=nx.cycle_graph(12)).prepare().system_.elements[0].space.prepare().size_
12
"""
field = 'physics/criticality'
topics = ('lattice', 'network', 'fire', 'stochastic', 'power law')
references = ('Drossel and Schwabl 1992', 'Argun et al. 2021')
until = 400
dt = 2
def __init__(
self,
shape: Sequence[int] = (80, 80),
*,
graph: nx.Graph | None = None,
growth: float = 0.02,
lightning: float = 1e-5,
density: float = 0.5,
cover: Sequence[float] | None = None,
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.graph = graph
self.growth = growth
self.lightning = lightning
self.density = density
self.cover = cover
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the forest fire on the cells of a triangular lattice or on the nodes of a graph.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
space = (
LatticeSpace(tuple(self.shape), geometry='triangular') if self.graph is None else NetworkSpace(self.graph)
).prepare()
size = int(space.size_ or 0)
initial = (
(np.random.default_rng(self.random_state).random(size) < self.density).astype(float)
if self.cover is None
else np.ravel(np.asarray(self.cover, dtype=float))
)
forest = ForestElement('forest', cover=initial, growth=self.growth, lightning=self.lightning, space=space)
neighborhood = SITE_NEIGHBORHOODS['triangular' if self.graph is None else 'graph']
self.system_ = System(
self.label,
elements=[forest],
interactions=[FireInteraction('fire', target='forest', neighborhood=neighborhood)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
ForestElement, fromElement
Interactions:
FireInteraction, fromInteraction
class ForestElement(Element):
"""Sites of the Drossel-Schwabl forest fire.
Every site is empty at 0, a tree at 1, or burning at 2.
A `FireInteraction` grows trees on empty sites with probability `growth`, sets them on fire from a burning
neighbour or from lightning with probability `lightning`, and empties burning sites.
Args:
label:
The label of the site or the lattice of sites.
cover:
The initial cover, 0, 1, or 2, or one cover per site.
growth:
The probability that a tree grows on an empty site per step.
lightning:
The probability that lightning strikes a tree per step.
space:
The lattice or network of the sites, or `None` for one site.
Examples:
>>> from skcomplex.systems.physics.criticality import ForestElement
>>> ForestElement('site').growth
0.05
"""
def __init__(
self,
label: str,
*,
cover: object = 0.0,
growth: Annotated[float, RealSet.closed_open(0, oo)] = 0.05,
lightning: Annotated[float, RealSet.closed_open(0, oo)] = 0.0001,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.cover = cover
self.growth = growth
self.lightning = lightning
class FireInteraction(Interaction):
"""Stochastic rule of the Drossel-Schwabl forest fire.
The cover is 0 for empty, 1 for a tree, and 2 for burning.
Every step a tree catches fire from a burning neighbour or from lightning with the probability `lightning` of the
site, a burning site becomes empty, and a tree grows on an empty site with the probability `growth` of the site.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the lattice or network of sites.
neighborhood:
The neighbours a fire spreads to, the von Neumann neighbourhood of a square lattice, the six neighbours of
a triangular lattice, or the neighbours of a node, each with the site itself.
Examples:
>>> from skcomplex.systems.physics.criticality import FireInteraction
>>> FireInteraction('fire', target='forest').neighborhood.metric
'manhattan'
"""
law_classes = (UpdateLaw,)
def __init__(self, label: str, *, target: Role, neighborhood: BaseNeighborhood = NEAREST) -> None:
super().__init__(label)
self.target = target
self.neighborhood = neighborhood
@staticmethod
def _burn(
cover: Array,
*around: Array,
growth: float | Array,
lightning: float | Array,
random: Array,
**kwargs: object,
) -> Array:
"""Return the covers after trees catch fire, fires burn out, and trees grow."""
burning = np.any(np.stack(around) == BURNING, axis=0) if around else np.zeros(np.shape(cover), dtype=bool)
ignites = burning | (random < lightning)
tree = np.where(ignites, float(BURNING), 1.0)
empty = np.where(random < growth, 1.0, 0.0)
return np.where(cover == BURNING, 0.0, np.where(cover == 1, tree, empty))
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rule of the covers of the target.
Args:
context:
The namespace of the target and the time `t`.
"""
super()._prepare(context)
self.laws_ = [UpdateLaw(context.target.cover, self._burn, neighborhood=self.neighborhood, stochastic=True)]