Skip to content

Commit

Permalink
Update PyO3 and Rust Numpy to 0.18.0 (#787)
Browse files Browse the repository at this point in the history
* Update PyO3 and Rust Numpy to 0.18.0

The latest releases of PyO3 and rust numpy were just released. The
changelogs for both can be found at:

https://pyo3.rs/v0.18.0/changelog

and

https://github.com/PyO3/rust-numpy/blob/main/CHANGELOG.md

Since the two releases are tightly coupled this commit opts to update
them together instead of the normal dependabot workflow. Similarly some
of our usage (mainly around signatures and argument ordering) for
building a python interface using PyO3 has been deprecated. That usage
is also updated in this PR to avoid compilation warnings, which will be
treated as errors by clippy in CI.

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
  • Loading branch information
mtreinish and IvanIsCoding authored Feb 1, 2023
1 parent 745862b commit a297e7f
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 189 deletions.
45 changes: 30 additions & 15 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ crate-type = ["cdylib"]
ahash = "0.8.0"
petgraph = "0.6.2"
fixedbitset = "0.4.2"
numpy = "0.17.2"
numpy = "0.18.0"
rand = "0.8"
rand_pcg = "0.3"
rayon = "1.6"
Expand All @@ -35,7 +35,7 @@ serde_json = "1.0"
rustworkx-core = { path = "rustworkx-core", version = "=0.13.0" }

[dependencies.pyo3]
version = "0.17.3"
version = "0.18.0"
features = ["extension-module", "hashbrown", "num-bigint", "num-complex", "indexmap"]

[dependencies.hashbrown]
Expand Down
38 changes: 34 additions & 4 deletions src/centrality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ use rustworkx_core::centrality;
/// :returns: a read-only dict-like object whose keys are the node indices and values are the
/// betweenness score for each node.
/// :rtype: CentralityMapping
#[pyfunction(normalized = "true", endpoints = "false", parallel_threshold = "50")]
#[pyfunction(
signature = (
graph,
normalized=true,
endpoints=false,
parallel_threshold=50
)
)]
#[pyo3(text_signature = "(graph, /, normalized=True, endpoints=False, parallel_threshold=50)")]
pub fn graph_betweenness_centrality(
graph: &graph::PyGraph,
Expand Down Expand Up @@ -119,7 +126,14 @@ pub fn graph_betweenness_centrality(
/// :returns: a read-only dict-like object whose keys are the node indices and values are the
/// betweenness score for each node.
/// :rtype: CentralityMapping
#[pyfunction(normalized = "true", endpoints = "false", parallel_threshold = "50")]
#[pyfunction(
signature = (
graph,
normalized=true,
endpoints=false,
parallel_threshold=50
)
)]
#[pyo3(text_signature = "(graph, /, normalized=True, endpoints=False, parallel_threshold=50)")]
pub fn digraph_betweenness_centrality(
graph: &digraph::PyDiGraph,
Expand Down Expand Up @@ -172,7 +186,15 @@ pub fn digraph_betweenness_centrality(
/// :returns: a read-only dict-like object whose keys are the node indices and values are the
/// centrality score for that node.
/// :rtype: CentralityMapping
#[pyfunction(default_weight = "1.0", max_iter = "100", tol = "1e-6")]
#[pyfunction(
signature = (
graph,
weight_fn=None,
default_weight=1.0,
max_iter=100,
tol=1e-6
)
)]
#[pyo3(text_signature = "(graph, /, weight_fn=None, default_weight=1.0, max_iter=100, tol=1e-6)")]
pub fn graph_eigenvector_centrality(
py: Python,
Expand Down Expand Up @@ -251,7 +273,15 @@ pub fn graph_eigenvector_centrality(
/// :returns: a read-only dict-like object whose keys are the node indices and values are the
/// centrality score for that node.
/// :rtype: CentralityMapping
#[pyfunction(default_weight = "1.0", max_iter = "100", tol = "1e-6")]
#[pyfunction(
signature = (
graph,
weight_fn=None,
default_weight=1.0,
max_iter=100,
tol=1e-6
)
)]
#[pyo3(text_signature = "(graph, /, weight_fn=None, default_weight=1.0, max_iter=100, tol=1e-6)")]
pub fn digraph_eigenvector_centrality(
py: Python,
Expand Down
14 changes: 10 additions & 4 deletions src/connectivity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ pub fn is_weakly_connected(graph: &digraph::PyDiGraph) -> PyResult<bool> {
///
/// :return: The adjacency matrix for the input directed graph as a numpy array
/// :rtype: numpy.ndarray
#[pyfunction(default_weight = "1.0", null_value = "0.0")]
#[pyo3(text_signature = "(graph, /, weight_fn=None, default_weight=1.0, null_value=0.0)")]
#[pyfunction]
#[pyo3(
signature=(graph, weight_fn=None, default_weight=1.0, null_value=0.0),
text_signature = "(graph, /, weight_fn=None, default_weight=1.0, null_value=0.0)"
)]
pub fn digraph_adjacency_matrix(
py: Python,
graph: &digraph::PyDiGraph,
Expand Down Expand Up @@ -341,8 +344,11 @@ pub fn digraph_adjacency_matrix(
///
/// :return: The adjacency matrix for the input graph as a numpy array
/// :rtype: numpy.ndarray
#[pyfunction(default_weight = "1.0", null_value = "0.0")]
#[pyo3(text_signature = "(graph, /, weight_fn=None, default_weight=1.0, null_value=0.0)")]
#[pyfunction]
#[pyo3(
signature=(graph, weight_fn=None, default_weight=1.0, null_value=0.0),
text_signature = "(graph, /, weight_fn=None, default_weight=1.0, null_value=0.0)"
)]
pub fn graph_adjacency_matrix(
py: Python,
graph: &graph::PyGraph,
Expand Down
7 changes: 5 additions & 2 deletions src/dag_algo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,11 @@ pub fn is_directed_acyclic_graph(graph: &digraph::PyDiGraph) -> bool {
/// :rtype: list
///
/// :raises InvalidNode: If a node index in ``first_layer`` is not in the graph
#[pyfunction(index_output = "false")]
#[pyo3(text_signature = "(dag, first_layer, /, index_output=False)")]
#[pyfunction]
#[pyo3(
signature=(dag, first_layer, index_output=false),
text_signature = "(dag, first_layer, /, index_output=False)"
)]
pub fn layers(
py: Python,
dag: &digraph::PyDiGraph,
Expand Down
26 changes: 11 additions & 15 deletions src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// License for the specific language governing permissions and limitations
// under the License.

#![allow(clippy::borrow_as_ptr)]
#![allow(clippy::borrow_as_ptr, clippy::redundant_closure)]

use std::cmp;
use std::cmp::Ordering;
Expand Down Expand Up @@ -285,7 +285,7 @@ impl PyDiGraph {
#[pymethods]
impl PyDiGraph {
#[new]
#[args(check_cycle = "false", multigraph = "true")]
#[pyo3(signature=(check_cycle=false, multigraph=true, attrs=None))]
fn new(py: Python, check_cycle: bool, multigraph: bool, attrs: Option<PyObject>) -> Self {
PyDiGraph {
graph: StablePyGraph::<Directed>::new(),
Expand Down Expand Up @@ -322,7 +322,7 @@ impl PyDiGraph {

fn __setstate__(&mut self, py: Python, state: PyObject) -> PyResult<()> {
self.graph = StablePyGraph::<Directed>::new();
let dict_state = state.cast_as::<PyDict>(py)?;
let dict_state = state.downcast::<PyDict>(py)?;

let nodes_dict = dict_state.get_item("nodes").unwrap().downcast::<PyDict>()?;
let edges_list = dict_state.get_item("edges").unwrap().downcast::<PyList>()?;
Expand Down Expand Up @@ -908,7 +908,7 @@ impl PyDiGraph {
/// would only retain edges if the input edge to ``node`` had the same
/// data payload as the outgoing edge.
#[pyo3(text_signature = "(self, node, /, use_outgoing=None, condition=None)")]
#[args(use_outgoing = "false")]
#[pyo3(signature=(node, use_outgoing=false, condition=None))]
pub fn remove_node_retain_edges(
&mut self,
py: Python,
Expand Down Expand Up @@ -1495,7 +1495,7 @@ impl PyDiGraph {
/// :returns: A list of the edge indices incident to a node in the graph
/// :rtype: EdgeIndices
#[pyo3(text_signature = "(self, node, /, all_edges=False)")]
#[args(all_edges = "false")]
#[pyo3(signature=(node, all_edges=false))]
pub fn incident_edges(&self, node: usize, all_edges: bool) -> EdgeIndices {
let node_index = NodeIndex::new(node);
if all_edges {
Expand Down Expand Up @@ -1538,7 +1538,7 @@ impl PyDiGraph {
/// ``(source, target, data)``
/// :rtype: EdgeIndexMap
#[pyo3(text_signature = "(self, node, /, all_edges=False)")]
#[args(all_edges = "false")]
#[pyo3(signature=(node, all_edges=false))]
pub fn incident_edge_index_map(
&self,
py: Python,
Expand Down Expand Up @@ -1876,7 +1876,7 @@ impl PyDiGraph {
/// mpl_draw(graph)
///
#[staticmethod]
#[args(labels = "false")]
#[pyo3(signature=(path, comment=None, deliminator=None, labels=false))]
#[pyo3(text_signature = "(path, /, comment=None, deliminator=None, labels=False)")]
pub fn read_edge_list(
py: Python,
Expand Down Expand Up @@ -2051,8 +2051,7 @@ impl PyDiGraph {
/// :returns: A new graph object generated from the adjacency matrix
/// :rtype: PyDiGraph
#[staticmethod]
#[args(null_value = "0.0")]
#[pyo3(text_signature = "(matrix, /, null_value=0.0)")]
#[pyo3(signature=(matrix, null_value=0.0), text_signature = "(matrix, /, null_value=0.0)")]
pub fn from_adjacency_matrix<'p>(
py: Python<'p>,
matrix: PyReadonlyArray2<'p, f64>,
Expand Down Expand Up @@ -2088,8 +2087,7 @@ impl PyDiGraph {
/// :returns: A new graph object generated from the adjacency matrix
/// :rtype: PyDiGraph
#[staticmethod]
#[args(null_value = "Complex64::zero()")]
#[pyo3(text_signature = "(matrix, /, null_value=0.0+0.0j)")]
#[pyo3(signature=(matrix, null_value=Complex64::zero()), text_signature = "(matrix, /, null_value=0.0+0.0j)")]
pub fn from_complex_adjacency_matrix<'p>(
py: Python<'p>,
matrix: PyReadonlyArray2<'p, Complex64>,
Expand Down Expand Up @@ -2497,8 +2495,7 @@ impl PyDiGraph {
/// the other.
/// :rtype: PyGraph
///
#[args(preserve_attrs = "false")]
#[pyo3(text_signature = "(self, nodes, /, preserve_attrs=False)")]
#[pyo3(signature=(nodes, preserve_attrs=false),text_signature = "(self, nodes, /, preserve_attrs=False)")]
pub fn subgraph(&self, py: Python, nodes: Vec<usize>, preserve_attrs: bool) -> PyDiGraph {
let node_set: HashSet<usize> = nodes.iter().cloned().collect();
let mut node_map: HashMap<NodeIndex, NodeIndex> = HashMap::with_capacity(nodes.len());
Expand Down Expand Up @@ -2637,8 +2634,7 @@ impl PyDiGraph {
/// :returns: A new PyGraph object with an undirected edge for every
/// directed edge in this graph
/// :rtype: PyGraph
#[pyo3(text_signature = "(self, /, multigraph=True, weight_combo_fn=None)")]
#[args(multigraph = "true", weight_combo_fn = "None")]
#[pyo3(signature=(multigraph=true, weight_combo_fn=None), text_signature = "(self, /, multigraph=True, weight_combo_fn=None)")]
pub fn to_undirected(
&self,
py: Python,
Expand Down
Loading

0 comments on commit a297e7f

Please sign in to comment.