Skip to content

Inline Visualization

Simplegrad includes inline visualisation utilities for Jupyter notebooks. graph renders the full computation graph of a tensor using Graphviz, showing each operation as a node and the data-flow edges between them. plot and scatter draw training-metric line and scatter charts from a tracker's results (rendered with matplotlib).

import simplegrad as sg
from simplegrad.track import Tracker

# Computation graph of a tensor
x = sg.Tensor([1.0, 2.0], comp_grad=True)
y = sg.sum(x * x)
sg.vis.graph(y)                # renders the computation graph inline

# Training curves from a tracked run
tracker = Tracker("./experiments")
tracker.set_experiment("demo")
run_id = tracker.start_run(name="run-1")
for step in range(20):
    tracker.record("loss", 1.0 / (step + 1), step=step)
tracker.end_run()

sg.vis.plot(tracker.get_results(run_id))   # one line chart per metric

Computation Graph

graph(tensor: Tensor, path: str | None = None) -> graphviz.Digraph

Render the computation graph of a tensor as an SVG diagram.

Functions decorated with @compound_op are enclosed in a labelled black-border rectangle. The internal intermediate tensors and the final operation node of the compound op are inside the rectangle; the output tensor node itself sits outside, connecting to the cluster via an edge.

Node colors
  • Green (#34b87e): leaf tensors (inputs / parameters)
  • Yellow (#feba14): intermediate tensors
  • Light grey (#e8e8e8): operation nodes

Parameters:

  • tensor (Tensor) –

    The output tensor whose computation graph to visualize.

  • path (str | None, default: None ) –

    If provided, save the SVG to this file path (without extension).

Returns:

  • Digraph –

    A graphviz.Digraph object. Displays inline in Jupyter notebooks.


Training Plots

plot(results: dict[str, list[RecordInfo]], selected: list[str] | None = None, num_cols: int = 2, cell_w: int = 8, cell_h: int = 5, path: Path | None = None, color: str | None = None)

Plot training metrics as line charts.

Parameters:

  • results (dict[str, list[RecordInfo]]) –

    Mapping of metric name to list of RecordInfo data points.

  • selected (list[str] | None, default: None ) –

    Subset of metric names to plot. Plots all if None.

  • num_cols (int, default: 2 ) –

    Number of subplot columns. Defaults to 2.

  • cell_w (int, default: 8 ) –

    Width of each subplot cell in inches. Defaults to 8.

  • cell_h (int, default: 5 ) –

    Height of each subplot cell in inches. Defaults to 5.

  • path (Path | None, default: None ) –

    If provided, save the figure to this path.

  • color (str | None, default: None ) –

    Fixed color for all lines. Random if None.

scatter(results: dict[str, list[RecordInfo]], selected: list[str] | None = None, num_cols: int = 2, cell_w: int = 8, cell_h: int = 5, path: Path | None = None, color: str | None = None)

Plot training metrics as scatter charts.

Parameters:

  • results (dict[str, list[RecordInfo]]) –

    Mapping of metric name to list of RecordInfo data points.

  • selected (list[str] | None, default: None ) –

    Subset of metric names to plot. Plots all if None.

  • num_cols (int, default: 2 ) –

    Number of subplot columns. Defaults to 2.

  • cell_w (int, default: 8 ) –

    Width of each subplot cell in inches. Defaults to 8.

  • cell_h (int, default: 5 ) –

    Height of each subplot cell in inches. Defaults to 5.

  • path (Path | None, default: None ) –

    If provided, save the figure to this path.

  • color (str | None, default: None ) –

    Fixed color for all points. Random if None.