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 produce quick training curves directly in the notebook without needing a separate plotting library.
import simplegrad as sg
x = sg.Tensor([1.0, 2.0], requires_grad=True)
y = (x * x).sum()
sg.graph(y) # renders the computation graph inline
losses = [0.9, 0.7, 0.5, 0.3]
sg.plot(losses, title="Training loss")
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.Digraphobject. 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
RecordInfodata 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
RecordInfodata 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.