Skip to content

Types

Define the types of the core: the targets of laws, the pairings and rules of matches, and the protocols.

AgentViewProtocol

Bases: Protocol

Agent as agent rules read it, such as AgentView of the agent stepper: its id, location, moves, and life.

alive property

Whether the agent has not been removed.

group property

Path of the group of the agent.

group_label property

Label of the agent's group, the last part of its path.

id property

Unique id of the agent.

location property

Grid coordinates, network node, or position of the agent.

location_key property

Location of the agent as a key, equal to the coordinates neighbor_cells gives for its cell or node.

agents_here(group=None)

Return the other agents of the agent's cell or node, of every group or of the group of a path.

Source code in src/skcomplex/core/types.py
145
146
def agents_here(self, group: str | None = None) -> Sequence[AgentViewProtocol]:
    """Return the other agents of the agent's cell or node, of every group or of the group of a path."""

create(group=None, location=None, **values)

Create an agent of a group, by default the agent's own group at the agent's location.

Source code in src/skcomplex/core/types.py
163
164
def create(self, group: str | None = None, location: object = None, **values: object) -> AgentViewProtocol:
    """Create an agent of a group, by default the agent's own group at the agent's location."""

displacement_to(other)

Return the vector from the agent to another agent or a location, the shortest one on a torus.

Source code in src/skcomplex/core/types.py
148
149
def displacement_to(self, other: AgentViewProtocol | object) -> npt.NDArray[np.float64]:
    """Return the vector from the agent to another agent or a location, the shortest one on a torus."""

distance_to(other)

Return the distance to another agent or a location, the number of hops on a network.

Source code in src/skcomplex/core/types.py
151
152
def distance_to(self, other: AgentViewProtocol | object) -> float:
    """Return the distance to another agent or a location, the number of hops on a network."""

lags(state, window=None)

Return the past values of a state of the agent at the ends of the last steps, the last one last.

Source code in src/skcomplex/core/types.py
169
170
def lags(self, state: str, window: int | None = None) -> npt.NDArray[np.float64]:
    """Return the past values of a state of the agent at the ends of the last steps, the last one last."""

move_to(location)

Move the agent to a cell, a node, or a position.

Source code in src/skcomplex/core/types.py
157
158
def move_to(self, location: object) -> None:
    """Move the agent to a cell, a node, or a position."""

neighbor_cells()

Return the coordinates of the cells or nodes around the agent's cell or node, hashable as location keys.

Source code in src/skcomplex/core/types.py
142
143
def neighbor_cells(self) -> list[object]:
    """Return the coordinates of the cells or nodes around the agent's cell or node, hashable as location keys."""

neighbors(radius=None, layer=None)

Return the other agents in the neighbouring cells or nodes, within a radius, or around it in a layer.

Source code in src/skcomplex/core/types.py
154
155
def neighbors(self, radius: float | None = None, layer: str | None = None) -> Sequence[AgentViewProtocol]:
    """Return the other agents in the neighbouring cells or nodes, within a radius, or around it in a layer."""

referenced(state)

Return the member of another group that a reference state of the agent names, or None.

Source code in src/skcomplex/core/types.py
166
167
def referenced(self, state: str) -> AgentViewProtocol | None:
    """Return the member of another group that a reference state of the agent names, or `None`."""

remove()

Remove the agent from the model.

Source code in src/skcomplex/core/types.py
160
161
def remove(self) -> None:
    """Remove the agent from the model."""

AutomatonProtocol(space, neighborhood, rule, states)

Bases: Protocol

Cellular automaton the analysis reads by its methods, such as Automaton of the automata models.

Source code in src/skcomplex/core/types.py
62
63
64
65
66
67
68
69
def __init__(
    self,
    space: BaseSpace,
    neighborhood: LatticeNeighborhood | MemoryNeighborhood,
    rule: object,
    states: int,
) -> None:
    """Store the space, the neighbourhood, the rule, and the number of states."""

reads property

Neighbourhood the rule reads.

size property

Number of sites.

local_map()

Return the next value of every pattern of the cells the rule reads.

Source code in src/skcomplex/core/types.py
82
83
def local_map(self) -> IntArray:
    """Return the next value of every pattern of the cells the rule reads."""

run(configuration, steps)

Return the configurations of a number of steps.

Source code in src/skcomplex/core/types.py
88
89
def run(self, configuration: npt.ArrayLike, steps: int) -> IntArray:
    """Return the configurations of a number of steps."""

step(configuration)

Return the image of a configuration.

Source code in src/skcomplex/core/types.py
85
86
def step(self, configuration: npt.ArrayLike) -> IntArray:
    """Return the image of a configuration."""

table()

Return the site of every cell the rule reads at every site.

Source code in src/skcomplex/core/types.py
79
80
def table(self) -> Indices:
    """Return the site of every cell the rule reads at every site."""

LinearAutomatonProtocol

Bases: Protocol

Linear cellular automaton the analysis reads by its matrix and its Laurent polynomial.

laurent_polynomial()

Return the Sage Laurent polynomial of the automaton on Z^d.

Source code in src/skcomplex/core/types.py
 99
100
def laurent_polynomial(self) -> LaurentPolynomial:
    """Return the Sage Laurent polynomial of the automaton on `Z^d`."""

matrix()

