Skip to content

Viz

Draw running simulations in Rerun.

A visual draws the values of an element at every frame, such as the points of a flock, the image of a grid, or the line of a population over time.

AgentsVisual(color_by=None, color_range=None, radius=None, *, position=None, path=None, recording=None)

Bases: BaseVisual

A visual that draws the agents of a group as coloured points, once per frame.

It draws every agent at its cell, position, or network node, coloured by one of its values, such as AgentsVisual(color_by='opinion'). Points in a plane are drawn with the vertical axis up, the regions of a map are drawn once beneath them, and every point keeps the id of its agent, so agents keep their identity and removed agents vanish. Agents with one position value, such as cars on a road, are drawn as one line per agent over time. It shows the opinions of voters on a network, the wealth of traders on a grid, and the cars along a road.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
color_by str | None

The name of a numeric state that colors the agents, or None for one color.

None
color_range tuple[float, float] | None

The values at the two ends of the color scale, or None for a range widened to every logged value.

None
radius float | None

The radius of the points, or None for 0.4 on grids and networks and a share of the side of other spaces.

None
position str | None

The name of a state that holds the position of every agent, or None for the location in the space.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
styled_

The entity paths whose series style or static region outlines are logged.

span_

The range of the colored values logged so far, or None.

See Also

PointsVisual: Draws a group of members with a position value as points. HistogramVisual: Draws the spread of the values of agents as histograms.

Examples:

