morphogen.automata.engine

Evolution of binary cellular automata on 2D or 3D lattices.

Updates are

synchronous

every cell applies the rule to the same previous state (classical automata);

asynchronous

at each step, each cell is updated with probability async_fraction (the alpha-asynchronous automata of Fates): it avoids the period-2 oscillations of synchronous majority rules;

sequential

the sublattices of cells that are not neighbours are updated one after the other, in random order, each seeing the latest state (radius-1 neighbourhoods; on tilings, the colour classes of a greedy colouring of the neighbourhood graph, any radius).

On a Tiling (triangles, hexagons, Penrose rhombi, Ammann-Beenker tiles, prisms, truncated octahedra, golden rhombohedra…), states hold one value per cell.

morphogen.automata.engine.interface_density(state: ndarray, periodic: bool = True) → float[source]

Mean fraction, over the three axes, of pairs of adjacent cells in different states (twice its value divided by the cell size estimates the specific surface).

class morphogen.automata.engine.Evolution(state: ndarray, steps: int, history: dict[str, list]=<factory>)[source]

Bases: object

Final state and history (one entry per recorded step) of a run.

as_arrays() → dict[str, ndarray][source]
class morphogen.automata.engine.CellularAutomaton(rule: Rule | str, *, neighbourhood: str = 'moore', radius: float = 1, dims: int = 3, periodic: bool = True, boundary: int = 0, fraction: float | None = None, tiling: Tiling | None = None)[source]

Bases: object

Binary automaton: a rule acting on a neighbourhood of a periodic or fixed lattice, the square grid or a tiling (whose dims and periodic then apply; finite patches have free boundaries, boundary is ignored).

Example:

ca = CellularAutomaton("anneal", neighbourhood="moore")
state = (rng.random((64, 64, 64)) < 0.5).astype(np.uint8)
result = ca.run(state, steps=30, rng=rng)
step(state, rng: Generator, *, update: str = 'synchronous', async_fraction: float = 0.5) → ndarray[source]

State after one update.

run(state, steps: int, rng: Generator | None = None, *, update: str = 'synchronous', async_fraction: float = 0.5, record: bool = True, stop_when_stable: bool = True, callback=None) → Evolution[source]

Apply steps updates (fewer if the state stops changing).

The history records, after each step, the fraction of cells in state 1, the number of cells that changed and the interface density. callback(step, state) is called after every step (e.g. to save frames of an animation).

morphogen.automata.engine.random_state(shape, fraction: float, rng: Generator, *, exact: bool = False) → ndarray[source]

Random binary state: each cell is 1 with probability fraction (or exactly round(fraction * n) cells at random positions with exact).