iqm.error_reduction_tools.utils.circuit_utils.TwirledCircuit#
- class iqm.error_reduction_tools.utils.circuit_utils.TwirledCircuit(operations)#
Bases:
objectA quantum circuit wrapper that supports readout twirling and gate randomization.
This class serves as a mutable working representation for building and manipulating quantum circuits. It tracks single-qubit gates, measurements, and readout twirling state. Use
to_circuit(name)to convert to the immutableCircuit.Note
We intentionally do not store a
Circuitinternally.Circuit.instructionsis an immutabletuple, which would be rebuilt on everyappend_operationcall. Instead,operationsis kept as a mutablelist[CircuitOperation]throughout circuit construction, and converted toCircuiton demand viato_circuit().- Parameters:
operations (list[CircuitOperation])
- operations#
List of operations in the circuit.
- rot_dict#
Dictionary for readout twirling rotations, if applied.
- sqg_counter#
Counter for single-qubit gates per qubit.
- measured_qubits#
List of qubits that are measured.
- active_qubits#
List of all qubits involved in the circuit.
Methods
append_operation(operation)Append a deep copy of the operation to the circuit and update basic analysis.
Perform basic analysis on quantum circuit operations.
Get rotation character per measurement key due to readout twirling.
to_circuit(name)Convert to an immutable
Circuit.- basic_analysis()#
Perform basic analysis on quantum circuit operations.
This method analyzes the circuit operations to extract information about single-qubit gates, measurements, and active qubits. It also validates that no mid-circuit measurements are present.
- Raises:
ValueError – If mid-circuit measurements are detected (when any qubit is measured more than once).
- Return type:
None
Note
This method populates the following instance attributes:
sqg_counter: Dictionary mapping qubit identifiers to the count of ‘prx’ operations performed on each qubit.measured_qubits: List of qubit identifiers that have measurement operations.active_qubits: List of all qubit identifiers that appear in any operation.
The method iterates through all operations in the circuit and:
Counts ‘prx’ (parametric rotation) operations per qubit
Counts measurement operations per qubit
Collects all qubits involved in any operation
Validates that no qubit is measured more than once
- append_operation(operation)#
Append a deep copy of the operation to the circuit and update basic analysis.
A deep copy is made to ensure that no external references to the operation are retained, preventing shared-state bugs when the same source circuit is randomized multiple times.
- Parameters:
operation (CircuitOperation)
- Return type:
None
- get_rot_char_per_meas_key()#
Get rotation character per measurement key due to readout twirling.