qecx.ResetVariant

class qecx.ResetVariant(*, name, circuit, registers=<factory>, fault_tolerant, description=None, references=(), syndrome_cregs=None, transversal_readout_cregs=None, state)

Bases: OperationVariant, ResetVariant

Reset variant for one target logical state.

Reset returns a code block in an arbitrary state to a known logical state; unlike state preparation, the circuit cannot assume physical |0⟩ input and typically starts with physical reset instructions. Variants are grouped by target state.

Variables:
  • name (str) – Variant name; the handle other document sections use to address the variant.

  • circuit (QuantumCircuit) – Circuit fragment implementing the reset; read-only, like every field of the frozen variant: a changed circuit goes into a copy made with dataclasses.replace.

  • registers (Mapping[QuantumRegister | ClassicalRegister, RegisterDecl]) – One declaration per register of circuit, keyed by the live register object. Defaults to an empty mapping.

  • fault_tolerant (bool) – Whether the variant provides fault-tolerance guarantees.

  • description (str | None) – Human-readable summary of the variant.

  • references (tuple[Reference, ...]) – Citations attached to the variant; sequence input is normalized to a tuple at construction.

  • syndrome_cregs (tuple[SyndromeCregDecl, ...] | None) – Check readouts holding one bit per check, in declaration order; each entry names a distinct output-scoped register of the variant, one transversal_readout_cregs does not name, and the source whose checks the register’s bits store. No named register carries RegisterPurpose.TRANSVERSAL_READOUT. A measurement writes every bit of each named register. No entry carries a block_index, and each states its frame. None means the field is absent; an empty tuple declares no check readout; sequence input is normalized to a tuple at construction.

  • transversal_readout_cregs (tuple[TransversalReadoutCregDecl, ...] | None) – Check readouts holding one bit per block qubit read, in declaration order; each entry names an output-scoped register of the variant that syndrome_cregs does not name, and several entries may name one register, agreeing on block_index and qubits and declaring no check twice. No named register carries RegisterPurpose.SYNDROME. A measurement writes every bit of each named register. No entry carries a block_index, and each states its frame. None means the field is absent; an empty tuple declares no check readout; sequence input is normalized to a tuple at construction.

  • source_qasm (str | None) – OpenQASM text the loader built the variant from, which the variant re-saves byte for byte; set only on the variant the loader built, so a copy made with dataclasses.replace carries None and saves its own circuit. Not a constructor argument; never participates in equality comparisons.

  • state (str) – Target logical state key: one character per logical qubit of the block, in the block’s logical-qubit order, over the alphabet 0, 1, +, -, i, j (j denotes the minus-i eigenstate). The key’s length equals the code’s logical-qubit count, checked at document registration.

classmethod from_state_preparation(prep, *, name=None)

Derive a reset variant from a state-preparation variant.

Reset to a state is reset to zero followed by preparation: the derived circuit is the preparation body preceded by one physical reset instruction on each data qubit except those the body already opens with a reset, so every data qubit of the derived circuit is reset before any instruction other than a barrier acts on it. The body opens a qubit with a reset when the first instruction acting on it, a barrier not counting, is a reset outside any control-flow block. The data register is identified by its declaration: a logical-data purpose classification or, when the purpose is unset, an inherited declaration whose template entry carries the reserved data-register name. The returned variant is an independent object with no remaining tie to prep.

Both readout fields are copied. The derived circuit gives the preparation body the input it assumes, its data register in physical |0⟩ (no other register carries an assumed state in either kind), so a readout declared in the exit frame holds on the reset as on the preparation. A declaration without frame takes the preparation’s default, the exit frame, and is copied with CheckFrame.EXIT stated, as the reset kind has no default frame. An absent field stays absent and an empty one empty.

Parameters:
  • prep (StatePreparationVariant) – Source variant supplying the target state, the circuit body, the register declarations, and the readout declarations.

  • name (str | None) – Name of the derived variant; None defaults to the name of prep.

Returns:

The derived reset variant.

Return type:

ResetVariant

Raises:
  • ValueError – If prep declares no logical-data register.

  • ValueError – If a readout declaration of prep states CheckFrame.ENTRY: it names checks of the physical |0⟩ input of the preparation, which the arbitrary state entering the reset does not share.

  • ValueError – If the derived variant fails one of its construction checks.