Skip to main content

class Diagram

Wrapper for SVG diagram with Jupyter notebook display support.

class GateLabel

Label for a gate in the SVG diagram.

parse_stim_circuit

Parse a stim circuit into a GraphRepresentation. Parameters:
  • stim_circuit (stim.Circuit) — The stim circuit to convert.
  • track_classical_wires (bool) — Whether to track classical wires.
Returns:
  • GraphRepresentation — A GraphRepresentation containing the ZX graph and all auxiliary data.

placeholders_to_t

Replace I_ERROR placeholder gates in an SVG diagram with actual gate names. Supported gates are T, T†, R_Z, R_X, R_Y, U_3. Parameters:
  • svg_string (str) — The SVG string from stim’s diagram() method containing I_ERROR placeholder gates whose p-value are used as identifiers.
  • placeholder_id_to_labels (dict[float, GateLabel]) — Mapping from identifier (float), i.e. the p values of I_ERROR gates, to GateLabel.
Returns:
  • str — Modified SVG string with I_ERROR gates replaced by the actual gate names.

render_pyzx_d3

Render a stim circuit as a pyzx ZX diagram using d3.js. Parameters:
  • stim_circ (stim.Circuit) — The stim circuit to render.
  • kwargs (dict[str, Any]) — Additional keyword arguments passed to the underlying diagram renderer.
Returns:
  • GraphS — A pyzx ZX diagram.

render_svg

Render a stim circuit timeline/timeslice diagram with custom labels.

scale_horizontally

Scale horizontal positions of graph vertices by a factor of scale. Parameters:
  • g (BaseGraph) — A ZX graph
  • scale (float) — The factor to scale the graph by

tagged_gates_to_placeholder

Replace tagged gates with I_ERROR placeholder gates for rendering. Converts S[T], S_DAG[T], I[R_X(…)], I[R_Y(…)], I[R_Z(…)], I[U3(…)] to I_ERROR placeholder gates whose p-values are used as identifiers. Parameters:
  • circuit (stim.Circuit) — The stim circuit to replace tagged gates with I_ERROR placeholder gates.
Returns:
  • stim.Circuit — A tuple containing the modified circuit and a dictionary mapping the p-values
  • dict[float, GateLabel] — of the I_ERROR placeholder gates to the actual gate names.

wrap_svg

Wrap an SVG string in a container div. Parameters:
  • svg (str) — Raw SVG markup.
  • width (float | None) — Width of the container in pixels.
  • height (float | None) — Height of the container in pixels (unused, kept for API symmetry with :func:wrap_svg_zoomable).

wrap_svg_zoomable

Wrap an SVG in a zoomable, scrollable container. The container has the given pixel dimensions. When width is None the container fills the available width. Users can pan by scrolling and zoom with pinch-zoom (trackpad) or Ctrl/Cmd + wheel. Zoom is anchored at the cursor position. Parameters:
  • svg (str) — Raw SVG markup.
  • width (float | None) — Pixel width of the container, or None for full width.
  • height (float) — Pixel height of the container.