Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new-style Bit in Pauli convertor from QuantumCircuit #10757

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated. I just noticed that the type hint for calling _from_circuit was missing.

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()