qecx.QECXViewer

class qecx.QECXViewer(qecx_file, config=None)

Bases: object

Display surface for a QECXFile (terminal summaries, Jupyter HTML, …).

Parameters:
  • qecx_file (QECXFile) – The loaded document this viewer renders.

  • config (ViewerConfig | None) – Render configuration. When None (default), a fresh copy of DEFAULT_VIEWER_CONFIG is taken at construction time so post-construction mutations to the singleton do not affect this instance.

summary(file=None)

Print a structured overview of the document to a text stream.

Uses rich for formatting if the library is importable, otherwise falls back to plain text.

Parameters:

file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

show_code(file=None)

Display the code section in detail.

Renders every populated matrix field (H_X, H_Z, stabilizer_generators, gauge_generators, gauge_X, gauge_Z) and the logical operators.

Parameters:

file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

show_matrix(field_name, file=None)

Display a single binary matrix field from the code section.

Parameters:
  • field_name (str) – Name of the field to display (e.g. "H_X", "H_Z", "gauge_X"). If the field is absent from the document, a short “not found” message is printed instead.

  • file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

show_variant(component, variant_name, draw_circuit=True, circuit_scale=None, circuit_fold=None, file=None, *, outer_key=None, **overrides)

Display a specific operation variant with QASM and optional circuit diagram.

Parameters:
  • component (str) – Operation name (e.g. "syndrome_measurement").

  • variant_name (str) – Variant name within the operation (e.g. "sequential").

  • draw_circuit (bool) – If True and Qiskit is available, also render an ASCII circuit diagram below the QASM source.

  • circuit_scale (float | None) – Scale factor for matplotlib circuit rendering; None (default) falls back to cfg.circuit_scale.

  • circuit_fold (int | None) – Number of layers before folding in text output; None (default) falls back to cfg.circuit_fold (-1 disables folding).

  • file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

  • outer_key (str | None) – Key addressing the variant’s declaration within the operation: a prepared or reset state, a measurement basis, a gate name, or an observable. When omitted and the operation declares exactly one such key, that key is used; flat operations take no key. Addressing failures and absent variants print a diagnostic and return, leaving the display path free of exceptions.

  • **overrides (Any) – Per-call ViewerConfig field overrides.

show_gate(gate_name, draw_circuit=True, circuit_scale=None, circuit_fold=None, file=None, **overrides)

Display a logical gate’s operand groups and variants.

For each operand group of the gate, prints the operand description and the QASM of every variant; when draw_circuit is True and Qiskit is available, an ASCII circuit diagram is appended to each variant.

Parameters:
  • gate_name (str) – Gate name as it appears under operations.logical_gates (e.g. "cx", "h").

  • draw_circuit (bool) – If True and Qiskit is available, render an ASCII circuit diagram for each variant’s QASM.

  • circuit_scale (float | None) – Scale factor for matplotlib circuit rendering; None (default) falls back to cfg.circuit_scale.

  • circuit_fold (int | None) – Number of layers before folding in text output; None (default) falls back to cfg.circuit_fold (-1 disables folding).

  • file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

  • **overrides (Any) – Per-call ViewerConfig field overrides.

show_decoder_config(file=None, **overrides)

Display the decoder_config section in detail.

Lists each declared decoder slug with its global parameters and its per-detector tags, resolving every parametric reference to the value it addresses for display.

Parameters:
  • file (Any) – Writable text stream to print to. None (default) uses sys.stdout.

  • **overrides (Any) – Per-call ViewerConfig field overrides.

get_circuit(component, variant_name, *, outer_key=None)

Parse a variant’s QASM and return a Qiskit QuantumCircuit.

Parameters:
  • component (str) – Operation name (e.g. "syndrome_measurement").

  • variant_name (str) – Variant name within the operation (e.g. "sequential").

  • outer_key (str | None) – Key addressing the variant’s declaration within the operation: a prepared or reset state, a measurement basis, a gate name, or an observable. When omitted and the operation declares exactly one such key, that key is used; flat operations take no key.

Returns:

The parsed circuit for the selected

variant’s inline QASM fragment.

Return type:

qiskit.circuit.QuantumCircuit

Raises:
  • ValueError – If the file does not declare component.

  • ValueError – If outer_key names no declaration, is omitted for an operation declaring more than one, or is passed to an operation that takes none.

  • ValueError – If the variant name is declared in more than one operand group of the addressed gate or observable, which needs a group-precise accessor.

  • ValueError – If the variant cannot be resolved or carries no inline QASM string.

  • ImportError – If the OpenQASM 3 importer is not installed.

get_gate_circuit(gate_name, variant_name, group_index=0)

Parse a logical gate variant’s QASM and return a Qiskit QuantumCircuit.

Parameters:
  • gate_name (str) – Gate name as it appears under operations.logical_gates (e.g. "cx", "h").

  • variant_name (str) – Variant name within the gate’s operand group (e.g. "transversal").

  • group_index (int) – Index of the operand group to select, counted from the front of the gate’s declared groups. Only relevant when the gate has more than one operand group; defaults to 0.

Returns:

The parsed circuit for the selected

gate variant’s inline QASM fragment.

Return type:

qiskit.circuit.QuantumCircuit

Raises:
  • ValueError – If the gate, operand group, or variant cannot be resolved, or if the variant carries no inline QASM string.

  • ImportError – If the OpenQASM 3 importer is not installed.

draw_layout(*, ax=None, show_vertex_indices=False, show_qubit_indices=None, show_face_indices=False, color_map=None, default_face_color='#BBBBBB', face_alpha=0.3, figsize=None, title=None, **overrides)

Draw the cell complex: colored face polygons, edges, and qubit placement.

Parameters:
  • ax (matplotlib.axes.Axes | None) – Existing matplotlib Axes to draw on. If None (default), a new Figure and Axes are created.

  • show_vertex_indices (bool) – Annotate each graph vertex with its index.

  • show_qubit_indices (bool | None) – Annotate each qubit dot with its register index. None (default) consults cfg.qubit_indices; if that is also None, the auto branch enables annotation for layouts with no more than cfg.qubit_indices_max_n data qubits. Pass True or False to override both.

  • show_face_indices (bool) – Annotate each face centroid with its face index.

  • color_map (dict[int, str] | None) – Override the default face colors. Keys are color integers; values are matplotlib color strings. Defaults to Paul Tol “bright”.

  • default_face_color (str) – Color for faces that have no color field (default grey).

  • face_alpha (float) – Opacity of the face fill polygons (0–1).

  • figsize (tuple[int | float, int | float] | None) – (width, height) in inches for a newly created figure. None (default) falls back to cfg.layout_figsize; if that is also None, an adaptive figsize is computed from vertex coordinates.

  • title (str | None) – Plot title. Defaults to the code name.

  • **overrides (Any) – Per-call ViewerConfig field overrides.

Returns:

(fig, ax), the matplotlib Figure and Axes. plt.show() is not called.

Return type:

tuple

Raises:

ValueError – If the file has no qubit_layout, no cell_complex, or an explicitly non-2D embedding.