graphix.visualization module

Functions to visualize graph-based objects: open graphs, flows and XZ-corrections.

class Colored(value: _T, color: Color)[source]

Bases: Generic[_T]

A generic container pairing a value with a color for visualization.

Parameters:
  • value (_T) – The value to be colored. Can be any type.

  • color (Color) – The color to associate with the value, used during visualization.

value: _T
color: Color
__init__(value: _T, color: Color) → None
class PlotLims(xmin: float, xmax: float, ymin: float, ymax: float)[source]

Bases: object

Dataclass to wrap the plot limits in axis coordinates.

xmin: float
xmax: float
ymin: float
ymax: float
__init__(xmin: float, xmax: float, ymin: float, ymax: float) → None
class DrawKwargs[source]

Bases: TypedDict

Common keyword arguments for graph visualization methods.

The keys correspond to the fields of VisualizationOptions.

pauli_measurements: bool
measurement_labels: bool
local_clifford: bool
node_labels: bool | Mapping[int, str]
node_distance: tuple[float, float]
legend: bool
figsize: tuple[int, int] | None
filename: Path | None
class VisualizationOptions(pauli_measurements: bool = True, measurement_labels: bool = False, local_clifford: bool = False, node_labels: bool | Mapping[int, str] = True, node_distance: tuple[float, float] = (1, 1), legend: bool = True, figsize: tuple[int, int] | None = None, filename: Path | None = None)[source]

Bases: object

Options controlling graph visualization.

Parameters:
  • pauli_measurements (bool, default=True) – If True, Pauli-measured nodes are highlighted with distinct coloring.

  • measurement_labels (bool, default=False) – If True, measurement labels (planes and axis) are displayed in the visualization.

  • local_clifford (bool, default=False) – If True, Clifford operations are displayed in the visualization.

  • node_labels (bool | Mapping[int, str], default=True) – If True, display numeric node labels. If a mapping, use custom labels for nodes specified in the mapping.

  • node_distance (tuple[float, float], default=(1, 1)) – Scaling factors (x_scale, y_scale) applied to node positions.

  • legend (bool, default=True) – If True, legend is shown.

  • figsize (tuple[int, int] | None, default=None) – Figure dimensions (width, height) in inches. If None, dimensions are determined automatically based on graph structure.

  • filename (Path | None, default=None) – File path to save the visualization. If None, figure is displayed but not saved.

pauli_measurements: bool = True
measurement_labels: bool = False
local_clifford: bool = False
node_labels: bool | Mapping[int, str] = True
node_distance: tuple[float, float] = (1, 1)
legend: bool = True
figsize: tuple[int, int] | None = None
filename: Path | None = None
__init__(pauli_measurements: bool = True, measurement_labels: bool = False, local_clifford: bool = False, node_labels: bool | Mapping[int, str] = True, node_distance: tuple[float, float] = (1, 1), legend: bool = True, figsize: tuple[int, int] | None = None, filename: Path | None = None) → None
class GraphVisualizer(og: OpenGraph[AbstractMeasurement], pos: Mapping[int, _Point], edge_paths: Mapping[_Edge, _Path], arrow_paths: Mapping[_Edge, Colored[_Path]] | None = None, n_layers: int | None = None, options: VisualizationOptions = <factory>, _source: _Source | None = None)[source]

Bases: object

Visualizer for flows and XZ-correction structures.

og

The open graph of the object being rendered.

Type:

OpenGraph[AbstractMeasurement]

pos

Mapping of node identifiers to (x, y) coordinates.

Type:

Mapping[int, _Point]

edge_paths

Bezier curve paths for graph edges.

Type:

Mapping[_Edge, _Path]

arrow_paths

Colored bezier curve paths for correction dependency arrows.

Type:

Mapping[_Edge, Colored[_Path]]

n_layers

Number of measurement layers in the partial order (determines horizontal extent).

Type:

int

options

Options controlling graph visualization.

Type:

VisualizationOptions, default=VisualizationOptions()

_source

Internal metadata indicating the source of the graph (e.g., OpenGraph, PauliFlow or XZCorrections).

Type:

_Source | None, default=None

Notes

Instantiate this class via factory methods rather than direct construction: - from_opengraph() : Create from OpenGraph instance. - from_flow() : Create from PauliFlow instance. - from_xzcorrections() : Create from XZCorrections instance.

Call visualize() to generate and display the graph visualization.

og: OpenGraph[AbstractMeasurement]
pos: Mapping[int, _Point]
edge_paths: Mapping[_Edge, _Path]
arrow_paths: Mapping[_Edge, Colored[_Path]] | None = None
n_layers: int | None = None
options: VisualizationOptions
static from_opengraph(og: OpenGraph[AbstractMeasurement], **kwargs: Unpack[DrawKwargs]) → GraphVisualizer[source]

Create a GraphVisualizer from an OpenGraph instance.

Parameters:
Return type:

GraphVisualizer

static from_flow(flow: PauliFlow[AbstractMeasurement], **kwargs: Unpack[DrawKwargs]) → GraphVisualizer[source]

Create a GraphVisualizer from a PauliFlow instance.

Parameters:
Return type:

GraphVisualizer

static from_xzcorrections(xz_corr: XZCorrections[AbstractMeasurement], **kwargs: Unpack[DrawKwargs]) → GraphVisualizer[source]

Create a GraphVisualizer from an XZCorrections instance.

Parameters:
Return type:

GraphVisualizer

visualize() → None[source]

Generate and display the complete graph visualization.

The figure is displayed via plt.show() or saved when self.options.filename has a non-null value.

__init__(og: OpenGraph[AbstractMeasurement], pos: Mapping[int, _Point], edge_paths: Mapping[_Edge, _Path], arrow_paths: Mapping[_Edge, Colored[_Path]] | None = None, n_layers: int | None = None, options: VisualizationOptions = <factory>, _source: _Source | None = None) → None