-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
coupling_map.subgraph() creates extra nodes #6736
Comments
Right, so if we don't care about retaining node indices (and I agree that it breaks the assumptions of the If for some reason (which I don't think there is any) we want to retain node ids (either by default or with a flag) we can do this, but the easiest way will require a retworkx PR to add an option for that (we can try to do it in python but it will require adding and removing nodes to create index holes as expected). |
Also I think the arg should be a set, not a list. Otherwise we have to renumber the ids based on the order passed, which could be a bit confusing I think. But I need to think about this a bit more. |
At least for the retwork implementation the order of the list isn't preserved. The first thing it does is convert it to a https://github.com/Qiskit/retworkx/blob/main/src/digraph.rs#L2389-L2417 I think that will preserve index sorted order, but I wouldn't count on that as a guarantee either more just a side effect. |
This commit fixes the subgraph() method on the coupling map class when the node list had a non-contiguous list that didn't start at 0. Previously, the subgraph method would inject nodes for the holes in the node list so that all the indices specified in the nodelist argument were present in the output subgraph. But this was neglecting the nodes get reindexed and wasn't valid. This commit fixes this by just removing that step and relying on retworkx's subgraph() method to do the underlying work. Fixes Qiskit#6736
Reading this issue, I've noticed the difference between
(I'm using Another issue, but we could consolidate these two functions into one adding optional args like |
This commit fixes the subgraph() method on the coupling map class when the node list had a non-contiguous list that didn't start at 0. Previously, the subgraph method would inject nodes for the holes in the node list so that all the indices specified in the nodelist argument were present in the output subgraph. But this was neglecting the nodes get reindexed and wasn't valid. This commit fixes this by just removing that step and relying on retworkx's subgraph() method to do the underlying work. Fixes #6736 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
This commit fixes the subgraph() method on the coupling map class when the node list had a non-contiguous list that didn't start at 0. Previously, the subgraph method would inject nodes for the holes in the node list so that all the indices specified in the nodelist argument were present in the output subgraph. But this was neglecting the nodes get reindexed and wasn't valid. This commit fixes this by just removing that step and relying on retworkx's subgraph() method to do the underlying work. Fixes #6736 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> (cherry picked from commit 0c6890d)
) This commit fixes the subgraph() method on the coupling map class when the node list had a non-contiguous list that didn't start at 0. Previously, the subgraph method would inject nodes for the holes in the node list so that all the indices specified in the nodelist argument were present in the output subgraph. But this was neglecting the nodes get reindexed and wasn't valid. This commit fixes this by just removing that step and relying on retworkx's subgraph() method to do the underlying work. Fixes #6736 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> (cherry picked from commit 0c6890d) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Trying to get a subgraph of this coupling map:
If I use retworkx directly to get the subgraph on 9 nodes, it gives me this which is correct I think:
But if I do the same using the CouplingMap API I get this. There are incorrect nodes added here:
@mtreinish says this is due to a difference in how networkx and retworkx implement
.subgraph()
. But I like the retworkx output because it numbers nodes as 0-k, and that is consistent with how coupling maps in qiskit are numbered (i.e. no "holes"). So I think something just needs to change here to remove the extra nodes. If we provide an option to keep the original node numberings, I'd be fine with that, but I'm not sure whether Qiskit can actually work with such a coupling map object. The best route I see is to remap the node numbers in the same order (smallest to 0, largest to k).The text was updated successfully, but these errors were encountered: