-
Notifications
You must be signed in to change notification settings - Fork 193
Add NodeIndices return type #198
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
Conversation
This commit adds a new return type NodeIndices that is used as the return type for functions that return Vec<usize> when its used as the return type to return a list of node indices. This custom type implements the Python sequence protocol and can be used as the list which was previously returned except for where explicit type checking was used. Just as in Qiskit#185 the advantage here is that for large lists of node indices the type conversion from a Vec<usize> to list(int) becomes a large bottleneck. This avoids that conversion and only does a usize to python int conversion on access. Related to Qiskit#71
Pull Request Test Coverage Report for Build 372748559
💛 - Coveralls |
In Qiskit#5117 the noise adaptive layout pass was updated to use retworkx internally for performance. In that PR there were a couple of TODO comments added about using neighbors methods when they were released. The retworkx 0.6.0 release was pushed last week so we can update the usage and remove the TODO comments. The neighbors methods should have lower overhead since it only returns a list of node indices instead of a dictionary of (node index, edge weight). This will also get significantly faster (for large neighbors lists) with Qiskit/rustworkx#198.
/// | ||
/// :raises Exception: If an unexpected error occurs or a path can't be found | ||
/// :raises DAGHasCycle: If the input PyDiGraph has a cycle | ||
#[pyfunction] | ||
#[text_signature = "(graph, /)"] | ||
fn dag_longest_path(graph: &digraph::PyDiGraph) -> PyResult<Vec<usize>> { | ||
longest_path(graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like longest_path
still returns PyResult<Vec<usize>>
. Should that not be updated to NodeIndices
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to leave it returning Vec<usize>
because dag_longest_path_length
calls it too. I actually did that in the first rev before pushing this and it errored because there is no len()
on NodeIndices
it felt easier to leave it like this and have dag_longest_path
just move the result into the NodeIndices
struct as the return and leave it as a Vec<usize>
for the other method
Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
This commit adds 2 new return types EdgeList and WeightedEdgeList that are used as the return type for functions that return Vec<(usize, usize)> and Vec<(usize, usize, PyObject)> respectively. This custom type implements the Python sequence protocol and can be used as the list which was previously returned except for where explicit type checking was used. Just as in Qiskit#185 and Qiskit#198 the advantage here is that for large edge lists the conversion from Rust to a Python type becomes a large bottleneck. This avoids that conversion and only does it per element on access.
I ran some benchmarks on this from https://github.com/mtreinish/retworkx-bench before merging and forgot to paste here. The numbers for the hosted bencharks are running now and when they finish it'll be updated on https://mtreinish.github.io/retworkx-bench/ but for now this is what it shows:
|
* Add EdgeList and WeightedEdgeList return types This commit adds 2 new return types EdgeList and WeightedEdgeList that are used as the return type for functions that return Vec<(usize, usize)> and Vec<(usize, usize, PyObject)> respectively. This custom type implements the Python sequence protocol and can be used as the list which was previously returned except for where explicit type checking was used. Just as in #185 and #198 the advantage here is that for large edge lists the conversion from Rust to a Python type becomes a large bottleneck. This avoids that conversion and only does it per element on access. * Add new return types to docs * Apply suggestions from code review Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com> * Fix docstring mistakes * Update in_edges and out_edges to use WeightedEdgeList
In #5117 the noise adaptive layout pass was updated to use retworkx internally for performance. In that PR there were a couple of TODO comments added about using neighbors methods when they were released. The retworkx 0.6.0 release was pushed last week so we can update the usage and remove the TODO comments. The neighbors methods should have lower overhead since it only returns a list of node indices instead of a dictionary of (node index, edge weight). This will also get significantly faster (for large neighbors lists) with Qiskit/rustworkx#198. Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit adds a new return type NodeIndices that is used as the
return type for functions that return Vec when its used as the
return type to return a list of node indices. This custom type implements
the Python sequence protocol and can be used as the list which was
previously returned except for where explicit type checking was used.
Just as in #185 the advantage here is that for large lists of node
indices the type conversion from a Vec to list(int) becomes a
large bottleneck. This avoids that conversion and only does a usize to
python int conversion on access.
Related to #71