forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use stable Python C API for building Rust extension (Qiskit#10120)
* Use stable Python C API for building Rust extension This commit tweaks the rust extension code to start using the PyO3 abi3 flag to build binaries that are compatible with all python versions, not just a single release. Previously, we were building against the version specific C API and that resulted in needing abinary file for each supported python version on each supported platform/architecture. By using the abi3 feature flag and marking the wheels as being built with the limited api we can reduce our packaging overhead to just having one wheel file per supported platform/architecture. The only real code change needed here was to update the memory marginalization function. PyO3's abi3 feature is incompatible with returning a big int object from rust (the C API they use for that conversion isn't part of the stable C API). So this commit updates the function to convert to create a python int manually using the PyO3 api where that was being done before. Co-authored-by: Jake Lishman <[email protected]> * Set minimum version on abi3 flag to Python 3.8 * Fix lint * Use py_limited_api="auto" on RustExtension According to the docs for the setuptools-rust RustExtension class: https://setuptools-rust.readthedocs.io/en/latest/reference.html#setuptools_rust.RustExtension The best setting to use for the py_limited_api argument is `"auto"` as this will use the setting in the PyO3 module to determine the correct value to set. This commit updates the setup.py to follow the recommendation in the docs. * Update handling of phase input to expval rust calls The pauli_expval module in Rust that Statevector and DensityMatrix leverage when computing defines the input type of the phase argument as Complex64. Previously, the quantum info code in the Statevector and DensityMatrix classes were passing in a 1 element ndarray for this parameter. When using the the version specific Python C API in pyo3 it would convert the single element array to a scalar value. However when using abi3 this handling was not done (or was not done correctly) and this caused the tests to fail. This commit updates the quantum info module to pass the phase as a complex value instead of a 1 element numpy array to bypass this behavior change in PyO3 when using abi3. Co-authored-by: Jake Lishman <[email protected]> * Set py_limited_api explicitly to True * DNM: Test cibuildwheel works with abi3 * Add abi3audit to cibuildwheel repair step * Force setuptools to use abi3 tag * Add wheel to sdist build * Workaround abiaudit3 not moving wheels and windows not having a default repair command * Add source of setup.py hack * Add comment about pending pyo3 abi3 bigint support * Revert "DNM: Test cibuildwheel works with abi3" This reverts commit 8ca24cf. * Add release note * Simplify setting abi3 tag in built wheels * Update releasenotes/notes/use-abi3-4a935e0557d3833b.yaml Co-authored-by: Jake Lishman <[email protected]> * Update release note * Update releasenotes/notes/use-abi3-4a935e0557d3833b.yaml --------- Co-authored-by: Jake Lishman <[email protected]> Co-authored-by: Jake Lishman <[email protected]>
- Loading branch information
1 parent
8c5d4ce
commit cb52fce
Showing
10 changed files
with
55 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
upgrade: | ||
- | | ||
By default Qiskit builds its compiled extensions using the | ||
`Python Stable ABI <https://docs.python.org/3/c-api/stable.html>`__ | ||
with support back to the oldest version of Python supported by Qiskit | ||
(currently 3.8). This means that moving forward there | ||
will be a single precompiled wheels that are shipped on release that | ||
works with all of Qiskit's supported Python versions. There isn't any | ||
expected runtime performance difference using the limited API so it is | ||
enabled by default for all builds now. | ||
Previously, the compiled extensions were built using the version specific API and | ||
would only work with a single Python version. This change was made | ||
to reduce the number of package files we need to build and publish in each | ||
release. When building Qiskit from source there should be no changes | ||
necessary to the build process except that the default tags in the output | ||
filenames will be different to reflect the use of the limited API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters