LogicalQ.LogicalGeneral ======================= .. py:module:: LogicalQ.LogicalGeneral Classes ------- .. autoapisummary:: LogicalQ.LogicalGeneral.LogicalCircuitGeneral Module Contents --------------- .. py:class:: LogicalCircuitGeneral(n_logical_qubits, label, stabilizer_tableau, name=None) Bases: :py:obj:`qiskit.QuantumCircuit` Core LogicalQ representation of a logical quantum circuit. Prototyping class for implementing and testing generalized functionality. .. py:attribute:: n_logical_qubits .. py:attribute:: stabilizer_tableau .. py:attribute:: n_stabilizers .. py:attribute:: label .. py:attribute:: n_physical_qubits .. py:attribute:: n_ancilla_qubits .. py:attribute:: n_measure_qubits .. py:attribute:: stabilizers :value: [] .. py:attribute:: logical_qregs :value: [] .. py:attribute:: ancilla_qregs :value: [] .. py:attribute:: logical_op_qregs :value: [] .. py:attribute:: enc_verif_cregs :value: [] .. py:attribute:: curr_syndrome_cregs :value: [] .. py:attribute:: prev_syndrome_cregs :value: [] .. py:attribute:: unflagged_syndrome_diff_cregs :value: [] .. py:attribute:: pauli_frame_cregs :value: [] .. py:attribute:: logical_op_meas_cregs :value: [] .. py:attribute:: final_measurement_cregs :value: [] .. py:attribute:: qreg_lists .. py:attribute:: creg_lists .. py:attribute:: output_creg .. py:attribute:: cbit_setter_qreg .. py:method:: add_logical_qubits(logical_qubit_count) .. py:method:: generate_code() .. py:method:: encode(*qubits, max_iterations=1, initial_states=None) Prepare logical qubit(s) in the specified initial state .. py:method:: reset_ancillas(logical_qubit_indices=None) .. py:method:: measure_stabilizers(logical_qubit_indices=None, stabilizer_indices=None) .. py:method:: measure_syndrome_diff(logical_qubit_indices=None) .. py:method:: append_qec_cycle(logical_qubit_indices=None) .. py:method:: apply_decoding(logical_qubit_indices) .. py:method:: 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 :math:`\lvert 0 \rangle` or :math:`\lvert 1 \rangle`. The classical bit ``cbit`` indicates the result of that projection as a ``0`` or a ``1`` respectively. This operation is non-reversible. :param qubit: qubit(s) to measure. :param cbit: classical bit(s) to place the measurement result(s) in. :returns: handle to the added instructions. :rtype: qiskit.circuit.InstructionSet :raises CircuitError: if arguments have bad format. .. rubric:: 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): .. plot:: :include-source: :nofigs: :context: reset from qiskit import QuantumCircuit circuit = QuantumCircuit(1, 1) circuit.h(0) circuit.measure(0, 0) circuit.draw() .. code-block:: text ┌───┐┌─┐ q: ┤ H ├┤M├ └───┘└╥┘ c: 1/══════╩═ 0 It is possible to call ``measure`` with lists of ``qubits`` and ``cbits`` as a shortcut for one-to-one measurement. These two forms produce identical results: .. plot:: :include-source: :nofigs: :context: circuit = QuantumCircuit(2, 2) circuit.measure([0,1], [0,1]) .. plot:: :include-source: :nofigs: :context: circuit = QuantumCircuit(2, 2) circuit.measure(0, 0) circuit.measure(1, 1) Instead of lists, you can use :class:`~qiskit.circuit.QuantumRegister` and :class:`~qiskit.circuit.ClassicalRegister` under the same logic. .. plot:: :include-source: :nofigs: :context: reset from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister qreg = QuantumRegister(2, "qreg") creg = ClassicalRegister(2, "creg") circuit = QuantumCircuit(qreg, creg) circuit.measure(qreg, creg) This is equivalent to: .. plot:: :include-source: :nofigs: :context: circuit = QuantumCircuit(qreg, creg) circuit.measure(qreg[0], creg[0]) circuit.measure(qreg[1], creg[1]) .. py:method:: measure_all(with_error_correction=True, meas_basis='Z') Adds measurement to all qubits. By default, adds new classical bits in a :obj:`.ClassicalRegister` to store these measurements. If ``add_bits=False``, the results of the measurements will instead be stored in the already existing classical bits, with qubit ``n`` being measured into classical bit ``n``. Returns a new circuit with measurements if ``inplace=False``. :param inplace: All measurements inplace or return new circuit. :type inplace: bool :param add_bits: Whether to add new bits to store the results. :type add_bits: bool :returns: Returns circuit with measurements when ``inplace=False``. :rtype: QuantumCircuit :raises CircuitError: if ``add_bits=False`` but there are not enough classical bits. .. py:method:: 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. .. seealso:: :class:`.RemoveFinalMeasurements` A 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) :param inplace: All measurements removed inplace or return new circuit. :type inplace: bool :returns: Returns the resulting circuit when ``inplace=False``, else None. :rtype: QuantumCircuit .. py:method:: get_logical_counts(physical_counts, logical_qubit_indices = None) Get logical counts from physical counts. :param physical_counts: Physical counts to convert to logical counts. :param logical_qubit_indices: Logical qubits to get counts for. If `None`, then get counts for all. :returns: Logical qubit counts. .. py:method:: h(*targets, method='Coherent_Feedback') Logical Hadamard gate .. py:method:: x(*targets) Logical PauliX gate .. py:method:: y(*targets) Logical PauliY gate .. py:method:: z(*targets) Logical PauliZ gate .. py:method:: s(*targets, method='Coherent_Feedback') Logical S gate Definition: [1 0] [0 i] .. py:method:: sdg(*targets, method='Coherent_Feedback') Logical S^dagger gate Definition: [1 0] [0 -i] .. py:method:: t(*targets, method='Coherent_Feedback') Logical T gate Definition: [1 0 ] [0 e^(ipi/4)] .. py:method:: tdg(*targets, method='Coherent_Feedback') Logical T^dagger gate Definition: [1 0 ] [0 e^(-ipi/4)] .. py:method:: cx(control, *_targets, method='Ancilla_Assisted') Logical Controlled-PauliX gate .. py:method:: cz(control, *_targets, method='Ancilla_Assisted') Logical Controlled-PauliZ gate .. py:method:: cy(control, *_targets, method='Ancilla_Assisted') Logical Controlled-PauliY gate .. py:method:: mcmt(gate, controls, targets) Logical Multi-Control Multi-Target gate .. py:method:: add_error(l_ind, p_ind, error_type) .. py:method:: set_cbit(cbit, value) .. py:method:: cbit_not(cbit) .. py:method:: cbit_and(cbits, values) .. py:method:: cbit_xor(cbits)