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

Fix phase of pauli_list.insert(..., qubit=True) for length-1 pauli_list (backport #13624) #13637

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jan 8, 2025

Summary

Fix #13623.

Details and comments

Fixes bug in PauliList.insert(..., qubit=True) method, where the output PauliList would have a 2D phase attribute (should be 1D).

The bug was in a line of code manually broadcasting the phase of the PauliList being inserted to match the shape of the phase of the original PauliList. This PR removes this line of code, and lets numpy handle the broadcasting of phase.

This PR also adds a check in PauliList.from_symplectic(..., phase) to reject phase if it is a multi-dimensional array, and a test for issue #13623.

(For the record, I messed up the commit message in 92161ec. The simpler if/elif case is indeed moved to be first, but in the commit message I mixed up the two cases).


This is an automatic backport of pull request #13624 done by [Mergify](https://mergify.com).

…_list` (#13624)

* switch order of if-clauses

`len(value) == 1` is the simplest case, and is also the case where the problematic clause `len(value) == size` fails.

This commit switches the order, so we check for `len(value) == 1` first.

This ensures that when the `len(value) == size` clause runs, we know that `size != 1`, avoiding the bug in #13623.

* add test

* Simplify `value.phase` broadcasting

Here, `phase` should be a 1D array. `np.vstack()` docs say explicitly output will be at least 2D, so we should not use that to create `phase`.

The intent of using `np.vstack()` was essentially to broadcast `phase` to properly add to `self.phase`. But, this happens automatically and correctly if we just add as-is. So this commit simplifies the code accordingly.

* Verify that `phase` is 1D in `from_symplectic()`

Verifying the input arg `phase`, since otherwise `from_symplectic()` will silently create PauliLists with malformed `phase` attributes (i.e. not 1D).

Zero-dimensional is OK (e.g. `phase` defaults to `0`) since that can broadcast per the shape of the `z` and `x` arrays.

* remove vestigial line

* lint

* release note

* Update releasenotes/notes/fix-paulilist-length1-phase-688d0e3a64ec9a9f.yaml

Co-authored-by: Jake Lishman <[email protected]>

---------

Co-authored-by: Jake Lishman <[email protected]>
(cherry picked from commit 408741c)
@mergify mergify bot requested a review from a team as a code owner January 8, 2025 19:17
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) labels Jan 8, 2025
@github-actions github-actions bot added this to the 1.3.2 milestone Jan 8, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12677497573

Details

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.003%) to 88.934%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/operators/symplectic/pauli_list.py 6 7 85.71%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 5 91.98%
crates/qasm2/src/parse.rs 6 97.62%
Totals Coverage Status
Change from base Build 12654869981: -0.003%
Covered Lines: 79162
Relevant Lines: 89012

💛 - Coveralls

@jakelishman jakelishman added this pull request to the merge queue Jan 8, 2025
Merged via the queue into stable/1.3 with commit 947ae89 Jan 8, 2025
20 checks passed
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants