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 deprecation warnings emitted by import qiskit.primitives #10287

Merged
merged 1 commit into from
Jun 15, 2023

Conversation

jakelishman
Copy link
Member

Summary

The primitives still need to support the legacy
qiskit.opflow.PauliSumOp while that object is deprecated but not removed. However, we do not want the import of qiskit.primitives to need to import opflow to do that, since that will cause the deprecation warnings emitted by the import of opflow to be hidden (they'll be blamed on Qiskit library code, so hidden by default).

All type-hint usage we can hide behind the TYPE_CHECKING static analysis gate. For cases where we were actively runtime type-checking an object, we can gate the isinstance check behind a check that qiskit.opflow is already imported; the object cannot be a PauliSumOp if the module isn't initialised.

Details and comments

Fix #10245

The primitives still need to support the legacy
`qiskit.opflow.PauliSumOp` while that object is deprecated but not
removed.  However, we do not want the import of `qiskit.primitives` to
need to import `opflow` to do that, since that will cause the
deprecation warnings emitted by the import of `opflow` to be hidden
(they'll be blamed on Qiskit library code, so hidden by default).

All type-hint usage we can hide behind the `TYPE_CHECKING` static
analysis gate.  For cases where we were actively runtime type-checking
an object, we can gate the `isinstance` check behind a check that
`qiskit.opflow` is already imported; the object cannot be a `PauliSumOp`
if the module isn't initialised.
@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Jun 15, 2023
@jakelishman jakelishman added this to the 0.24.2 milestone Jun 15, 2023
@jakelishman jakelishman requested review from a team, ikkoham and t-imamichi as code owners June 15, 2023 11:36
@qiskit-bot
Copy link
Collaborator

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

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

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5278300292

  • 12 of 17 (70.59%) changed or added relevant lines in 4 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 85.958%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/primitives/backend_estimator.py 2 3 66.67%
qiskit/primitives/base/base_estimator.py 2 3 66.67%
qiskit/primitives/estimator.py 2 3 66.67%
qiskit/primitives/utils.py 6 8 75.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
crates/qasm2/src/lex.rs 2 91.65%
Totals Coverage Status
Change from base Build 5266466291: 0.02%
Covered Lines: 71348
Relevant Lines: 83003

💛 - Coveralls

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

@jakelishman jakelishman added this pull request to the merge queue Jun 15, 2023
Merged via the queue into Qiskit:main with commit 81964e6 Jun 15, 2023
mergify bot pushed a commit that referenced this pull request Jun 15, 2023
The primitives still need to support the legacy
`qiskit.opflow.PauliSumOp` while that object is deprecated but not
removed.  However, we do not want the import of `qiskit.primitives` to
need to import `opflow` to do that, since that will cause the
deprecation warnings emitted by the import of `opflow` to be hidden
(they'll be blamed on Qiskit library code, so hidden by default).

All type-hint usage we can hide behind the `TYPE_CHECKING` static
analysis gate.  For cases where we were actively runtime type-checking
an object, we can gate the `isinstance` check behind a check that
`qiskit.opflow` is already imported; the object cannot be a `PauliSumOp`
if the module isn't initialised.

(cherry picked from commit 81964e6)
@jakelishman jakelishman deleted the fix-opflow-warnings-primitives branch June 15, 2023 14:12
jakelishman added a commit that referenced this pull request Jun 15, 2023
… (#10290)

The primitives still need to support the legacy
`qiskit.opflow.PauliSumOp` while that object is deprecated but not
removed.  However, we do not want the import of `qiskit.primitives` to
need to import `opflow` to do that, since that will cause the
deprecation warnings emitted by the import of `opflow` to be hidden
(they'll be blamed on Qiskit library code, so hidden by default).

All type-hint usage we can hide behind the `TYPE_CHECKING` static
analysis gate.  For cases where we were actively runtime type-checking
an object, we can gate the `isinstance` check behind a check that
`qiskit.opflow` is already imported; the object cannot be a `PauliSumOp`
if the module isn't initialised.

(cherry picked from commit 81964e6)

Co-authored-by: Jake Lishman <jake.lishman@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 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.

Importing qiskit.primitives emits a large number of opflow deprecation warnings
5 participants