-
Notifications
You must be signed in to change notification settings - Fork 163
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
Use Vector
for intermediate computations in Dijkstra
#493
Conversation
Pull Request Test Coverage Report for Build 1699742967
💛 - Coveralls |
HashMap
for intermediate computations in DijkstraVector
for intermediate computations in Dijkstra
Tried using |
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.
While we are here, we could also see if there is any performance benfit replacing BinaryHeap
with a QuaternaryHeap
. At least, BGL (that graph-tool depends on) uses a 4-ary heap.
That crate seems a bit too young, I will hold on the Quaternary Heap for a bit. The MSRVs are incompatible as well. |
Edit: I removed the QuaternaryHeap, the bottleneck is not there so I will save it for another PR when we benchmark with more details. I added the QuaternaryHeap, they had a version without const generics with Rust MSRV 1.31 |
@mtreinish I think the biggest culprit is https://github.com/Qiskit/retworkx/blob/main/src/shortest_path/mod.rs#L221-L231, every time we map through a HashMap/DictMap we allocate more memory. Because DictMap uses more memory and the graph had millions of nodes, the results got worse. The code I have now is not the cleanest, but it creates a DictMap only once. That does lower the performance regression |
This reverts commit 4a17a25.
@IvanIsCoding yeah that does the trick now. Running the benchmarks again it's faster than 0.10.2 now: |
I will try to clean the code for this one, and flag other similar cases in #492. |
…x into dijkstra-regression
It's great that we managed to fixed the regression! Having two separate functions
|
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.
I left some inline comments. Apart from that, it's weird that we use internally a vector for the computation in dijkstra_shortest_path_lengths
but a DictMap
in dijkstra_shortest_paths
. For maximum flexibility and control over memory - speed trade-off, it seems a good choice to add a kwarg sparse
in order to let users choose which data structure best fits their needs.
I addressed the comments, but I think adding a |
Yeah, it's ok to make a choice for the users but then why not use a vector internally for |
I've updated the PR to include that as well |
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 LGTM, thanks for keeping with this. The code looks great and the performance definitely is where we want it to be:
It'd be good if @georgios-ts gave this a look too since he had comments on earlier revisions.
I just had two quick comments inline about the documentation and comments before we merge this around the DistanceMap
trait. It might be worth manually checking the cargo doc
output to verify how it renders.
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 and performance looks great!
Co-authored-by: georgios-ts <[email protected]>
* Sort Dijkstra output at the end * Handle dense cases at the end * Change condition for sorting output * Use Vector for intermediate calculations * Use vector in k_shortest_path * Address clippy comments * Fix bug * Incorporate feedback from PR * Add quaternary heap * Fix steiner tree test * Avoid creating duplicated dictmaps * Revert "Fix steiner tree test" This reverts commit 4a17a25. * Add tests and docstring * Use trait to reduce duplication * Move DistanceMap to its own file * Use DistanceMap in k_shortest_path * Add test coverage * Support HashMap in DistanceMap * Remove type casting * Remove unnecessary IndexType * Use Vector in dijkstra_shortest_paths and all_pairs_dijkstra_path_lengths * Update distancemap.rs * Update retworkx-core/src/distancemap.rs Co-authored-by: georgios-ts <[email protected]> * Add docstrings * Cargo fmt Co-authored-by: georgios-ts <[email protected]>
Related to #492
Replaces
DictMap
withVector
for intermediate computations in our Dijkstra's implementation.DictMap
to store the scores, we use aVector
and create theDictMap
the end. That way, users can get a nice deterministic output and we can keep computations fast