-
Notifications
You must be signed in to change notification settings - Fork 146
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
Save next nodes in Floyd-Warshall numpy variants for path reconstruction #1040
Save next nodes in Floyd-Warshall numpy variants for path reconstruction #1040
Conversation
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.
Thanks for making your first contribution! I agree that we can add predecessors to floydwarshall_numpy
.
However, changing the return type is a breaking change. It will also fail all our tests, which should give you a hint that it is not exactly the change you're looking to make.
Can you create a new function rustworkx.floyd_warshall_predecessor_and_distance
to incorporate the new code? It would be akin to https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance.html
@IvanIsCoding now that the new implementations are separated to not break the existing APIs |
Pull Request Test Coverage Report for Build 7436857178
💛 - Coveralls |
If we choose predecessors to represent shortest paths, it may cause much more change of the parallelism implementation than the case we choose successors. That's why I don't use predecessors. |
I won’t have time to review this week but I hope to get a review by January 2. In the meantime, I encourage you to write unit tests. You can simply copy the existing Floyd Warshall test cases and reuse them for the new methods |
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.
Overall the code looks correct, thanks for implementing it!
There are two items we need to address however:
- It would be best to split the code path for the predecessors from the code path for Floyd Warshall Numpy. The additional overhead of the extra memory doubles the memory consumption in a function that already uses O(n^2) memory. So I'd rather keep the constant down
- We need to add tests for correctness. See https://github.com/Qiskit/rustworkx/blob/main/tests/rustworkx_tests/graph/test_floyd_warshall.py and https://github.com/Qiskit/rustworkx/blob/main/tests/rustworkx_tests/digraph/test_floyd_warshall.py for examples
@IvanIsCoding
It's done. |
6a032b8
to
37f3973
Compare
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.
LGTM, thanks for making your first contribution!
I am going to merge this soon, but as a last step can you add it to the docs? These are the files you need to change:
docs/source/api/algorithm_functions/shortest_paths.rst
docs/source/api/pygraph_api_functions.rst
docs/source/api/pydigraph_api_functions.rst
You will also need to write a short docstring adding a description of the function you implemented. I can do it for you if you want
@IvanIsCoding Can you please tell me the file location where to add a docstring? |
You add a comment in the Rust code. See the Floyd Warshall one for example: rustworkx/src/shortest_path/mod.rs Line 868 in 99f9756
|
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.
LGTM, I will add the release notes and merge it today. Thanks for your contribution!
I don't have permission to edit your branch so I will merge this and add the release notes in a new PR |
…or_and_distance` (#1049) Follow up of #1040 This adds the release notes, universal function, and shortens the name of the new floyd_warshall_successor_and_distance * Save next nodes in Floyd-Warshall numpy variants * Create `graph_floyd_warshall_successor_and_distance_numpy` * Reformat * Split a function by by `generate_successors` * Add testcases * Add the functions to docs * Add docstring to Rust code * Change name and add universal function * Add release notes --------- Co-authored-by: maleicacid <maleicacid824+dev@gmail.com>
This PR adds "next node" matrix to the Floyd-Warshall implementations' return value.
This helps re-construct the shortest path from the result.
digraph_floyd_warshall_numpy
andgraph_floyd_warshall_numpy
return two variable by applying this patch. In recent version, they returned only a length table.The next node table is inherently dense, even though the graph is sparse. To not break the advantage of the implementation optimized for the sparse graph, I modified only numpy variants.