qecx.QECXViewer¶
- class qecx.QECXViewer(qecx_file, config=None)¶
Bases:
objectDisplay 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 ofDEFAULT_VIEWER_CONFIGis 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
richfor formatting if the library is importable, otherwise falls back to plain text.- Parameters:
file (Any) – Writable text stream to print to.
None(default) usessys.stdout.
- show_code(file=None)¶
Display the
codesection 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) usessys.stdout.
- show_matrix(field_name, file=None)¶
Display a single binary matrix field from the
codesection.- 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) usessys.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
Trueand 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 tocfg.circuit_scale.circuit_fold (int | None) – Number of layers before folding in text output;
None(default) falls back tocfg.circuit_fold(-1disables folding).file (Any) – Writable text stream to print to.
None(default) usessys.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
ViewerConfigfield 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_circuitisTrueand 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
Trueand 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 tocfg.circuit_scale.circuit_fold (int | None) – Number of layers before folding in text output;
None(default) falls back tocfg.circuit_fold(-1disables folding).file (Any) – Writable text stream to print to.
None(default) usessys.stdout.**overrides (Any) – Per-call
ViewerConfigfield overrides.
- show_decoder_config(file=None, **overrides)¶
Display the
decoder_configsection in detail.Lists each declared decoder slug with its global
parametersand 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) usessys.stdout.**overrides (Any) – Per-call
ViewerConfigfield 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_keynames 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
Axesto draw on. IfNone(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) consultscfg.qubit_indices; if that is alsoNone, the auto branch enables annotation for layouts with no more thancfg.qubit_indices_max_ndata qubits. PassTrueorFalseto 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
colorfield (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 tocfg.layout_figsize; if that is alsoNone, an adaptive figsize is computed from vertex coordinates.**overrides (Any) – Per-call
ViewerConfigfield overrides.
- Returns:
(fig, ax), the matplotlib Figure and Axes.plt.show()is not called.- Return type:
- Raises:
ValueError – If the file has no
qubit_layout, nocell_complex, or an explicitly non-2D embedding.