Ensure uniqueness of nodes in neighbors()#5847
Merged
mergify[bot] merged 3 commits intoFeb 15, 2021
Merged
Conversation
Changes in Qiskit#5411, to use retworkx's neighbors() function, replaces the returned dict with an iterator. In the dict version, neighbor node indices are the keys and therefore, they are unique. In the iterator version, node indices appear multiple times, once per edge in multigraphs. This commit use a Python set to preserve the semantics of the old version ensuring the uniqueness of the nodes.
mtreinish
approved these changes
Feb 15, 2021
Member
mtreinish
left a comment
There was a problem hiding this comment.
This LGTM, it might be good to leave a comment here about why we're casting to a set. Assuming we fix the behavior on the retworkx side the set() cast will be unnecessary with a future retworkx release (and will add overhead). But not worth blocking over.
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Mar 3, 2021
In Qiskit#5847 we added a set() cast to calls to retworkx's graph neighbors method. This was to workaround a bug in retworkx where duplicate node indices would be returned if there were parallel edges to a successor node. In the recent retworkx 0.8.0 release this issue has been fixed [1][2] so there is no need to cast to a set anymore. Removing the set cast will remove a duplicate iteration (to generate the set) over the neighbors list, marginally improving performance. [1] https://retworkx.readthedocs.io/en/stable/release_notes.html#bug-fixes [2] Qiskit/rustworkx@49727f8
mergify Bot
pushed a commit
that referenced
this pull request
Mar 3, 2021
In #5847 we added a set() cast to calls to retworkx's graph neighbors method. This was to workaround a bug in retworkx where duplicate node indices would be returned if there were parallel edges to a successor node. In the recent retworkx 0.8.0 release this issue has been fixed [1][2] so there is no need to cast to a set anymore. Removing the set cast will remove a duplicate iteration (to generate the set) over the neighbors list, marginally improving performance. [1] https://retworkx.readthedocs.io/en/stable/release_notes.html#bug-fixes [2] Qiskit/rustworkx@49727f8
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.
Summary
Fixes #5530
Changes in #5411, to use retworkx's neighbors() function, replaces the
returned dict with an iterator. In the dict version, neighbor node indices
are the keys and therefore, they are unique. In the iterator version, node
indices appear multiple times, once per edge in multigraphs.
This commit uses a Python set to preserve the semantics of the old version
ensuring the uniqueness of the nodes.
Details and comments