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

Reject bad values in SparsePauliOp.paulis setter #10437

Merged
merged 9 commits into from
Aug 16, 2023

Conversation

atharva-satpute
Copy link
Contributor

Summary

Updated the sparse pauli setter method to propagate dimension info by calling the parent's (BaseOperator) __init__()
Fix: #10384

Details and comments

The dimension info was updated and propagated up via PauliList but remained unchanged when accessed via SparsePauliOp object

@atharva-satpute atharva-satpute requested review from a team and ikkoham as code owners July 16, 2023 04:32
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 16, 2023
@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 the following people are requested to review this:

  • @Qiskit/terra-core
  • @ikkoham

@coveralls
Copy link

coveralls commented Jul 16, 2023

Pull Request Test Coverage Report for Build 5875634140

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 14 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.007%) to 87.257%

Files with Coverage Reduction New Missed Lines %
qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py 1 93.28%
qiskit/pulse/library/waveform.py 3 93.75%
crates/qasm2/src/lex.rs 4 91.14%
crates/qasm2/src/parse.rs 6 97.13%
Totals Coverage Status
Change from base Build 5872123450: -0.007%
Covered Lines: 74300
Relevant Lines: 85151

💛 - Coveralls

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.

Thanks for looking at this. I'm not certain that this will be the direction we ought to go with the linked issue: see #10384 (comment).

For what it's worth, it's typically not good to call an __init__ method from anywhere other than a child class's __init__; it's quite easy for bugs to slip in like this if the child class __init__ prepares some other state before calling up to its parent initialiser. It doesn't happen currently in SparsePauliOp, but it's something that may well get introduced in the future.

Value error will be raised if:
1. Number of qubits are not equal
2. Number of elements in PauliList are not equal
Value error will be raised if:
1. Number of qubits are not equal
2. Number of elements in PauliList are not equal
@atharva-satpute atharva-satpute force-pushed the fix-pauli-setter-propagate-info branch from b6a2891 to 94df9e7 Compare July 18, 2023 13:49
@ikkoham ikkoham added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: quantum info Related to the Quantum Info module (States & Operators) labels Jul 19, 2023
Copy link
Contributor

@ikkoham ikkoham left a comment

Choose a reason for hiding this comment

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

Thanks. It looks good to me. Could you add the release note and tests to check this spec?

@atharva-satpute
Copy link
Contributor Author

Sure

@jakelishman
Copy link
Member

@ikkoham: I've just updated this PR to add the tests and a release note. Could you review / merge?

@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable and removed stable backport potential The bug might be minimal and/or import enough to be port to stable labels Aug 3, 2023
@jakelishman jakelishman changed the title Fix Sparse pauli setter to update dimension info Reject bad values in SparsePauliOp.paulis setter Aug 3, 2023
@ikkoham ikkoham added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Aug 16, 2023
Copy link
Contributor

@ikkoham ikkoham left a comment

Choose a reason for hiding this comment

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

Nice. LGTM! (I believe this is back port stable potential.)

@ikkoham ikkoham added this pull request to the merge queue Aug 16, 2023
Merged via the queue into Qiskit:main with commit fe87015 Aug 16, 2023
9 of 13 checks passed
mergify bot pushed a commit that referenced this pull request Aug 16, 2023
* Fix Sparse pauli setter to update dimension info

* Fix Sparse pauli setter to verify dimension info

Value error will be raised if:
1. Number of qubits are not equal
2. Number of elements in PauliList are not equal

* Add tests

* Add release note

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
(cherry picked from commit fe87015)
github-merge-queue bot pushed a commit that referenced this pull request Aug 16, 2023
* Fix Sparse pauli setter to update dimension info

* Fix Sparse pauli setter to verify dimension info

Value error will be raised if:
1. Number of qubits are not equal
2. Number of elements in PauliList are not equal

* Add tests

* Add release note

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
(cherry picked from commit fe87015)

Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com>
SamD-1998 pushed a commit to SamD-1998/qiskit-terra that referenced this pull request Sep 7, 2023
* Fix Sparse pauli setter to update dimension info

* Fix Sparse pauli setter to verify dimension info

Value error will be raised if:
1. Number of qubits are not equal
2. Number of elements in PauliList are not equal

* Add tests

* Add release note

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.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 Community PR PRs from contributors that are not 'members' of the Qiskit repo 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
Status: Done
Development

Successfully merging this pull request may close these issues.

SparsePauliOp.paulis setter does not propagate dimension info
5 participants