LogicalQ.Logical
Classes
Core LogicalQ representation of a logical quantum circuit. |
|
A single LogicalQubit |
|
A register containing LogicalQubits |
|
A LogicalStatevector |
|
A LogicalDensityMatrix |
Functions
|
Module Contents
- class LogicalQ.Logical.LogicalCircuit(n_logical_qubits, label, stabilizer_tableau, name=None)
Bases:
qiskit.QuantumCircuitCore LogicalQ representation of a logical quantum circuit.
- Parameters:
n_logical_qubits (int)
label (Iterable[int])
stabilizer_tableau (Iterable[str])
name (str)
- n_logical_qubits
- stabilizer_tableau
- n_stabilizers
- label
- n_physical_qubits
- n_ancilla_qubits
- n_measure_qubits
- flagged_stabilizers_1 = []
- flagged_stabilizers_2 = []
- x_stabilizers = []
- z_stabilizers = []
- qed_cycle_indices_initial
- qed_cycle_indices_final
- qec_cycle_indices_initial
- qec_cycle_indices_final
- logical_qregs = []
- ancilla_qregs = []
- logical_op_qregs = []
- enc_verif_cregs = []
- curr_syndrome_cregs = []
- prev_syndrome_cregs = []
- flagged_syndrome_diff_cregs = []
- unflagged_syndrome_diff_cregs = []
- pauli_frame_cregs = []
- logical_op_meas_cregs = []
- final_measurement_cregs = []
- qreg_lists
- creg_lists
- output_creg
- cbit_setter_qreg
- data_without_qec
- data_without_qed
- classmethod from_physical_circuit(physical_circuit, label, stabilizer_tableau, name=None, max_iterations=1)
Construct a LogicalCircuit from a physical qiskit circuit.
- Parameters:
physical_circuit (qiskit.QuantumCircuit) – The QuantumCircuit to construct from.
label (Iterable[int]) – The QECC label.
stabilizer_tableau (Iterable[str]) – The set of stabilizers for the QECC.
name (str) – An optional name for the circuit.
max_iterations (int) – Number of times, to attempt to encod qubits.
- Returns:
The LogicalCircuit constructed from the physical.
- Return type:
- add_logical_qubits(logical_qubit_count)
Add logical qubit(s) to the LogicalCircuit.
- Parameters:
logical_qubit_count (int) – The number of logical qubits to add.
- group_stabilizers()
Generate the stabilizers for the code.
- generate_code()
Generate the encoding circuit and logical operators for the selected tableau.
- encode(*qubits, max_iterations=1, initial_states=None)
Prepare logical qubit(s) in the specified initial state.
- Parameters:
qubits (Iterable[int]) – Qubits to encode.
max_iterations (int) – Maximum number of times, to try to encode data.
initial_states (Iterable[list[int]] | None) – Initial states to encode in each qubit.
- Returns:
True, always
- Return type:
bool
- reset_ancillas(logical_qubit_indices=None)
Reset all ancillas associated with specified logical qubits.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Indices of logical qubits to reset. If None, then reset all.
- steane_flagged_circuit1(logical_qubit_indices)
Measure first set of flagged syndromes for the Steane code.
- Parameters:
logical_qubit_indices (Iterable[int])
- steane_flagged_circuit2(logical_qubit_indices)
Measure second set of flagged syndromes for the Steane code.
- Parameters:
logical_qubit_indices (Iterable[int])
- measure_stabilizers(logical_qubit_indices=None, stabilizer_indices=None)
Measure specified stabilizers to the circuit as controlled Pauli operators.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Indices of logical qubits for which to measure stabilizers.
stabilizer_indices (Iterable[int] | None) – Indices of stabilizers to measure.
- measure_syndrome_diff(logical_qubit_indices=None, stabilizer_indices=None, flagged=False, steane_flag_1=False, steane_flag_2=False)
Measure flagged or unflagged syndrome differences for specified logical qubits and stabilizers.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits for which to measure indices.
stabilizer_indices (Iterable[int] | None) – Stabilizers for which to measure indices.
flagged (bool) – Whether to measure flagged or unflagged differences.
steane_flag_1 (bool) – Whether to measure the first Steane code syndrome. Takes priority over steane_flag_2.
steane_flag_2 (bool) – Whether to measure the second Steane code syndrome. Ignored if steane_flag_1 is True.
- optimize_qec_cycle_indices(logical_qubit_indices=None, constraint_model=None, ignore_existing_qec=False, clear_existing_qec=False)
Compute optimal QEC cycle indices.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits for which to compute optimal QEC cycle indices.
constraint_model (dict[str, float] | None) – Constraint model, i.e., dictionary of gadget costs for the circuit.
ignore_existing_qec (bool) – Whether to ignore QEC-related parameters in the constraint model.
clear_existing_qec (bool) – Whether to remove existing QEC cycles.
- Returns:
Dictionary with optimal QEC cycle indices for each requested qubit.
- Return type:
dict[int, int]
- insert_qec_cycles(logical_qubit_indices=None, qec_cycle_indices=None, clear_existing_qec=False)
Insert QEC cycles at specified indices in the circuit data.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits for which to insert QEC cycles.
qec_cycle_indices (dict[int, list] | list[list] | None) – Indices at which to insert QEC cycles for each logical qubit.
clear_existing_qec (bool) – Whether to clear the existing QEC cycles.
- Returns:
Original circuit data and data after appending QEC cycles.
- Return type:
tuple[qiskit.circuit.quantumcircuitdata.QuantumCircuitData, qiskit.circuit.quantumcircuitdata.QuantumCircuitData]
- append_qed_cycle(logical_qubit_indices=None, perform_flagged_syndrome_measurements=True)
Append a QED cycle to the end of the circuit.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits for which to add QED cycles.
perform_flagged_syndrome_measurements (bool)
- Returns:
Qubits and indices with QED cycles, before and after appending.
- Return type:
tuple[dict[int, int], dict[int, int]]
- append_qec_cycle(logical_qubit_indices=None, perform_flagged_syndrome_measurements=True)
Append a QEC cycle to the end of the circuit.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits for which to add QEC cycles.
perform_flagged_syndrome_measurements (bool)
- Returns:
Qubits and indices with QEC cycles, before and after appending.
- Return type:
tuple[dict[int, int], dict[int, int]]
- clear_qec_cycles(logical_qubit_indices=None, qec_cycle_indices=None)
Clear QEC cycles (either specified or all) on specified logical qubits.
- Parameters:
logical_qubit_indices (Iterable[int] | None) – Logical qubits from which to clear QEC cycles. Clears all if
None.qec_cycle_indices (Iterable[int] | None) – QEC cycles to clear. Clears all if
None
- Returns:
This method is not yet implemented.
- Return type:
NotImplementedError
- apply_decoding(logical_qubit_indices, stabilizer_indices, with_flagged)
Decode the syndrome measurements to determine the correction to apply.
- Parameters:
logical_qubit_indices (Iterable[int]) – Logical qubits to apply decoding to.
stabilizer_indices (Iterable[int]) – Stabilizers for which to decode syndromes.
with_flagged (bool) – Whether to decode with flagged or unflagged syndrome differences.
- measure(logical_qubit_indices, cbit_indices, with_error_correction=True)
Measure specified qubits (in the Z basis) into classical bits.
- Parameters:
logical_qubit_indices (Iterable[int]) – Logical qubits to measure.
cbit_indices (Iterable[int]) – Classical bits in which to record measurements.
with_error_correction (bool) – Whether to apply QEC.
- Raises:
ValueError – if logical_qubit_indices or cbit_indices is not an iterable or if number of qubits and cbits does not match.
- measure_all(inplace=True, with_error_correction=True)
Add measurements to all qubits.
- Parameters:
inplace (bool) – Whether to perform measurements on this circuit or a copy. If False, a new circuit is returned.
with_error_correction (bool) – Whether to perform measurements with QEC.
- Returns:
Circuit with measurements, if inplace = False.
- Return type:
- remove_final_measurements(inplace=False)
Remove final measurements from circuit.
- Parameters:
inplace (bool) – Whether to remove measurements in place, i.e., for this circuit (not supported).
- Raises:
NotImplementedError – if in-place measurement is attempted.
- Returns:
The circuit without measurements.
- Return type:
- 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
- rx(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Logical Single-Target Rotation Gate
method = “LCU” -> linear combination of unitaries or “S-K” -> solovay-kitaev algorithm or “OAA” -> oblivious amplitude amplification
theta in radians
- Parameters:
theta (float)
- ry(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Logical Single-Target Rotation Gate
method = “LCU” or “S-K”
theta in radians
- Parameters:
theta (float)
- rz(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Logical Single-Target Rotation Gate
method = “LCU” or “S-K”
theta in radians
- Parameters:
theta (float)
- rxx(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Apply
RXXGate.For the full matrix form of this gate, see the underlying gate documentation.
- Parameters:
theta (float) – The angle of the rotation.
qubit1 – The qubit(s) to apply the gate to.
qubit2 – The qubit(s) to apply the gate to.
- Returns:
A handle to the instructions created.
- ryy(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Apply
RYYGate.For the full matrix form of this gate, see the underlying gate documentation.
- Parameters:
theta (float) – The rotation angle of the gate.
qubit1 – The qubit(s) to apply the gate to.
qubit2 – The qubit(s) to apply the gate to.
- Returns:
A handle to the instructions created.
- rzz(theta, targets, method='S-K', depth=10, recursion_degree=1, box=True)
Apply
RZZGate.For the full matrix form of this gate, see the underlying gate documentation.
- Parameters:
theta (float) – The rotation angle of the gate.
qubit1 – The qubit(s) to apply the gate to.
qubit2 – The qubit(s) to apply the gate to.
- Returns:
A handle to the instructions created.
- append_sk_decomposition(circuit, targets, label='U', depth=10, recursion_degree=1, box=False, return_subcircuit=False)
- r(axis, targets, theta=0, label='R', depth=10, recursion_degree=1, box=True, method='S-K')
Apply
RGate.For the full matrix form of this gate, see the underlying gate documentation.
- Parameters:
theta – The angle of the rotation.
phi – The angle of the axis of rotation in the x-y plane.
qubit – The qubit(s) to apply the gate to.
- Returns:
A handle to the instructions created.
- append(instruction, qargs=None, cargs=None, copy=True)
Append one or more instructions to the end of the circuit, modifying the circuit in place.
The
qargsandcargswill be expanded and broadcast according to the rules of the givenInstruction, and any non-Bitspecifiers (such as integer indices) will be resolved into the relevant instances.If a
CircuitInstructionis given, it will be unwrapped, verified in the context of this circuit, and a new object will be appended to the circuit. In this case, you may not passqargsorcargsseparately.- Parameters:
instruction –
Instructioninstance to append, or aCircuitInstructionwith all its context.qargs – specifiers of the
Qubits to attach instruction to.cargs – specifiers of the
Clbits to attach instruction to.copy – if
True(the default), then the incominginstructionis copied before adding it to the circuit if it contains symbolic parameters, so it can be safely mutated without affecting other circuits the same instruction might be in. If you are sure this instruction will not be in other circuits, you can set thisFalsefor a small speedup.
- Returns:
a handle to the
CircuitInstructions that were actually added to the circuit.- Return type:
qiskit.circuit.InstructionSet
- Raises:
CircuitError – if the operation passed is not an instance of
Instruction.
- add_error(l_ind, p_ind, error_type)
- set_cbit(cbit, value)
- cbit_not(cbit)
- cbit_and(cbits, values)
- cbit_xor(cbits)
- draw(output=None, scale=None, filename=None, style=None, interactive=False, plot_barriers=True, reverse_bits=None, justify=None, vertical_compression='medium', idle_wires=None, with_layout=True, fold=None, ax=None, initial_state=False, cregbundle=None, wire_order=None, expr_len=30, fold_qec=True, fold_logicalop=True)
LogicalCircuit drawer based on Qiskit circuit drawer
- class LogicalQ.Logical.LogicalQubit(regs=None, qregs=None, cregs=None)
Bases:
listA single LogicalQubit
- _data = []
- qregs = []
- cregs = []
- class LogicalQ.Logical.LogicalRegister(qregs=None, cregs=None)
Bases:
listA register containing LogicalQubits
- qregs = None
- cregs = None
- class LogicalQ.Logical.LogicalStatevector(data, logical_circuit=None, n_logical_qubits=None, label=None, stabilizer_tableau=None, dims=None)
Bases:
qiskit.quantum_info.StatevectorA LogicalStatevector
- Parameters:
data (numpy.ndarray | qiskit.QuantumCircuit | LogicalCircuit | qiskit.quantum_info.Statevector)
logical_circuit (LogicalCircuit)
n_logical_qubits (int)
label (Iterable[int])
stabilizer_tableau (Iterable[str])
dims (int)
- _logical_decomposition = None
- classmethod from_counts(counts, n_logical_qubits, label, stabilizer_tableau, basis='physical')
Construct a LogicalStatevector from measurement counts.
- Parameters:
counts (dict) – The set of counts measured from a circuit execution.
n_logical_qubits (int) – The number of logical qubits.
label (tuple) – The quantum error correction code [[n,k,d]] (given as a tuple).
stabilizer_tableau (Iterable[str]) – The set of stabilizers for the QECC.
basis (str) – The basis in which each respective count’s vector is given, physical or logical.
- Returns:
The normalized LogicalStatevector constructed from the counts.
- Raises:
ValueError – if the counts format could not be parsed or if basis is invalid.
- Return type:
- classmethod from_basis_str(basis_str, n_logical_qubits, label, stabilizer_tableau, basis='physical')
- Construct a LogicalStatevector, an element of the logical computational basis, from
a basis string.
- Parameters:
basis_str (str) – Either a binary bitstring or its hex equivalent to identify the basis.
n_logical_qubits (int) – Number of logical qubits.
label (tuple) – The label of the quantum error correction code [[n,k,d]] (as a tuple).
stabilizer_tableau (Iterable[str]) – The set of stabilizers for the QECC.
basis (str) – The basis in which each respective count’s vector is given, physical or logical.
- Returns:
- The LogicalStatevector of
the given basis state.
- Return type:
- Raises:
ValueError – if the basis_str could not be parsed due to improper format.
- property logical_decomposition
Give a decomposition of a LogicalStatevector into the logical basis.
- Parameters:
atol (float) – Tolerance within which to set probability amplitude to zero.
- Returns:
- The set of coefficients \(\alpha_i, \delta\), where
\(|\psi\rangle = \sum_{x=0}^{2^n - 1}\alpha_x|x\rangle + \delta|\psi^\perp\rangle\), where \(|\psi^\perp\rangle\) is the component of the state vector not in the codespace. Note that coefficients are returned in ascending order of value, e.g., 000, 001, 010, 011, 100, 101, etc.
- Return type:
np.ndarray
- __array__(basis='physical', dtype=None, copy=_numpy_compat.COPY_ONLY_IF_NEEDED)
Return an array representation of the object.
- Parameters:
basis (str) – The basis, physical or logical, in which to represent the vector.
dtype (data-type) – The desired data-type for the array.
copy (bool) – If True, then the array data is copied
- Returns:
- The
logical_decomposition() if basis is logical and the statevector data otherwise.
- The
- Return type:
np.ndarray- Raises:
ValueError – if the basis is invalid.
- __repr__(basis='logical')
Return a string representation of the statevector.
- Parameters:
basis (str) – The basis, logical or physical, in which to return the array.
- Returns:
String representation of the statevector in the requested basis.
- Return type:
np.ndarray- Raises:
ValueError – if the basis is invalid.
- draw(output=None)
Return a visual representation of the statevector in the logical basis.
- Parameters:
output (str) – The method in which to draw. Valid choices are text, latex, and latex_source.
- Returns:
String or LaTeX representation of the statevector.
- Return type:
strorIPython.display.Latex- Raises:
ValueError – if the draw method is invalid.
- class LogicalQ.Logical.LogicalDensityMatrix(data, n_logical_qubits=None, label=None, stabilizer_tableau=None, dims=None)
Bases:
qiskit.quantum_info.DensityMatrixA LogicalDensityMatrix
- _logical_decomposition = None
- abstract property logical_decomposition
- __repr__(basis='logical')
- LogicalQ.Logical.logical_state_fidelity(state1, state2)