qecx.QECXFile

class qecx.QECXFile(data, *, source='')

Bases: object

Loaded QECX file with structured property access.

Holds the resolved document dict and an optional source label. Display methods live on QECXViewer; obtain one via view().

Equality compares the underlying _data dict; source is excluded so two files loaded from different paths but with identical content are equal. The amend-after-import idiom: data = qf.to_dict(); ...mutate...; qf2 = QECXFile(data=data, source=qf.source); qf2.validate().

Parameters:
  • data (dict) – The fully-resolved QECX data dictionary.

  • source (str) – Display name for the source file (e.g. filename).

Variables:

source (str) – Display name for the source file (e.g. filename).

to_dict()

Return a deep copy of the underlying data dictionary.

Use this for amend-after-import: mutate the returned dict freely and pass it back into QECXFile(data=...) to construct an independent file.

validate()

Validate this file’s data against schema and semantic rules.

Findings are computed once and memoised; subsequent calls return them without re-running validation. The cache reflects the document as it stood at first validation: mutating the underlying data through the section-property references is unsupported and can leave the cache stale, while the amend-after-import idiom constructs a new QECXFile that starts unvalidated.

Returns:

All findings (warnings and errors), as a fresh list per call. An empty list means the document is valid.

Return type:

list[ValidationError]

property code: dict

The code section.

property register_template: dict

The register_template section.

property operations: dict

The operations section.

property properties: dict

The properties section.

property qubit_layout: dict | None

The qubit_layout section, or None if absent.

property error_correction_cycle: dict

The error_correction_cycle section with parametric repeat references resolved to integers.

Every {"ref": "<dot.path>"} value on a cycle-level or step-level repeat field is replaced by the integer the root-anchored dot-path (e.g. code.d) addresses in the document. Returns a derived deep copy, fresh per access.

Raises:

ValueError – If a repeat reference is not a dot-path string, does not resolve to a field of the document, or resolves to a non-integer. Validation guarantees resolvability, so only documents that skipped or failed validation can raise.

property decoder_config: dict | None

The decoder_config section with parametric references resolved, or None if the section is absent.

Every {"ref": "<dot.path>"} value is replaced by the value the dot-path, anchored at the code or qubit_layout section, addresses in the document: a single * projection segment resolves to a list, otherwise to a scalar. Returns a derived deep copy, fresh per access; resolution never mutates the underlying data, so to_dict() preserves the raw references.

Raises:

ValueError – If a reference does not resolve. Validation guarantees resolvability, so only documents that skipped or failed validation can raise.

property name: str

Human-readable code name.

property code_type: str

Code type string from code.code_type ("unknown" if absent).

property n: int

Number of physical qubits per code block (code.n).

property k: int

Number of logical qubits per code block (code.k).

property d: Any

Code distance (code.d). An integer for symmetric codes or a dict ({"X": ..., "Z": ...}) for asymmetric-distance codes.

property params_str: str

Formatted parameter string like [[7,1,3]].

view(config=None, **overrides)

Return a viewer over this file for display methods.

The viewer’s settings start from config when given, otherwise from DEFAULT_VIEWER_CONFIG as currently set, with overrides applied on top. The viewer holds a new ViewerConfig: neither config nor DEFAULT_VIEWER_CONFIG is modified, and later changes to either do not reach the returned viewer.

Parameters:
  • config (ViewerConfig | None) – Base settings for the viewer. None (default) uses DEFAULT_VIEWER_CONFIG.

  • **overrides (Any) – Viewer settings for this call, keyed by ViewerConfig field name (for example circuit_mode="text").

Returns:

Viewer over this file.

Return type:

QECXViewer

Raises:

TypeError – If a key of overrides is not a ViewerConfig field.