LogicalQ.LogicalGeneral
Classes
Core LogicalQ representation of a logical quantum circuit. |
Module Contents
- class LogicalQ.LogicalGeneral.LogicalCircuitGeneral(n_logical_qubits, label, stabilizer_tableau, name=None)
Bases:
qiskit.QuantumCircuitCore LogicalQ representation of a logical quantum circuit.
Prototyping class for implementing and testing generalized functionality.
- n_logical_qubits
- stabilizer_tableau
- n_stabilizers
- label
- n_physical_qubits
- n_ancilla_qubits
- n_measure_qubits
- stabilizers = []
- logical_qregs = []
- ancilla_qregs = []
- logical_op_qregs = []
- enc_verif_cregs = []
- curr_syndrome_cregs = []
- prev_syndrome_cregs = []
- unflagged_syndrome_diff_cregs = []
- pauli_frame_cregs = []
- logical_op_meas_cregs = []
- final_measurement_cregs = []
- qreg_lists
- creg_lists
- output_creg
- cbit_setter_qreg
- add_logical_qubits(logical_qubit_count)
- generate_code()
- encode(*qubits, max_iterations=1, initial_states=None)
Prepare logical qubit(s) in the specified initial state
- reset_ancillas(logical_qubit_indices=None)
- measure_stabilizers(logical_qubit_indices=None, stabilizer_indices=None)
- measure_syndrome_diff(logical_qubit_indices=None)
- append_qec_cycle(logical_qubit_indices=None)
- apply_decoding(logical_qubit_indices)
- measure(logical_qubit_indices, cbit_indices, with_error_correction=True, meas_basis='Z')
Measure a quantum bit (
qubit) in the Z basis into a classical bit (cbit).When a quantum state is measured, a qubit is projected in the computational (Pauli Z) basis to either \(\lvert 0 \rangle\) or \(\lvert 1 \rangle\). The classical bit
cbitindicates the result of that projection as a0or a1respectively. This operation is non-reversible.- Parameters:
qubit – qubit(s) to measure.
cbit – classical bit(s) to place the measurement result(s) in.
- Returns:
handle to the added instructions.
- Return type:
qiskit.circuit.InstructionSet
- Raises:
CircuitError – if arguments have bad format.
Examples
In this example, a qubit is measured and the result of that measurement is stored in the classical bit (usually expressed in diagrams as a double line):
┌───┐┌─┐ q: ┤ H ├┤M├ └───┘└╥┘ c: 1/══════╩═ 0It is possible to call
measurewith lists ofqubitsandcbitsas a shortcut for one-to-one measurement. These two forms produce identical results:Instead of lists, you can use
QuantumRegisterandClassicalRegisterunder the same logic.This is equivalent to:
- measure_all(with_error_correction=True, meas_basis='Z')
Adds measurement to all qubits.
By default, adds new classical bits in a
ClassicalRegisterto store these measurements. Ifadd_bits=False, the results of the measurements will instead be stored in the already existing classical bits, with qubitnbeing measured into classical bitn.Returns a new circuit with measurements if
inplace=False.- Parameters:
inplace (bool) – All measurements inplace or return new circuit.
add_bits (bool) – Whether to add new bits to store the results.
- Returns:
Returns circuit with measurements when
inplace=False.- Return type:
QuantumCircuit
- Raises:
CircuitError – if
add_bits=Falsebut there are not enough classical bits.
- remove_final_measurements(inplace=False)
Removes final measurements and barriers on all qubits if they are present. Deletes the classical registers that were used to store the values from these measurements that become idle as a result of this operation, and deletes classical bits that are referenced only by removed registers, or that aren’t referenced at all but have become idle as a result of this operation.
Measurements and barriers are considered final if they are followed by no other operations (aside from other measurements or barriers.)
Note
This method has rather complex behavior, particularly around the removal of newly idle classical bits and registers. It is much more efficient to avoid adding unnecessary classical data in the first place, rather than trying to remove it later.
See also
RemoveFinalMeasurementsA transpiler pass that removes final measurements and barriers. This does not remove the classical data. If this is your goal, you can call that with:
from qiskit.circuit import QuantumCircuit from qiskit.transpiler.passes import RemoveFinalMeasurements qc = QuantumCircuit(2, 2) qc.h(0) qc.cx(0, 1) qc.barrier() qc.measure([0, 1], [0, 1]) pass_ = RemoveFinalMeasurements() just_bell = pass_(qc)
- Parameters:
inplace (bool) – All measurements removed inplace or return new circuit.
- Returns:
Returns the resulting circuit when
inplace=False, else None.- Return type:
QuantumCircuit
- get_logical_counts(physical_counts, logical_qubit_indices=None)
Get logical counts from physical counts.
- Parameters:
physical_counts (Iterable[int]) – Physical counts to convert to logical counts.
logical_qubit_indices (Iterable[int]) – Logical qubits to get counts for. If None, then get counts for all.
- Returns:
Logical qubit counts.
- Return type:
dict[str, int]
- h(*targets, method='Coherent_Feedback')
Logical Hadamard gate
- x(*targets)
Logical PauliX gate
- y(*targets)
Logical PauliY gate
- z(*targets)
Logical PauliZ gate
- s(*targets, method='Coherent_Feedback')
Logical S gate
Definition: [1 0] [0 i]
- sdg(*targets, method='Coherent_Feedback')
Logical S^dagger gate
Definition: [1 0] [0 -i]
- t(*targets, method='Coherent_Feedback')
Logical T gate
Definition: [1 0 ] [0 e^(ipi/4)]
- tdg(*targets, method='Coherent_Feedback')
Logical T^dagger gate
Definition: [1 0 ] [0 e^(-ipi/4)]
- cx(control, *_targets, method='Ancilla_Assisted')
Logical Controlled-PauliX gate
- cz(control, *_targets, method='Ancilla_Assisted')
Logical Controlled-PauliZ gate
- cy(control, *_targets, method='Ancilla_Assisted')
Logical Controlled-PauliY gate
- mcmt(gate, controls, targets)
Logical Multi-Control Multi-Target gate
- add_error(l_ind, p_ind, error_type)
- set_cbit(cbit, value)
- cbit_not(cbit)
- cbit_and(cbits, values)
- cbit_xor(cbits)