Return the Sage matrix of the automaton on its space.

Source code in src/skcomplex/core/types.py
96
97
def matrix(self) -> Matrix:
    """Return the Sage matrix of the automaton on its space."""

ModelViewProtocol

Bases: Protocol

Model as agent rules read it, such as ModelView of the agent stepper: its agents, storage, and randomness.

dimensions property

Extent of the agent space per axis, cells of a lattice or lengths of a continuous space, None otherwise.

inputs property

Values of the states of other partitions at the last synchronisation point, by dotted name.

parameters property

Current values of every parameter by dotted name.

rng property

Random number generator of the model.

round property

Index of the current round of a repeated phase, 0 outside repeated phases.

storage property

Mutable mapping private to the owner of the rule that persists across the steps of one run.

time property

Time of the model, with the fraction of the step that the visits of a phase reached.

torus property

Whether the agent space wraps around at its edges.

agents(name)

Return the agents of a group bound to a role of the owner, or of a group by path.

Source code in src/skcomplex/core/types.py
185
186
def agents(self, name: str) -> Sequence[AgentViewProtocol]:
    """Return the agents of a group bound to a role of the owner, or of a group by path."""

composition(name, state)

Return the number of agents of a group, a role of the owner or a path, by value of a state.

Source code in src/skcomplex/core/types.py
242
243
def composition(self, name: str, state: str) -> dict[Hashable, int]:
    """Return the number of agents of a group, a role of the owner or a path, by value of a state."""

count(name)

Return the number of agents of a group, a role of the owner or a path.

Source code in src/skcomplex/core/types.py
217
218
def count(self, name: str) -> int:
    """Return the number of agents of a group, a role of the owner or a path."""

create(group, location=None, **values)

Create an agent of a group, a role of the owner or a path, at a location or by default a random place.

Source code in src/skcomplex/core/types.py
232
233
def create(self, group: str, location: object = None, **values: object) -> AgentViewProtocol:
    """Create an agent of a group, a role of the owner or a path, at a location or by default a random place."""

deposit(name, cell, amount)

Add an amount to a field state, by path or as <role>.<state>, at a cell or node.

Source code in src/skcomplex/core/types.py
229
230
def deposit(self, name: str, cell: object, amount: float) -> None:
    """Add an amount to a field state, by path or as `<role>.<state>`, at a cell or node."""

field(name, cell)

Return the value of a field state, by path or as <role>.<state>, at a cell or node.

Source code in src/skcomplex/core/types.py
226
227
def field(self, name: str, cell: object) -> float:
    """Return the value of a field state, by path or as `<role>.<state>`, at a cell or node."""

groups(name)

Return the paths of the groups a role of the owner binds, or of a group by path.

Source code in src/skcomplex/core/types.py
196
197
def groups(self, name: str) -> list[str]:
    """Return the paths of the groups a role of the owner binds, or of a group by path."""

history(name, window=None)

Return the past values of a reporter, or of an observable at the end of every earlier step.

Source code in src/skcomplex/core/types.py
239
240
def history(self, name: str, window: int | None = None) -> npt.NDArray[np.float64]:
    """Return the past values of a reporter, or of an observable at the end of every earlier step."""

observable(name)

Return the current value of an observable of the system, such as an aggregate of a group.

Source code in src/skcomplex/core/types.py
223
224
def observable(self, name: str) -> object:
    """Return the current value of an observable of the system, such as an aggregate of a group."""

occupancy(name)

Return the number of agents of a group, a role of the owner or a path, by the key of their location.

Source code in src/skcomplex/core/types.py
245
246
def occupancy(self, name: str) -> dict[Hashable, int]:
    """Return the number of agents of a group, a role of the owner or a path, by the key of their location."""

parameter(name)

Return the current value of a parameter of the owner.

Source code in src/skcomplex/core/types.py
199
200
def parameter(self, name: str) -> float:
    """Return the current value of a parameter of the owner."""

random_empty_cell()

Return the coordinates of a random empty cell of the grid or network.

Source code in src/skcomplex/core/types.py
220
221
def random_empty_cell(self) -> object:
    """Return the coordinates of a random empty cell of the grid or network."""

report(name, value)

Publish a value of the owner as the reporter <owner>.<name>.

Source code in src/skcomplex/core/types.py
248
249
def report(self, name: str, value: float) -> None:
    """Publish a value of the owner as the reporter `<owner>.<name>`."""

set_parameter(name, value)

Set a parameter of any group or interaction during the run, recorded in the trajectory.

Source code in src/skcomplex/core/types.py
206
207
def set_parameter(self, name: str, value: float) -> None:
    """Set a parameter of any group or interaction during the run, recorded in the trajectory."""

SubshiftProtocol

Bases: Protocol

Subshift of finite type the analysis reads by its count of admissible configurations and its violations.

count(space)

Return the number of admissible configurations of a space.

Source code in src/skcomplex/core/types.py
107
108
def count(self, space: BaseSpace) -> int:
    """Return the number of admissible configurations of a space."""

violations(configuration, space)

Return the sites at which a forbidden pattern appears.

Source code in src/skcomplex/core/types.py
110
111
def violations(self, configuration: npt.ArrayLike, space: BaseSpace) -> npt.NDArray[np.bool_]:
    """Return the sites at which a forbidden pattern appears."""