Linear automata over rings
The discrete Laplacian as a linear automaton on a ring.
- Class:
LinearRingAutomatonSystem - Import:
from skcomplex.systems.computer_science.automata import LinearRingAutomatonSystem - Field:
computer_science/automata - Topics:
group,cellular automaton,linear,Laplacian - References:
- Ceccherini-Silberstein and Coornaert 2023
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 LinearRingAutomatonSystem
trajectory = LinearRingAutomatonSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
size |
101 |
modulus |
3 |
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 | integer |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class LinearRingAutomatonSystem(BaseSystem):
"""The discrete Laplacian as a linear automaton on a ring.
It runs over the field of `modulus` elements.
The ring is the cyclic group of order `size`, a periodic lattice, and every cell becomes `x(g - 1) + x(g + 1) - 2
x(g)` modulo the field size, the element `a^-1 + a - 2` of the group ring. From a single 1 in the middle the values
spread as binomial coefficients reduced modulo the field size, a self-similar triangle. The system has the cells
`cells.value`.
Args:
size:
The order of the cyclic group, the number of cells of the ring.
modulus:
The prime size of the field.
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 LinearRingAutomatonSystem
>>> LinearRingAutomatonSystem(11).prepare().simulate(until=1).get_values('cells.value').shape
(2, 11)
"""
field = 'computer_science/automata'
topics = ('group', 'cellular automaton', 'linear', 'Laplacian')
references = ('Ceccherini-Silberstein and Coornaert 2023',)
until = 40
dt = 1
observables = (Observable('mean', group='cells', variable='value'),)
def __init__(
self,
size: int = 101,
*,
modulus: int = 3,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.size = size
self.modulus = modulus
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of a ring with a single 1 in the middle and the Laplacian."""
super()._prepare(context)
values = np.zeros(self.size)
values[self.size // 2] = 1.0
self.system_ = System(
self.label,
elements=[LaplacianCellElement('cells', value=values, space=LatticeSpace(self.size))],
interactions=[LaplacianRuleInteraction('laplacian', target='cells', modulus=self.modulus)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
LaplacianCellElement, fromElement
Interactions:
LaplacianRuleInteraction, fromInteraction
class LaplacianCellElement(Element):
"""Cell of an automaton over the field of a prime number of elements.
An example is the discrete Laplacian on a ring. With `space`, the element holds one cell on every site.
Args:
label:
The label of the cells.
value:
The initial value, an integer from 0 to the size of the field minus 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 LaplacianCellElement
>>> LaplacianCellElement('cell', value=2).value
2
"""
def __init__(
self,
label: str,
*,
value: Annotated[float | Array, ZZ] = 0,
space: BaseSpace | None = None,
) -> None:
super().__init__(label, space=space)
self.value = value
class LaplacianRuleInteraction(Interaction):
"""Discrete Laplacian `x(g - 1) + x(g + 1) - 2 x(g)` of cells on a ring, modulo the size of a field.
Args:
label:
The label of the interaction.
target:
The cells whose state `value` the rule updates.
modulus:
The prime size of the field.
Examples:
>>> from skcomplex.systems.computer_science.automata import LaplacianRuleInteraction
>>> LaplacianRuleInteraction('laplacian', target='cells', modulus=5).modulus
5
"""
def __init__(self, label: str, *, target: Role = 'cells', modulus: int = 3) -> None:
super().__init__(label)
self.target = target
self.modulus = modulus
def _get_function(self) -> Callable[[Array, Array, Array], Array]:
"""Return the discrete Laplacian taken modulo the field size."""
modulus = self.modulus
def laplacian(left: Array, center: Array, right: Array, **kwargs: object) -> Array:
return (left + right - 2 * center) % modulus
return laplacian
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the Laplacian of every cell and its two neighbours as the law.
Args:
context:
The namespace of the elements a binding of the roles names.
"""
super()._prepare(context)
value = context.target.value
self.laws_: list[BaseLaw] = [
UpdateLaw(value, self._get_function(), neighborhood=THREE_CELLS, label=self.label),
]