>>> from skcomplex.core.engine.viz import AgentsVisual
>>> AgentsVisual(color_by='opinion').color_by
'opinion'
Source code in src/skcomplex/core/engine/viz/_agents.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def __init__(
    self,
    color_by: str | None = None,
    color_range: tuple[float, float] | None = None,
    radius: float | None = None,
    *,
    position: str | None = None,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.color_by = color_by
    self.color_range = color_range
    self.radius = radius
    self.position = position
    self.path = path
    self.recording = recording

AxisVisual(state, scalar=None, every=4, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws the arrows of a vector value or the axes of a matrix value.

It draws one arrow per sampled site for a vector value, or one line along the main axis of a matrix value, on top of an image of a scalar value, such as AxisVisual('Q', scalar='rho', every=2) for every second site. A site sits at the same pixel as the image. It shows the flow of a fluid, the direction of the rods of a liquid crystal, and the heading of the cells of a tissue.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
state str

The tensor or vector state to draw.

required
scalar str | None

The scalar state of the image, or None for no image.

None
every int

The spacing of the sampled sites along every dimension.

4
path str | None

The entity path of the element to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
sites_

The row and the column of every sampled site.

Raises:

Type Description
ValidationError

The state is no tensor or vector state of a two-dimensional lattice, or the spacing is not positive.

See Also

ImageVisual: Draws scalar values on a grid as images.

Examples:

>>> from skcomplex.core.engine.viz import AxisVisual
>>> AxisVisual('Q', scalar='rho', every=2)
AxisVisual(every=2, scalar='rho', state='Q')
Source code in src/skcomplex/core/engine/viz/_axes.py
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(
    self,
    state: str,
    scalar: str | None = None,
    every: int = 4,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    super().__init__(path=path, recording=recording)
    self.state = state
    self.scalar = scalar
    self.every = every

BaseVisual(*, path=None, recording=None)

Bases: BaseConfig[BaseProblemSpec, FrameSpec]

An abstract visual, which logs a component of a system to Rerun at every frame.

A subclass draws the values of one element or group in the Rerun viewer, such as the prey of a predator and prey system in ScalarsVisual(path='prey'). prepare(problem) finds the element at path and sets the views that show it, and run(frame) draws it at one frame. A subclass draws elements with _log, agents with _log_agents, and names its views with _views. A subclass lists the options that take numbers in numeric_options, so that RerunObserver evaluates such an option given as an expression of parameters, such as 'R_0 / 2'. RerunObserver builds one visual per element. Its subclasses draw the populations of an ecosystem, the spins of a magnet, and the traders of a market.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
element_

The compiled element or agents the visual logs.

recording_

The Rerun recording the visual logs to, or None while no recording is active.

space_

The space the agents of the problem live in, or None.

layouts_

The positions of the nodes of every network drawn so far, by the id of its graph.

views_

The Rerun views that show what the visual logs, each with an entity path of the element as origin.

See Also

RerunObserver: Builds the visual of every element and logs the frames of a run. ScalarsVisual: Draws the values of an element as lines over time.

Examples:

>>> from skcomplex.core.engine.viz import ScalarsVisual
>>> from skcomplex.systems.biology.ecology import LotkaVolterraSystem
>>> problem = LotkaVolterraSystem().prepare().simulate(until=0).problem
>>> visual = ScalarsVisual(path='prey').prepare(problem)
>>> visual.element_.path, str(visual.views_[0].origin)
('prey', 'prey')
Source code in src/skcomplex/core/engine/viz/_base.py
125
126
127
def __init__(self, *, path: str | None = None, recording: rr.RecordingStream | None = None) -> None:
    self.path = path
    self.recording = recording

prepare(problem=None)

Prepare the checked visual for the element at its path in a compiled problem.

Parameters:

Name Type Description Default
problem BaseProblemSpec | None

The compiled problem.

None

Returns:

Name Type Description
self Self

The prepared visual, with its views views_.

Raises:

Type Description
ValidationError

No element or agent group of the problem has the path of the visual.

Source code in src/skcomplex/core/engine/viz/_base.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def prepare(self, problem: BaseProblemSpec | None = None) -> Self:
    """Prepare the checked visual for the element at its path in a compiled problem.

    Args:
        problem:
            The compiled problem.

    Returns:
        self:
            The prepared visual, with its views `views_`.

    Raises:
        ValidationError:
            No element or agent group of the problem has the path of the visual.
    """
    return super().prepare(problem)

run(frame=None, final=False)

Log the element or the agents of the visual at a frame.

Parameters:

Name Type Description Default
frame FrameSpec | None

The frame.

None
final bool

Whether this is the last call of the run.

False

Returns:

Name Type Description
self Self

The visual.

Source code in src/skcomplex/core/engine/viz/_base.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def run(self, frame: FrameSpec | None = None, final: bool = False) -> Self:
    """Log the element or the agents of the visual at a frame.

    Args:
        frame:
            The frame.

        final:
            Whether this is the last call of the run.

    Returns:
        self:
            The visual.
    """
    super().run(frame, final)
    return self

BodiesVisual(positions, *, pivot=None, rods=False, traced=None, trail=TRAIL_LENGTH, outline=(), marks=(), radius=None, path=None, recording=None)

Bases: BaseVisual

A visual that draws bodies at positions computed from the states of an element.

It computes the position of every body from the values of an element and draws the bodies as points, with rods from a pivot through them, trails that fade with age, and fixed outlines and marks, such as BodiesVisual(('x', 'y'), trail=50) for one body whose position is held by x and y. Every value is also drawn as a line over time, and bodies in a plane are drawn with the vertical axis up. It shows the swing of a double pendulum, the orbits of planets, and a ball bouncing on a table.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
positions Positions

A function of the parameters and states of the element by keyword that returns one row (x, y) per body, or the names of the two states that hold the position of a single body.

required
pivot Sequence[float] | None

The fixed point the rods start from, or None to start them at the first body.

None
rods bool

Whether to draw rods through the bodies.

False
traced Sequence[int] | None

The indices of the bodies whose trails are drawn, or None for every body.

None
trail int | None

The number of recent positions in a trail, 0 for no trail, or None for the whole path.

TRAIL_LENGTH
outline Outline

Static polylines, each an array of rows (x, y), such as the walls of a table, or a function of the parameters and states by keyword that returns them from the first frame.

()
marks Marks

Static points, such as fixed attracting centres, or a function of the parameters and states by keyword that returns them from the first frame.

()
radius float | None

The radius of the bodies, or None for a share of the extent of the view.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
history_

The recent positions of the traced bodies, the oldest first.

drawn_

The entity paths whose outline and marks are logged.

See Also

PointsVisual: Draws a group whose position is one vector value.

Examples:

>>> from skcomplex.core.engine.viz import BodiesVisual
>>> BodiesVisual(('x', 'y'), trail=50).trail
50
Source code in src/skcomplex/core/engine/viz/_bodies.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def __init__(
    self,
    positions: Positions,
    *,
    pivot: Sequence[float] | None = None,
    rods: bool = False,
    traced: Sequence[int] | None = None,
    trail: int | None = TRAIL_LENGTH,
    outline: Outline = (),
    marks: Marks = (),
    radius: float | None = None,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.positions = positions
    self.pivot = pivot
    self.rods = rods
    self.traced = traced
    self.trail = trail
    self.outline = outline
    self.marks = marks
    self.radius = radius
    self.path = path
    self.recording = recording

CellVisual(state=None, plane=(0, 1), section=0, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws a value on the links or faces of a cell complex.

It draws a value on links as lines coloured by value, with a palette that wraps around for an angle, and the sum of the values around each face, such as CellVisual('theta') for angles on the links of a grid. Values on faces are an image on a grid and coloured polygons on a network, and a grid of more than two dimensions shows one plane of it. It shows the angles of a gauge field, the flows of a road network, and the currents of a circuit.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
state str | None

The state to log, or None for the first state of the group.

None
plane tuple[int, int]

The two axes of a lattice complex to draw.

(0, 1)
section int

The site every other axis of a lattice complex is fixed at.

0
path str | None

The entity path of the group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Raises:

Type Description
ValidationError

The group lives on no edges or hyperedges of a cell complex, or the plane is not two axes of the lattice.

See Also

SiteVisual: Draws values on the sites of a triangular grid or a network.

Examples:

>>> from skcomplex.core.engine.viz import CellVisual
>>> CellVisual('theta', plane=(0, 2)).plane
(0, 2)
Source code in src/skcomplex/core/engine/viz/_cells.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(
    self,
    state: str | None = None,
    plane: tuple[int, int] = (0, 1),
    section: int = 0,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.state = state
    self.plane = plane
    self.section = section
    self.path = path
    self.recording = recording

ExpectationVisual(states=None, low=None, high=None, history=None, *, slices=None, moments=None, path=None, recording=None)

Bases: ImageVisual

A visual that draws the average measured values of an element of operators.

It draws the average of a measurement on every member of a quantum group, such as the spin z of each site, as an image of the grid, with one row per frame in one dimension, as in ExpectationVisual(low=-1.0, high=1.0). A particle on sites shows the chance of finding it at each site, and any other quantum element draws each average as a line over time. It shows the spins of a quantum magnet, a particle spreading on a chain, and the qubits of a circuit.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
states Sequence[str] | None

Unused, kept from ImageVisual.

None
low float | None

The value of the darkest color, or None for the smallest value of every frame.

None
high float | None

The value of the brightest color, or None for the largest value of every frame.

None
history int | None

The largest number of rows of the space-time image, or None for as many as sites, between 64 and 256.

None
See Also

ImageVisual: Draws the plain values of a grid as images.

Examples:

>>> from skcomplex.core.engine.viz import ExpectationVisual
>>> ExpectationVisual(low=-1.0, high=1.0)
ExpectationVisual(high=1.0, low=-1.0)
Source code in src/skcomplex/core/engine/viz/_images.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(
    self,
    states: Sequence[str] | None = None,
    low: float | None = None,
    high: float | None = None,
    history: int | None = None,
    *,
    slices: Mapping[str | int, int] | None = None,
    moments: Sequence[int] | None = None,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.states = states
    self.low = low
    self.high = high
    self.history = history
    self.slices = slices
    self.moments = moments
    self.path = path
    self.recording = recording

HistogramVisual(color_by=None, color_range=None, radius=None, *, bins=BINS, shown=('agents', 'mean', 'std'), histogram_first=False, path=None, recording=None)

Bases: AgentsVisual

A visual that draws histograms of the values of agents or of a group.

It takes one number per agent for every value, such as a fitness, the total of a genome, or the size of a vocabulary, and draws its histogram with the mean and spread over time, as in HistogramVisual(color_by='fitness'). Whole numbers, such as type labels, also show how many distinct values there are, and a group of at most ten agents shows each agent as a line of its own. The members of a group with no space are drawn the same way. It shows the fitness of a population, the wealth of traders, and the opinions of voters.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
color_by str | None

The trait whose histogram the first view shows, or None for the first trait of the agents.

None
color_range tuple[float, float] | None

The starting range of the histogram of the color_by trait, which still widens to every logged value, or None for a range widened to every logged value. The other traits always bin by their own range.

None
radius float | None

Not used, kept for the options of agents visuals.

None
bins int

The number of bins of the histograms.

BINS
shown Sequence[str]

The series of the colored trait that the first view shows, among 'agents', 'mean', 'std', and 'distinct'.

('agents', 'mean', 'std')
histogram_first bool

Whether the histogram view comes before the time series view of the colored trait, for traits whose distribution matters more than its statistics, such as clustered opinions.

False
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
spans_

The range of the histogram of every trait logged so far, by entity path.

See Also

AgentsVisual: Draws the agents themselves where they live. ScalarsVisual: Draws the values of an element as lines over time.

Examples:

>>> from skcomplex.core.engine.viz import HistogramVisual
>>> HistogramVisual(color_by='fitness').bins
20
Source code in src/skcomplex/core/engine/viz/_histograms.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    color_by: str | None = None,
    color_range: tuple[float, float] | None = None,
    radius: float | None = None,
    *,
    bins: int = BINS,
    shown: Sequence[str] = ('agents', 'mean', 'std'),
    histogram_first: bool = False,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    super().__init__(color_by=color_by, color_range=color_range, radius=radius, path=path, recording=recording)
    self.bins = bins
    self.shown = shown
    self.histogram_first = histogram_first

ImageVisual(states=None, low=None, high=None, history=None, *, slices=None, moments=None, path=None, recording=None)

Bases: BaseVisual

A visual that draws every value of a group on a grid as a coloured image.

It draws one pixel per site, with colours from low to high, such as ImageVisual(low=0, high=1) for a value between 0 and 1. A row of sites also builds an image with one row per frame, the oldest at the top, so the change over time reads from top to bottom. On a phase space it can show one plane through slices and the averages over the extra axes through moments. It shows the patterns of a chemical reaction, the spins of a magnet, and the heat spreading along a rod.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
states Sequence[str] | None

The states to log, or None for every state.

None
low float | None

The value of the darkest color, or None for the smallest value of every frame.

None
high float | None

The value of the brightest color, or None for the largest value of every frame.

None
history int | None

The largest number of rows of the space-time image of a one-dimensional lattice, 0 for no space-time image, or None for as many rows as the lattice has sites, between 64 and 256.

None
slices Mapping[str | int, int] | None

The index that every axis but two is fixed at, by the name of a class axis or the index of an axis, or None to log the whole state.

None
moments Sequence[int] | None

The orders of the moments over the class axes of a phase space to log, or None for none.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
rows_

The recent rows of the space-time image of every state, by entity path.

Raises:

Type Description
ValidationError

slices or moments are given for a group that is not on a phase space, or slices does not leave two axes.

See Also

SiteVisual: Draws values on the sites of a triangular grid or a network. MeshVisual: Draws values on the triangles of a mesh.

Examples:

>>> from skcomplex.core.engine.viz import ImageVisual
>>> ImageVisual(low=0, high=1)
ImageVisual(high=1, low=0)
Source code in src/skcomplex/core/engine/viz/_images.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(
    self,
    states: Sequence[str] | None = None,
    low: float | None = None,
    high: float | None = None,
    history: int | None = None,
    *,
    slices: Mapping[str | int, int] | None = None,
    moments: Sequence[int] | None = None,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.states = states
    self.low = low
    self.high = high
    self.history = history
    self.slices = slices
    self.moments = moments
    self.path = path
    self.recording = recording

LinearProgramVisual(variables=None, *, graph=None, seed=LAYOUT_SEED, path=None, recording=None)

Bases: BaseVisual

A visual that draws the solution of a linear program of an element.

It draws the solved variables as bars and the value of the objective over time, such as LinearProgramVisual(graph=False) for the bars alone. With a graph it also draws one node per constraint and per variable, in two colours, joined by lines as wide as the size of each variable. It shows the fluxes of a metabolic network, the shipments of a supply chain, and the flows of a power grid.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
variables Sequence[str] | None

The dotted names of the variables to draw, or None for every variable in declared order.

None
graph bool | None

Whether to log the graph, or None for a graph up to 100 variables.

None
seed int

The seed of the layout of the graph.

LAYOUT_SEED
path str | None

The entity path of the element to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
kernel_

The kernel of the linear program of the element.

names_

The dotted names of the variables the visual draws.

positions_

The position of every node of the graph, by its name, or nothing without a graph.

See Also

MatrixVisual: Draws a matrix value as an image.

Examples:

>>> from skcomplex.core.engine.viz import LinearProgramVisual
>>> LinearProgramVisual(graph=False)
LinearProgramVisual(graph=False)
Source code in src/skcomplex/core/engine/viz/_linear_programs.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def __init__(
    self,
    variables: Sequence[str] | None = None,
    *,
    graph: bool | None = None,
    seed: int = LAYOUT_SEED,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.variables = variables
    self.graph = graph
    self.seed = seed
    self.path = path
    self.recording = recording

MatrixVisual(variable='W', *, color_range=None, path=None, recording=None)

Bases: BaseVisual

A visual that draws a matrix value of an element as an image coloured by value.

It draws one image per frame with one pixel per entry of the matrix, such as the trained weights A of a network in MatrixVisual('A', path='net/recurrence'). The colours span color_range when it is given and the values of each frame otherwise. It shows the weights of a neural network as it learns, the trade between the sectors of an economy, and the couplings between the species of an ecosystem.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
variable str

The name of the matrix-valued state or parameter.

'W'
color_range tuple[float, float] | None

The values of the darkest and the brightest color, or None for the range of every frame.

None
path str | None

The entity path of the element, or the path the name of the variable starts with.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
name_ str

The dotted name of the variable in the problem.

shape_ tuple[int, ...]

The shape of the matrix.

Raises:

Type Description
ValidationError

The variable is not a name, or the problem has no matrix of that name.

See Also

ImageVisual: Draws the values of a grid as images.

Examples:

>>> from skcomplex.core.engine.viz import MatrixVisual
>>> from skcomplex.systems.computer_science.neural_networks import ElmanNetworkSystem
>>> problem = ElmanNetworkSystem(n_bits=30).prepare().simulate(until=0).problem
>>> MatrixVisual('A', path='net/recurrence').prepare(problem).name_
'net/recurrence.A'
Source code in src/skcomplex/core/engine/viz/_matrices.py
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    variable: str = 'W',
    *,
    color_range: tuple[float, float] | None = None,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    super().__init__(path=path, recording=recording)
    self.variable = variable
    self.color_range = color_range

MeshVisual(states=None, low=None, high=None, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws every value of a field on a mesh as coloured triangles.

It colours the triangles of a mesh by value and raises each node to its value, so the field reads as a surface, such as MeshVisual(low=0.0) for a value that never falls below zero. A mesh of tetrahedra is drawn as coloured points. It shows the heat in a machine part, the stress in a beam, and the pressure of air around a wing.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
states Sequence[str] | None

The states to log, or None for every state.

None
low float | None

The value of the darkest color, or None for the smallest value of every frame.

None
high float | None

The value of the brightest color, or None for the largest value of every frame.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None
See Also

ImageVisual: Draws the values of a regular grid as images.

Examples:

>>> from skcomplex.core.engine.viz import MeshVisual
>>> MeshVisual(low=0.0)
MeshVisual(low=0.0)
Source code in src/skcomplex/core/engine/viz/_meshes.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def __init__(
    self,
    states: Sequence[str] | None = None,
    low: float | None = None,
    high: float | None = None,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.states = states
    self.low = low
    self.high = high
    self.path = path
    self.recording = recording

PhaseRingVisual(phase, position=None, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws the phases of a group of oscillators against their position.

It draws every oscillator as a point at its position and its phase wrapped into (-pi, pi], coloured by a palette that wraps around, such as PhaseRingVisual('theta'). Oscillators in step show as a flat run of one colour, and oscillators out of step as scattered points. The other values are drawn as lines over time. It shows fireflies flashing together, the generators of a power grid, and the neurons of a ring firing in waves.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
phase str

The name of the state that holds the phase of every member.

required
position str | None

The name of a scalar state or of the first coordinate of a vector state that holds the position of every member, or None for the member index.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None
See Also

PointsVisual: Draws a group at its positions in space.

Examples:

>>> from skcomplex.core.engine.viz import PhaseRingVisual
>>> PhaseRingVisual('theta').phase
'theta'
Source code in src/skcomplex/core/engine/viz/_rings.py
53
54
55
56
57
58
59
60
61
62
63
64
def __init__(
    self,
    phase: str,
    position: str | None = None,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.phase = phase
    self.position = position
    self.path = path
    self.recording = recording

PointsVisual(position, radius=None, color_by=None, color_range=None, states=None, *, trail=TRAIL_LENGTH, strip=False, path=None, recording=None)

Bases: BaseVisual

A visual that draws a position value as points and other values as lines.

It draws one point per member at its position, coloured by another value, such as PointsVisual(position='x', color_by='v') for particles coloured by speed. Points in a plane are drawn with the vertical axis up, and without a radius they take a share of the area the positions cover, smaller for larger groups. A group of at most ten points also draws the trail of its recent positions, and strip joins the points in member order. It shows the atoms of a gas, the birds of a flock, and the masses of a chain of springs.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
position str

The name of the vector state that holds the position.

required
radius float | None

The radius of the points, or None for a share of the extent of the positions.

None
color_by str | None

The name of a scalar state, or of a vector state whose norm, colors the points, or None for one color.

None
color_range tuple[float, float] | None

The values at the two ends of the color scale, or None for a range widened to every logged value.

None
states Sequence[str] | None

The names of the other states to log as time series, or None for all of them.

None
trail int

The number of recent positions the trail of each point holds, or 0 for no trail.

TRAIL_LENGTH
strip bool

Whether to join the points in member order by one line strip.

False
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
history_

The recent positions of the points, the oldest first.

bounds_

The lowest and highest coordinates of the positions logged so far, or None.

span_

The range of the colored values logged so far, or None.

See Also

BodiesVisual: Draws bodies whose positions follow from several values. AgentsVisual: Draws agents at their cells, positions, or nodes.

Examples:

>>> from skcomplex.core.engine.viz import PointsVisual
>>> PointsVisual(position='x', color_by='v').color_by
'v'
Source code in src/skcomplex/core/engine/viz/_points.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def __init__(
    self,
    position: str,
    radius: float | None = None,
    color_by: str | None = None,
    color_range: tuple[float, float] | None = None,
    states: Sequence[str] | None = None,
    *,
    trail: int = TRAIL_LENGTH,
    strip: bool = False,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.position = position
    self.radius = radius
    self.color_by = color_by
    self.color_range = color_range
    self.states = states
    self.trail = trail
    self.strip = strip
    self.path = path
    self.recording = recording

RerunObserver(application_id='skcomplex', *, spawn=False, connect=False, save_path=None, interval=1, blueprint=None, primary=None, parameters=False, visuals=None)

Bases: BaseObserver

An observer that logs the frames of a run to the Rerun viewer.

It draws every element of a system with the visual its class names, in the Rerun viewer or in a .rrd file, such as system.simulate(until=10.0, observers=[RerunObserver(save_path='run.rrd')]). prepare(problem) builds the visuals and lays out their views, run(frame) draws one frame, and run(final=True) writes out what is left. Each frame also draws the parameters and the renewals of renewal laws, on timelines of the simulated time and the step. The default layout puts the pictures of space first, side by side, and the lines over time below them. A subclass draws more with _log_extra. It replays a predator and prey cycle, the spread of an epidemic on a network, and the patterns of a chemical reaction.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
application_id str

The Rerun application id.

'skcomplex'
spawn bool

Whether to spawn the Rerun viewer installed with the running interpreter, or the one on PATH.

False
connect bool

Whether to connect to a running Rerun viewer.

False
save_path str | Path | None

The path of a .rrd file to save the recording to.

None
interval int

The number of frames between logged frames.

1
blueprint Literal['default'] | Blueprint | None

The layout of the viewer: None to let the viewer choose it, 'default' for the default blueprint built from the views of the visuals, or a Rerun blueprint. It is sent with the recording, and written next to a saved recording as a .rbl file with the same stem.

None
primary str | None

The name or the origin of the view to put first in the default blueprint, with its row, or None for the first spatial view, or the first time series view without one.

None
parameters bool

Whether the default blueprint has a time series view of the parameters.

False
visuals Mapping[str, VisualSpec] | None

How to draw elements by path, such as {'oscillators': VisualSpec('phase_ring', {'phase': 'theta'})}, in place of the drawing each element has by default, or None to keep every default.

None

Attributes:

Name Type Description
recording_

The Rerun recording stream.

visuals_

The prepared visuals of the elements and the agent groups, in the order they are logged.

views_

The views of the visuals, the observables, and the reporters, in the order of the default blueprint, so the first one is the primary view that shows the signature behaviour of the system.

blueprint_

The blueprint sent with the recording, or None.

logged_frames_

The number of frames logged.

See Also

BaseVisual: Draws one element at every frame.

Examples:

>>> from skcomplex.core.engine.viz import RerunObserver
>>> from skcomplex.systems.biology.ecology import LotkaVolterraSystem
>>> observer = RerunObserver(interval=10)
>>> _ = LotkaVolterraSystem().prepare().simulate(until=1.0, dt=0.1, observers=[observer])
>>> observer.logged_frames_
2
Source code in src/skcomplex/core/engine/viz/_rerun.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def __init__(
    self,
    application_id: str = 'skcomplex',
    *,
    spawn: bool = False,
    connect: bool = False,
    save_path: str | Path | None = None,
    interval: int = 1,
    blueprint: Literal['default'] | rrb.Blueprint | None = None,
    primary: str | None = None,
    parameters: bool = False,
    visuals: Mapping[str, VisualSpec] | None = None,
) -> None:
    self.application_id = application_id
    self.spawn = spawn
    self.connect = connect
    self.save_path = save_path
    self.interval = interval
    self.blueprint = blueprint
    self.primary = primary
    self.parameters = parameters
    self.visuals = visuals

ScalarsVisual(components=None, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws every value of an element as a line over time.

It draws one line per value, or per entry of a vector value, each with a colour of its own, such as the prey of a predator and prey system in ScalarsVisual(path='prey'). The past values that a delayed value keeps are left out. It shows the populations of an ecosystem, the concentrations of a reaction, and the price of a market.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
components Sequence[int] | None

The indices of the components of vector states to log, or None for every component.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
styled_

The entity paths whose series colors are logged.

See Also

HistogramVisual: Draws the spread of the values of a group as histograms. ImageVisual: Draws the values of a grid as images.

Examples:

>>> from skcomplex.core.engine.viz import ScalarsVisual
>>> ScalarsVisual(path='prey')
ScalarsVisual(path='prey')
Source code in src/skcomplex/core/engine/viz/_scalars.py
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    components: Sequence[int] | None = None,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.components = components
    self.path = path
    self.recording = recording

SiteVisual(states=None, low=None, high=None, *, path=None, recording=None)

Bases: BaseVisual

A visual that draws the values of a group on a triangular grid or a network.

It colours each site by value, from low to high, such as SiteVisual(low=0, high=2) for three states of a cell. A triangular grid draws a hexagon around each site, and a network draws its nodes at their pos attributes or a fixed spring layout, with its edges drawn once. A network whose links change draws the nodes and edges present at each frame. It shows the infected people of a contact network, the cells of a hexagonal automaton, and the opinions of a growing social network.

Read more in the user guide, under Observe.

Parameters:

Name Type Description Default
states Sequence[str] | None

The states to log, or None for every state.

None
low float | None

The value of the darkest color, or None for the smallest value of every frame.

None
high float | None

The value of the brightest color, or None for the largest value of every frame.

None
path str | None

The entity path of the element or agent group to draw, which also names it in the problem.

None
recording RecordingStream | None

The Rerun recording to log to, or None for the active recording of the thread.

None

Attributes:

Name Type Description
edges_

The entity paths whose static edges are logged.

changing_

The hash of the latest logged edges of every changing network, by entity path.

See Also

ImageVisual: Draws the values of a square grid as images. AgentsVisual: Draws agents at the nodes they occupy.

Examples:

>>> from skcomplex.core.engine.viz import SiteVisual
>>> SiteVisual(low=0, high=2)
SiteVisual(high=2, low=0)
Source code in src/skcomplex/core/engine/viz/_sites.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def __init__(
    self,
    states: Sequence[str] | None = None,
    low: float | None = None,
    high: float | None = None,
    *,
    path: str | None = None,
    recording: rr.RecordingStream | None = None,
) -> None:
    self.states = states
    self.low = low
    self.high = high
    self.path = path
    self.recording = recording