plot_registry¶

Custom plot registry for the ARIEL dashboard.

This module is intentionally standalone so that custom plot files can from ariel.visualisation.dashboard.plot_registry import custom_registry without pulling in the full dashboard (and avoiding circular imports).

Module Contents¶

Classes¶

CustomPlotEntry

Metadata for a single registered custom plot.

CustomPlotRegistry

Registry for user-defined dashboard plots.

Attributes¶

class CustomPlotEntry¶

Metadata for a single registered custom plot.

name: str¶
columns: list[str]¶
callback: Callable¶
description: str = ''¶
mode: str = 'per_generation'¶
y_label: str = ''¶
class CustomPlotRegistry¶

Registry for user-defined dashboard plots.

Example — per-generation mode (returns scalar metrics, auto-plotted):

from ariel.visualisation.dashboard.plot_registry import custom_registry

@custom_registry.register(
    name="Selection Pressure",
    columns=["fitness_", "n_offspring"],
    y_label="Pressure",
)
def selection_pressure(generation, data):
    return {"pressure": float(np.mean(data["n_offspring"])
                              / (np.mean(data["fitness_"]) + 1e-9))}

Example — full-figure mode (returns a go.Figure):

@custom_registry.register(
    name="My Plot",
    columns=["fitness_"],
    mode="full_figure",
)
def my_plot(generations, per_gen_data):
    import plotly.graph_objects as go
    fig = go.Figure()
    means = [float(np.mean(d["fitness_"])) for d in per_gen_data]
    fig.add_trace(go.Scatter(x=list(generations), y=means))
    return fig
register(*, name: str, columns: list[str], description: str = '', mode: str = 'per_generation', y_label: str = '') Callable¶

Decorator that registers a custom plot function.

Parameters:
  • name – Display name shown in the sidebar button and page title.

  • columns – Column names from the individual table that the callback needs (e.g. ["fitness_", "genotype_"]). time_of_birth and time_of_death are always fetched automatically — no need to list them.

  • description – Optional subtitle shown on the page.

  • mode –

    "per_generation" — callback signature:

    def fn(generation: int, data: dict[str, np.ndarray]) -> dict[str, float]
    

    "full_figure" — callback signature:

    def fn(generations: np.ndarray,
           per_gen_data: list[dict[str, np.ndarray]]) -> go.Figure
    

  • y_label – Y-axis label (only used in per_generation mode).

property entries: dict[str, CustomPlotEntry]¶
static query_columns(path: str, columns: list[str], sentinel: int) tuple[numpy.ndarray, numpy.ndarray, dict[str, numpy.ndarray]]¶

Fetch requested columns plus birth/death from the DB.

Returns (births, deaths, col_arrays) where col_arrays maps each requested column name to a NumPy array.

compute_custom(entry: CustomPlotEntry, path: str, min_gen: int, max_gen: int) dict¶

Run a custom plot’s callback against the DB data.

For per_generation mode returns::

{“generations”: np.ndarray, “<metric>”: np.ndarray, …}

For full_figure mode returns::

{“figure”: go.Figure}

custom_registry¶