Skip to content

Commit

Permalink
Bump PyO3 and rust-numpy to 0.23 (#1364)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mtreinish authored Jan 16, 2025
1 parent 51e2830 commit c05a583
Show file tree
Hide file tree
Showing 19 changed files with 376 additions and 367 deletions.
97 changes: 52 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ license = "Apache-2.0"
[workspace.dependencies]
ahash = "0.8.6"
fixedbitset = "0.5.7"
hashbrown = { version = ">=0.13, <0.15", features = ["rayon"] }
indexmap = { version = ">=1.9, <3", features = ["rayon"] }
ndarray = { version = "0.16.1", features = ["rayon"] }
num-traits = "0.2"
numpy = "0.22"
petgraph = "0.7.0"
hashbrown = { version = ">=0.13, <0.16", features = ["rayon"] }
numpy = "0.23"
rand = "0.8"
rand_pcg = "0.3"
rayon = "1.10"
Expand Down Expand Up @@ -63,20 +63,14 @@ rustworkx-core = { path = "rustworkx-core", version = "=0.16.0" }
flate2 = "1.0.35"

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

[dependencies.sprs]
version = "^0.11"
default-features = false
features = ["multi_thread"]

[features]
default = []
# TODO: remove this once PyO3 is updated to 0.23. Currently, this is a bug in PyO3 0.22
# that leaks some of their features in a public macro. However, this was removed in 0.23.
gil-refs = ["pyo3/gil-refs"]

[profile.release]
lto = 'fat'
codegen-units = 1
23 changes: 12 additions & 11 deletions src/cartesian_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use petgraph::visit::{EdgeRef, IntoEdgeReferences, IntoNodeReferences};
use petgraph::{algo, EdgeType};

use pyo3::prelude::*;
use pyo3::IntoPyObjectExt;
use pyo3::Python;

fn cartesian_product<Ty: EdgeType>(
py: Python,
first: &StablePyGraph<Ty>,
second: &StablePyGraph<Ty>,
) -> (StablePyGraph<Ty>, ProductNodeMap) {
) -> PyResult<(StablePyGraph<Ty>, ProductNodeMap)> {
let mut final_graph = StablePyGraph::<Ty>::with_capacity(
first.node_count() * second.node_count(),
first.node_count() * second.edge_count() + first.edge_count() * second.node_count(),
Expand All @@ -35,7 +36,7 @@ fn cartesian_product<Ty: EdgeType>(

for (x, weight_x) in first.node_references() {
for (y, weight_y) in second.node_references() {
let n0 = final_graph.add_node((weight_x, weight_y).into_py(py));
let n0 = final_graph.add_node((weight_x, weight_y).into_py_any(py)?);
hash_nodes.insert((x, y), n0);
}
}
Expand Down Expand Up @@ -65,7 +66,7 @@ fn cartesian_product<Ty: EdgeType>(
.collect(),
};

(final_graph, out_node_map)
Ok((final_graph, out_node_map))
}

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

(
Ok((
graph::PyGraph {
graph: out_graph,
multigraph: true,
node_removed: false,
attrs: py.None(),
},
out_node_map,
)
))
}

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

(
Ok((
digraph::PyDiGraph {
graph: out_graph,
cycle_state: algo::DfsSpace::default(),
Expand All @@ -167,5 +168,5 @@ pub fn digraph_cartesian_product(
attrs: py.None(),
},
out_node_map,
)
))
}
Loading

0 comments on commit c05a583

Please sign in to comment.