Add longest_path_length to rustworkx_core::dag_algo#1605
Merged
IvanIsCoding merged 3 commits intoJun 18, 2026
Conversation
This commit builds off of Qiskit#1577 which improved the performance of the `longest_path` function to avoid allocating on each iteration of the loop. It was pointed out in that PR and Qiskit#1563 that storing and returning a path for applications that only care about the length is unnecessary overhead. To provide an option for such cases a new function is added to offer a better alternative for these use cases.
Since path weights might be floating point numbers or other types which don't implment Ord we need to handle the case where the comparison isn't possible (e.g. for floats the presence of NaN). Previously we just were treating this as equal which is not correct. This commit updates the logic in the path length function to just return None in the presence of non comparable elements along the longest path and adds documentation to tell users about this and suggestions on how to handle this case in the weight functions.
Member
Author
|
I forgot to put in the commit message, but the reason for the seeming duplication here is that internally I changed the typing of the |
IvanIsCoding
approved these changes
Jun 18, 2026
IvanIsCoding
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. The tests are good, existing test pass. It should be an easy merge. It is bound to be faster than the code we had before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit builds off of #1577 which improved the performance of the
longest_pathfunction to avoid allocating on each iteration of the loop. It was pointed out in that PR and #1563 that storing and returning a path for applications that only care about the length is unnecessary overhead. To provide an option for such cases a new function is added to offer a better alternative for these use cases.