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 stable Python C API for building Rust extension #10120

Merged
merged 22 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fb4debb
Use stable Python C API for building Rust extension
mtreinish May 16, 2023
d1e88b3
Set minimum version on abi3 flag to Python 3.8
mtreinish May 16, 2023
6422de7
Fix lint
mtreinish May 16, 2023
0cbe140
Use py_limited_api="auto" on RustExtension
mtreinish May 16, 2023
7e5b027
Update handling of phase input to expval rust calls
mtreinish May 16, 2023
4429cbe
Set py_limited_api explicitly to True
mtreinish May 16, 2023
7321041
Merge branch 'main' into abi3
mtreinish May 24, 2023
5d1a856
Merge remote-tracking branch 'origin/main' into abi3
mtreinish Jun 2, 2023
8ca24cf
DNM: Test cibuildwheel works with abi3
mtreinish Jun 2, 2023
ee72813
Add abi3audit to cibuildwheel repair step
mtreinish Jun 2, 2023
cd986c0
Force setuptools to use abi3 tag
mtreinish Jun 2, 2023
e3de73a
Add wheel to sdist build
mtreinish Jun 2, 2023
8dc009b
Workaround abiaudit3 not moving wheels and windows not having a defau…
mtreinish Jun 2, 2023
1d8f6f1
Add source of setup.py hack
mtreinish Jun 2, 2023
0b0c030
Add comment about pending pyo3 abi3 bigint support
mtreinish Jun 2, 2023
d23e60c
Revert "DNM: Test cibuildwheel works with abi3"
mtreinish Jun 2, 2023
402ec29
Add release note
mtreinish Jun 2, 2023
deee6b0
Simplify setting abi3 tag in built wheels
mtreinish Jun 2, 2023
948cce8
Update releasenotes/notes/use-abi3-4a935e0557d3833b.yaml
mtreinish Jun 5, 2023
4979fce
Merge branch 'main' into abi3
mtreinish Jun 5, 2023
6257bdd
Update release note
mtreinish Jun 5, 2023
7a83c79
Update releasenotes/notes/use-abi3-4a935e0557d3833b.yaml
jakelishman Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustworkx-core = "0.12"
# can be done in the workspace and inherited once we hit Rust 1.64.
[dependencies.pyo3]
version = "0.18.3"
features = ["extension-module", "hashbrown", "indexmap", "num-complex", "num-bigint"]
features = ["extension-module", "hashbrown", "indexmap", "num-complex", "num-bigint", "abi3"]
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

[dependencies.ndarray]
version = "^0.15.6"
Expand Down
19 changes: 6 additions & 13 deletions crates/accelerate/src/results/marginalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,12 @@ pub fn marginal_memory(
.collect()
};
if return_int {
if out_mem.len() < parallel_threshold || !run_in_parallel {
Ok(out_mem
.iter()
.map(|x| BigUint::parse_bytes(x.as_bytes(), 2).unwrap())
.collect::<Vec<BigUint>>()
.to_object(py))
} else {
Ok(out_mem
.par_iter()
.map(|x| BigUint::parse_bytes(x.as_bytes(), 2).unwrap())
.collect::<Vec<BigUint>>()
.to_object(py))
}
let int_pyobject = py.import("builtins")?.getattr("int")?;
Ok(out_mem
.iter()
.map(|x| int_pyobject.call1((x, 2u8)).unwrap())
.collect::<Vec<_>>()
.to_object(py))
Copy link
Member

Choose a reason for hiding this comment

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

Depending on when we merge this, there's a PR on PyO3 to add support for num-bigint+abi3 in the works: PyO3/pyo3#3198.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a comment about this inline. I do wonder if there is a measurable performance difference here between doing Rust str -> biguint -> python int vs doing rust str -> python str -> python int.

} else {
Ok(out_mem.to_object(py))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ crate-type = ["cdylib"]

[dependencies]
hashbrown = "0.13.2"
pyo3 = { version = "0.18.3", features = ["extension-module"] }
pyo3 = { version = "0.18.3", features = ["extension-module", "abi3"] }
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@
"crates/accelerate/Cargo.toml",
binding=Binding.PyO3,
debug=rust_debug,
py_limited_api=True
),
RustExtension(
"qiskit._qasm2", "crates/qasm2/Cargo.toml", binding=Binding.PyO3, debug=rust_debug
"qiskit._qasm2", "crates/qasm2/Cargo.toml", binding=Binding.PyO3, debug=rust_debug, py_limited_api=True
),
],
zip_safe=False,
Expand Down