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

Deprecate PauliList estimator observables #11055

Merged
merged 6 commits into from
Nov 2, 2023

Conversation

chriseclectic
Copy link
Member

Summary

Deprecates using a PauliList as an observable that is implicitly converted to a SparsePauliOp with coefficients 1 when calling Estimator.run. Users should instead explicitly convert the argument using SparsePauliOp(pauli_list) first.

Details and comments

Deprecates using a `PauliList` as an observable that is implicitly converted to a `SparsePauliOp` with coefficients 1 when calling `Estimator.run`. Users should instead explicitly convert the argument using `SparsePauliOp(pauli_list)` first.
@qiskit-bot
Copy link
Collaborator

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

  • @ElePT
  • @Qiskit/terra-core
  • @ajavadia
  • @ikkoham
  • @levbishop
  • @t-imamichi
  • @woodsp-ibm

@chriseclectic chriseclectic added the Changelog: Deprecation Include in "Deprecated" section of changelog label Oct 19, 2023
@woodsp-ibm woodsp-ibm added the mod: primitives Related to the Primitives module label Oct 19, 2023
t-imamichi
t-imamichi previously approved these changes Oct 23, 2023
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 22 to 29
@classmethod
def setUpClass(cls):
super().setUpClass()
allow_dep_warning_message = [
r"Implicit conversion from a PauliList to a SparsePauliOp*",
]
for msg in allow_dep_warning_message:
warnings.filterwarnings("default", category=DeprecationWarning, message=msg)
Copy link
Member

Choose a reason for hiding this comment

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

  1. Can we add a comment explaining why this needs to be a warning skip and the tests/library cannot be fixed, including the criteria for when the skip can be removed? It could also do with a module argument setting to limit the skip to precisely the allowed code, not allowed in general in all code.
  2. This skip is never torn down again but affects the global state of the warnings module, so it actually applies to all test cases, because qiskit.algorithms tests run first alphabetically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the algorithms will be removed, how about merging this PR after that?
#11086

Copy link
Member

Choose a reason for hiding this comment

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

Point 1 is still important because Algorithms isn't disappearing completely, it's just in a separate package. We should know how much work it is that we're asking downstream packages to do to manage a deprecation, and if the only option is a warning skip (though I don't think that is the case here), that's an indication that there are use cases that the new form cannot supply. It's a good thing that this warning was triggered before Algorithms moved out and we'd have seen it too late.

The warnings and errors aren't there to be annoying, they're there to ensure that the effect of deprecations on consumers is properly accounted for, and skipping a warning that we emitted is very rarely the correct action.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chriseclectic I don't recall any algorithm/test in qiskit.algorithms explicitly using PauliList, but I guess that this warning filter was introduced after some tests raised warnings. Can you point out which tests did? This would help address Jake's first point.

Copy link
Member

Choose a reason for hiding this comment

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

I expected that used around opflow, but not explicitly by algorithms. Searching here shows PauliList in 8 test files, one in opflow, nothing explicit in algorithms. Code use in primitives, visualization and of course quantum_info modules. Searching qiskit_algorithms repo shows no occurrence of PauliList at all

Copy link
Member

@t-imamichi t-imamichi Oct 26, 2023

Choose a reason for hiding this comment

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

I ran the test locally and found that no algorithm tests raise the deprecation warning due to PauliList. The deprecation warning is raised by only test.python.primitives.test_estimator.TestObservableValidation.test_validate_observables_deprecated_{1,2} as expected. So, I don't think filterwarnings is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. I ran the test locally and all tests passed.

@ikkoham ikkoham added this pull request to the merge queue Nov 2, 2023
Merged via the queue into Qiskit:main with commit 34773f3 Nov 2, 2023
14 checks passed
Matrixmang0 pushed a commit to Matrixmang0/qiskit that referenced this pull request Nov 3, 2023
* Deprecate PauliList estimator observables

Deprecates using a `PauliList` as an observable that is implicitly converted to a `SparsePauliOp` with coefficients 1 when calling `Estimator.run`. Users should instead explicitly convert the argument using `SparsePauliOp(pauli_list)` first.

* Revert algorithms_test_case.py

* Update test/python/algorithms/algorithms_test_case.py

Co-authored-by: Takashi Imamichi <[email protected]>

* Update test/python/primitives/test_estimator.py

---------

Co-authored-by: Takashi Imamichi <[email protected]>
Co-authored-by: ikkoham <[email protected]>
1ucian0 added a commit to 1ucian0/qiskit-terra that referenced this pull request Jan 9, 2024
* Deprecate PauliList estimator observables

Deprecates using a `PauliList` as an observable that is implicitly converted to a `SparsePauliOp` with coefficients 1 when calling `Estimator.run`. Users should instead explicitly convert the argument using `SparsePauliOp(pauli_list)` first.

* Revert algorithms_test_case.py

* Update test/python/algorithms/algorithms_test_case.py

Co-authored-by: Takashi Imamichi <[email protected]>

* Update test/python/primitives/test_estimator.py

---------

Co-authored-by: Takashi Imamichi <[email protected]>
Co-authored-by: ikkoham <[email protected]>
Co-authored-by: Christopher J. Wood <[email protected]>
@1ucian0
Copy link
Member

1ucian0 commented Jan 9, 2024

This PR introduced a deprecation which it was not included in the 0.* branches. Therefore, I'm porting it to stable/0.46 in #11520 and removing the Changelog label.

In #11520 I also included docstring note for warning about it.

@1ucian0 1ucian0 added Changelog: None Do not include in changelog and removed Changelog: Deprecation Include in "Deprecated" section of changelog labels Jan 9, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jan 23, 2024
* Deprecate PauliList estimator observables (#11055)

* Deprecate PauliList estimator observables

Deprecates using a `PauliList` as an observable that is implicitly converted to a `SparsePauliOp` with coefficients 1 when calling `Estimator.run`. Users should instead explicitly convert the argument using `SparsePauliOp(pauli_list)` first.

* Revert algorithms_test_case.py

* Update test/python/algorithms/algorithms_test_case.py

Co-authored-by: Takashi Imamichi <[email protected]>

* Update test/python/primitives/test_estimator.py

---------

Co-authored-by: Takashi Imamichi <[email protected]>
Co-authored-by: ikkoham <[email protected]>
Co-authored-by: Christopher J. Wood <[email protected]>

* documentation

* typo in warning msg

* adapt test

---------

Co-authored-by: Takashi Imamichi <[email protected]>
Co-authored-by: ikkoham <[email protected]>
Co-authored-by: Christopher J. Wood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: primitives Related to the Primitives module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants