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/components/types.py
83
84
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/components/types.py
109
110
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/components/types.py
86
87
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/components/types.py
89
90
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/components/types.py
115
116
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, or to a uniform point inside a polygon.

Source code in src/skcomplex/core/components/types.py
103
104
def move_to(self, location: object) -> None:
    """Move the agent to a cell, a node, or a position, or to a uniform point inside a polygon."""

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/components/types.py
80
81
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, group=None)

Return the other agents in the neighbouring cells or nodes, of every group or of the group of a path.

Source code in src/skcomplex/core/components/types.py
92
93
94
95
96
97
98
def neighbors(
    self,
    radius: float | None = None,
    layer: str | None = None,
    group: str | None = None,
) -> Sequence[AgentViewProtocol]:
    """Return the other agents in the neighbouring cells or nodes, of every group or of the group of a path."""

referenced(state)

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

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

regions_here(layer)

Return the indices of the regions of a layer of the continuous space that contain the agent.

Source code in src/skcomplex/core/components/types.py
100
101
def regions_here(self, layer: str) -> list[int]:
    """Return the indices of the regions of a layer of the continuous space that contain the agent."""

remove()

Remove the agent from the system.

Source code in src/skcomplex/core/components/types.py
106
107
def remove(self) -> None:
    """Remove the agent from the system."""

SystemViewProtocol

Bases: Protocol

System as agent rules read it, such as SystemView 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 system.

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 system, 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/components/types.py
131
132
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/components/types.py
194
195
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/components/types.py
169
170
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/components/types.py
184
185
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/components/types.py
181
182
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/components/types.py
178
179
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/components/types.py
142
143
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/components/types.py
191
192
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/components/types.py
175
176
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/components/types.py
197
198
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/components/types.py
151
152
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/components/types.py
172
173
def random_empty_cell(self) -> object:
    """Return the coordinates of a random empty cell of the grid or network."""

region(layer, index)

Return the polygon of a region of a layer of the continuous space.

Source code in src/skcomplex/core/components/types.py
148
149
def region(self, layer: str, index: int) -> Polygon:
    """Return the polygon of a region of a layer of the continuous space."""

regions(layer)

Return the number of regions of a layer of the continuous space.

Source code in src/skcomplex/core/components/types.py
145
146
def regions(self, layer: str) -> int:
    """Return the number of regions of a layer of the continuous space."""

report(name, value)

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

Source code in src/skcomplex/core/components/types.py
200
201
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/components/types.py
158
159
def set_parameter(self, name: str, value: float) -> None:
    """Set a parameter of any group or interaction during the run, recorded in the trajectory."""