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

Use PyO3 0.22 and rust-numpy 0.22 #13313

Merged
merged 3 commits into from
Oct 11, 2024
Merged

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Oct 11, 2024

Summary

This commit migrates to using PyO3 0.22 and rust-numpy and updates all the deprecated and changed interfaces in the libraries to their new syntax. No new or alternative interfaces are used as part of this PR except for where deprecation warnings pointed to do so.

One thing to note is that in pyo3 0.22 a new feature py-clone was added to re-enable Py<T>::clone(). This was disabled by default in pyo3 0.22 because of a soundness issue around calling that in situations when the GIL was not held. [1] Right now qiskit relies on using Clone on Py objects because we have container types that own a PyObject that we sometimes clone at the top level so this flag needs to be set. This only occurs in the circuit crate. In the future we can look at adding interfaces to avoid needing this flag in the future.

Another thing to note is that rust-numpy includes support for ndarray 0.16, however this PR doesn't migrate to it because ndarray_einsum_beta used in the qiskit_accelerate::unitary_compose module still depends on ndarray 0.15 and we can't upgrade until that does.

Details and comments

[1] https://pyo3.rs/v0.22.3/migration#pyclone-is-now-gated-behind-the-py-clone-feature

This commit migrates to using PyO3 0.22 and rust-numpy and updates all
the deprecated and changed interfaces in the libraries to their new
syntax. No new or alternative interfaces are used as part of this PR
except for where deprecation warnings pointed to do so.

One thing to note is that in pyo3 0.22 a new feature py-clone
was added to re-enable `Py<T>::clone()`. This was disabled by default in
pyo3 0.22 because of a soundness issue around calling that in situations
when the GIL was not held. [1] Right now qiskit relies on using `Clone` on
`Py` objects because we have container types that own a `PyObject` that
we sometimes clone at the top level so this flag needs to be set. In the
future we can look at adding interfaces to avoid needing this flag in
the future.

Another thing to note is that rust-numpy includes support for ndarray
0.16, however this PR doesn't migrate to it because `ndarray_einsum_beta`
used in the `qiskit_accelerate::unitary_compose` module still depends on
ndarray 0.15 and we can't upgrade until that does.

[1] https://pyo3.rs/v0.22.3/migration#pyclone-is-now-gated-behind-the-py-clone-feature
@mtreinish mtreinish added the Changelog: None Do not include in changelog label Oct 11, 2024
@mtreinish mtreinish requested a review from a team as a code owner October 11, 2024 19:28
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @levbishop

@mtreinish mtreinish added Rust This PR or issue is related to Rust code in the repository dependencies Pull requests that update a dependency file labels Oct 11, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11298339065

Details

  • 13 of 16 (81.25%) changed or added relevant lines in 10 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 88.676%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/nlayout.rs 1 4 25.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 92.73%
crates/accelerate/src/target_transpiler/mod.rs 8 79.11%
Totals Coverage Status
Change from base Build 11277520565: 0.02%
Covered Lines: 73194
Relevant Lines: 82541

💛 - Coveralls

Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Thanks for doing this. It's always neat to see how PyO3's interface evolves through these updates 🙂.

@@ -613,6 +613,7 @@ impl CommutationLibrary {
#[pymethods]
impl CommutationLibrary {
#[new]
#[pyo3(signature=(py_any=None))]
Copy link
Contributor

Choose a reason for hiding this comment

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

They finally got rid of the automatic optional stuff I see!

@kevinhartman kevinhartman added this pull request to the merge queue Oct 11, 2024
Merged via the queue into Qiskit:main with commit 1e2d337 Oct 11, 2024
15 checks passed
@mtreinish mtreinish deleted the bump-pyo3-22 branch October 11, 2024 22:16
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 dependencies Pull requests that update a dependency file Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants