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 Numpy 1.25 deprecations #10308

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Jun 19, 2023

Summary

Most of the effects we see are because of the removal of various aliases (np.product being a common one), but the new warning on implicit conversion of size-1 arrays to scalars that was initially found in parts of c463b3c has reared its head again too.

Details and comments

This is not a complete resolution of #10305 because of larger issues with correctness of the Isometry code triggered by Numpy 1.25. It should fix all the new deprecation warnings, though.

Most of the effects we see are because of the removal of various aliases
(`np.product` being a common one), but the new warning on implicit
conversion of size-1 arrays to scalars that was initially found in parts
of c463b3c has reared its head again too.
@jakelishman jakelishman added type: qa Issues and PRs that relate to testing and code quality stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: None Do not include in changelog labels Jun 19, 2023
@qiskit-bot
Copy link
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ikkoham
  • @woodsp-ibm

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5311917846

  • 29 of 30 (96.67%) changed or added relevant lines in 17 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 85.972%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/operators/symplectic/pauli_list.py 1 2 50.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
crates/qasm2/src/lex.rs 2 92.15%
Totals Coverage Status
Change from base Build 5311759651: 0.02%
Covered Lines: 71429
Relevant Lines: 83084

💛 - Coveralls

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, and I did a quick check (because it would slip my mind otherwise and CI wouldn't catch it because we're testing with 1.24.x) and nothing here looks like it would require raising our minimum numpy version of 1.17.

Comment on lines +92 to +96
lhs = math.sin(angle / 2)

def objective(phi):
rhs = 2 * math.sin(phi / 2) ** 2
rhs *= math.sqrt(1 - math.sin(phi / 2) ** 4)
lhs = math.sin(angle / 2)
return rhs - lhs
sin_sq = np.sin(phi / 2) ** 2
return 2 * sin_sq * np.sqrt(1 - sin_sq**2) - lhs
Copy link
Member

Choose a reason for hiding this comment

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

I assume this was the place with the implicit scalar conversion was emitting a deprecation warning because of the switch from math.sin() and math.sqrt() to np.sin() and np.sqrt()`.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of them, yeah. I didn't realise I'd screwed with the implementation as much as that - I think I was thinking about reducing the increased overhead from switching back to Numpy dispatchers. I don't know enough about the internals of how Scipy's fsolve to know for sure what's safe as a return value, but it definitely puts in arrays.

@mtreinish mtreinish enabled auto-merge June 19, 2023 13:42
@mtreinish mtreinish added this pull request to the merge queue Jun 19, 2023
Merged via the queue into Qiskit:main with commit 364d6fd Jun 19, 2023
mergify bot pushed a commit that referenced this pull request Jun 19, 2023
Most of the effects we see are because of the removal of various aliases
(`np.product` being a common one), but the new warning on implicit
conversion of size-1 arrays to scalars that was initially found in parts
of c463b3c has reared its head again too.

(cherry picked from commit 364d6fd)
@jakelishman jakelishman deleted the fix-numpy-1.25-deprecations branch June 19, 2023 16:22
jakelishman added a commit that referenced this pull request Jun 19, 2023
Most of the effects we see are because of the removal of various aliases
(`np.product` being a common one), but the new warning on implicit
conversion of size-1 arrays to scalars that was initially found in parts
of c463b3c has reared its head again too.

(cherry picked from commit 364d6fd)

Co-authored-by: Jake Lishman <[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 stable backport potential The bug might be minimal and/or import enough to be port to stable type: qa Issues and PRs that relate to testing and code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants