Elementary automata
An elementary cellular automaton by its Wolfram number.
- Class:
ElementaryAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import ElementaryAutomatonSystem - Field:
computer_science/automata - Topics:
lattice,elementary,chaos - References:
- Wolfram 1983
- Charbonneau 2017
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.computer_science.automata import ElementaryAutomatonSystem
trajectory = ElementaryAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
rule |
30 |
size |
101 |
initial |
None |
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 | unknown |
| Domains | boolean |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class ElementaryAutomatonSystem(BaseSystem):
"""An elementary cellular automaton by its Wolfram number.
By default it starts from a single live cell. The system has the cells `cells.alive`.
Args:
rule:
The Wolfram number from 0 to 255.
size:
The number of cells of the ring.
initial:
The initial cells, or `None` for a single live cell in the middle.
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.computer_science.automata import ElementaryAutomatonSystem
>>> trajectory = ElementaryAutomatonSystem(90, size=7).prepare().simulate(until=2)
>>> trajectory.get_values('cells.alive')[-1].astype(int).tolist()
[0, 1, 0, 0, 0, 1, 0]
"""
field = 'computer_science/automata'
topics = ('lattice', 'elementary', 'chaos')
references = ('Wolfram 1983', 'Charbonneau 2017')
until = 100
dt = 1
def __init__(
self,
rule: int = 30,
*,
size: int = 101,
initial: Sequence[float] | None = None,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.rule = rule
self.size = size
self.initial = initial
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a ring of cells and its elementary rule."""
super()._prepare(context)
values = np.zeros(self.size) if self.initial is None else np.asarray(self.initial, dtype=float)
if self.initial is None:
values[self.size // 2] = 1.0
self.system_ = System(
self.label,
elements=[BinaryCellElement('cells', alive=values, space=LatticeSpace(self.size))],
interactions=[ElementaryRuleInteraction('rule', target='cells', rule=self.rule)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
BinaryCellElement, fromElement
Interactions:
ElementaryRuleInteraction, fromInteraction
class BinaryCellElement(Element):
"""Cell of an automaton whose value `alive` is 0 or 1.
The local rule of an interaction changes the value. With `space`, the element holds one cell on every site.
Args:
label:
The label of the cells.
alive:
The initial value, 0 or 1, or one value per cell.
space:
The space with one cell on every site, such as a lattice, or `None` for one cell.
Examples:
>>> from skcomplex.systems.computer_science.automata import BinaryCellElement
>>> BinaryCellElement('cell', alive=1).alive
1
"""
def __init__(
self,
label: str,
*,
alive: Annotated[float | Array, {0, 1}] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.alive = alive
class ElementaryRuleInteraction(Interaction):
"""Elementary rule of a line of cells, given by its Wolfram number.
Every cell reads itself and its two neighbours, which make one of eight patterns, and the bit of the Wolfram number
at the place of that pattern gives its next value. Rule 30 looks random, and rule 90 draws Pascal's triangle
modulo 2.
Args:
label:
The label of the interaction.
target:
The cells whose state `alive` the rule updates.
rule:
The Wolfram number from 0 to 255.
Examples:
>>> from skcomplex.systems.computer_science.automata import ElementaryRuleInteraction
>>> ElementaryRuleInteraction('rule', target='cells', rule=90).rule
90
"""
def __init__(self, label: str, *, target: Role = 'cells', rule: int = 30) -> None:
super().__init__(label)
self.target = target
self.rule = rule
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the local rule of the cells as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
alive = context.target.alive
self.laws_: list[BaseLaw] = [
UpdateLaw(alive, Wolfram(self.rule), neighborhood=ELEMENTARY, label=self.label),
]