Skip to content

Commit c05a583

Browse files
authored
Bump PyO3 and rust-numpy to 0.23 (#1364)
* Bump PyO3 and rust-numpy to 0.23 This commit bumps the version of pyo3 and rust-numpy used by qiskit to the latest release 0.23. The largest change by volume of code is the deprecation of all the *_bound() methods. These are just warnings but they would be fatal to our CI so it needs to be updated. The larger functional change that required updating the code is the change in the traits around converting to Python objects. As a side effect of this change it lets us unify the hashbrown versions installed because we can update indexmap. * Remove unused features section from Cargo.toml
1 parent 51e2830 commit c05a583

File tree

19 files changed

+376
-367
lines changed

19 files changed

+376
-367
lines changed

Cargo.lock

Lines changed: 52 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ license = "Apache-2.0"
2626
[workspace.dependencies]
2727
ahash = "0.8.6"
2828
fixedbitset = "0.5.7"
29-
hashbrown = { version = ">=0.13, <0.15", features = ["rayon"] }
3029
indexmap = { version = ">=1.9, <3", features = ["rayon"] }
3130
ndarray = { version = "0.16.1", features = ["rayon"] }
3231
num-traits = "0.2"
33-
numpy = "0.22"
3432
petgraph = "0.7.0"
33+
hashbrown = { version = ">=0.13, <0.16", features = ["rayon"] }
34+
numpy = "0.23"
3535
rand = "0.8"
3636
rand_pcg = "0.3"
3737
rayon = "1.10"
@@ -63,20 +63,14 @@ rustworkx-core = { path = "rustworkx-core", version = "=0.16.0" }
6363
flate2 = "1.0.35"
6464

6565
[dependencies.pyo3]
66-
version = "0.22.6"
66+
version = "0.23"
6767
features = ["abi3-py39", "extension-module", "hashbrown", "num-bigint", "num-complex", "indexmap", "py-clone"]
6868

6969
[dependencies.sprs]
7070
version = "^0.11"
7171
default-features = false
7272
features = ["multi_thread"]
7373

74-
[features]
75-
default = []
76-
# TODO: remove this once PyO3 is updated to 0.23. Currently, this is a bug in PyO3 0.22
77-
# that leaks some of their features in a public macro. However, this was removed in 0.23.
78-
gil-refs = ["pyo3/gil-refs"]
79-
8074
[profile.release]
8175
lto = 'fat'
8276
codegen-units = 1

src/cartesian_product.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ use petgraph::visit::{EdgeRef, IntoEdgeReferences, IntoNodeReferences};
1919
use petgraph::{algo, EdgeType};
2020

2121
use pyo3::prelude::*;
22+
use pyo3::IntoPyObjectExt;
2223
use pyo3::Python;
2324

2425
fn cartesian_product<Ty: EdgeType>(
2526
py: Python,
2627
first: &StablePyGraph<Ty>,
2728
second: &StablePyGraph<Ty>,
28-
) -> (StablePyGraph<Ty>, ProductNodeMap) {
29+
) -> PyResult<(StablePyGraph<Ty>, ProductNodeMap)> {
2930
let mut final_graph = StablePyGraph::<Ty>::with_capacity(
3031
first.node_count() * second.node_count(),
3132
first.node_count() * second.edge_count() + first.edge_count() * second.node_count(),
@@ -35,7 +36,7 @@ fn cartesian_product<Ty: EdgeType>(
3536

3637
for (x, weight_x) in first.node_references() {
3738
for (y, weight_y) in second.node_references() {
38-
let n0 = final_graph.add_node((weight_x, weight_y).into_py(py));
39+
let n0 = final_graph.add_node((weight_x, weight_y).into_py_any(py)?);
3940
hash_nodes.insert((x, y), n0);
4041
}
4142
}
@@ -65,7 +66,7 @@ fn cartesian_product<Ty: EdgeType>(
6566
.collect(),
6667
};
6768

68-
(final_graph, out_node_map)
69+
Ok((final_graph, out_node_map))
6970
}
7071

7172
/// Return a new PyGraph by forming the cartesian product from two input
@@ -104,18 +105,18 @@ pub fn graph_cartesian_product(
104105
py: Python,
105106
first: &graph::PyGraph,
106107
second: &graph::PyGraph,
107-
) -> (graph::PyGraph, ProductNodeMap) {
108-
let (out_graph, out_node_map) = cartesian_product(py, &first.graph, &second.graph);
108+
) -> PyResult<(graph::PyGraph, ProductNodeMap)> {
109+
let (out_graph, out_node_map) = cartesian_product(py, &first.graph, &second.graph)?;
109110

110-
(
111+
Ok((
111112
graph::PyGraph {
112113
graph: out_graph,
113114
multigraph: true,
114115
node_removed: false,
115116
attrs: py.None(),
116117
},
117118
out_node_map,
118-
)
119+
))
119120
}
120121

121122
/// Return a new PyDiGraph by forming the cartesian product from two input
@@ -154,10 +155,10 @@ pub fn digraph_cartesian_product(
154155
py: Python,
155156
first: &digraph::PyDiGraph,
156157
second: &digraph::PyDiGraph,
157-
) -> (digraph::PyDiGraph, ProductNodeMap) {
158-
let (out_graph, out_node_map) = cartesian_product(py, &first.graph, &second.graph);
158+
) -> PyResult<(digraph::PyDiGraph, ProductNodeMap)> {
159+
let (out_graph, out_node_map) = cartesian_product(py, &first.graph, &second.graph)?;
159160

160-
(
161+
Ok((
161162
digraph::PyDiGraph {
162163
graph: out_graph,
163164
cycle_state: algo::DfsSpace::default(),
@@ -167,5 +168,5 @@ pub fn digraph_cartesian_product(
167168
attrs: py.None(),
168169
},
169170
out_node_map,
170-
)
171+
))
171172
}

0 commit comments

Comments
 (0)