Skip to content

Commit

Permalink
Support new-style Bit in Pauli convertor from QuantumCircuit (#10757) (
Browse files Browse the repository at this point in the history
…#10760)

* Do not use Bit.index in quantum_info/operators/symplectic/pauli.py

* bugfix

* Fix cross-reference

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
(cherry picked from commit 89ea58b)

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
  • Loading branch information
mergify[bot] and 1ucian0 authored Sep 1, 2023
1 parent 6b01a13 commit cc0f30c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions qiskit/quantum_info/operators/symplectic/pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ class initialization (``Pauli('-iXYZ')``). A ``Pauli`` object can be
_CANONICAL_PHASE_LABEL = {"": 0, "-i": 1, "-": 2, "i": 3}

def __init__(
self, data: str | tuple | Pauli | ScalarOp | None = None, x=None, *, z=None, label=None
self,
data: str | tuple | Pauli | ScalarOp | QuantumCircuit | None = None,
x=None,
*,
z=None,
label=None,
):
"""Initialize the Pauli.
Expand Down Expand Up @@ -712,7 +717,7 @@ def _from_circuit(cls, instr):
if not isinstance(inner.operation, (Barrier, Delay)):
next_instr = BasePauli(*cls._from_circuit(inner.operation))
if next_instr is not None:
qargs = [tup.index for tup in inner.qubits]
qargs = [instr.find_bit(tup).index for tup in inner.qubits]
ret = ret.compose(next_instr, qargs=qargs)
return ret._z, ret._x, ret._phase

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
The class :class:`.Pauli` now support creation from :class:`.QuantumCircuit`
that use new-style :class:`.Bit`.
10 changes: 10 additions & 0 deletions test/python/quantum_info/operators/symplectic/test_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ddt import ddt, data, unpack

from qiskit import QuantumCircuit
from qiskit.circuit import Qubit
from qiskit.exceptions import QiskitError
from qiskit.circuit.library import (
IGate,
Expand Down Expand Up @@ -484,6 +485,15 @@ def test_zero_qubit_pauli_construction(self, label, phase):
test = Pauli(label)
self.assertEqual(expected, test)

def test_circuit_with_bit(self):
"""Test new-style Bit support when converting from QuantumCircuit"""
circ = QuantumCircuit([Qubit()])
circ.x(0)
value = Pauli(circ)
target = Pauli("X")

self.assertEqual(value, target)


if __name__ == "__main__":
unittest.main()

0 comments on commit cc0f30c

Please sign in to comment.