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

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Sep 1, 2023

Internal dunder code in quantum_info/operators/symplectic/pauli.py was still using Bit.index access, which is deprecated since 0.17 (see #10744).

Because tup is coming from a QuantumCircuit in scope (instr), it is easy to fix with find_bit.

@1ucian0 1ucian0 requested review from ikkoham and a team as code owners September 1, 2023 11:32
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @ikkoham

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This is also more correct, so that's good too. I strongly suspect that this PR also fixes this code block:

from qiskit.quantum_info import Pauli
from qiskit.circuit import Qubit, QuantumCircuit
qc = QuantumCircuit([Qubit()])
qc.x(0)
Pauli(qc)

Would you like to add a test and a bugfix release note about that?

@1ucian0
Copy link
Member Author

1ucian0 commented Sep 1, 2023

Would you like to add a test and a bugfix release note about that?

I was unaware of the issue. Redoing this PR as a bugfix in 0347975 . thanks!

@1ucian0 1ucian0 changed the title Do not use Bit.index in quantum_info/operators/symplectic/pauli.py Support new-style Bit in Pauli convertor from QuantumCircuit Sep 1, 2023
@1ucian0 1ucian0 added Changelog: Bugfix Include in the "Fixed" section of the changelog and removed Changelog: None Do not include in changelog labels Sep 1, 2023
@@ -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.

@1ucian0 1ucian0 added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Sep 1, 2023
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Yeah, I wasn't aware of it as a bug before this PR either - I had a quick look through our issues but didn't see anything - it was just clear from the code change that it couldn't have handled loose qubits, so I made a quick failure-path demo. Thanks for fixing it!

@jakelishman jakelishman added the mod: quantum info Related to the Quantum Info module (States & Operators) label Sep 1, 2023
@jakelishman jakelishman added this to the 0.25.2 milestone Sep 1, 2023
@jakelishman jakelishman added this pull request to the merge queue Sep 1, 2023
Merged via the queue into Qiskit:main with commit 89ea58b Sep 1, 2023
14 checks passed
mergify bot pushed a commit that referenced this pull request Sep 1, 2023
* 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)
github-merge-queue bot pushed a commit that referenced this pull request Sep 1, 2023
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants