Skip to content
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

retworkx.generators.hexagonal_lattice_graph does not generate consecutive nodes #373

Closed
1ucian0 opened this issue Jun 25, 2021 · 1 comment · Fixed by #397
Closed

retworkx.generators.hexagonal_lattice_graph does not generate consecutive nodes #373

1ucian0 opened this issue Jun 25, 2021 · 1 comment · Fixed by #397
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@1ucian0
Copy link
Member

1ucian0 commented Jun 25, 2021

Information

  • retworkx version: main
  • Python version: 3.8

While generating hexagonal_lattice_graph I noticed that the generated node indexes are not consecutive. This seems unexpected to me.

What is the current behavior?

import retworkx
G = retworkx.generators.hexagonal_lattice_graph(10, 10)
offset = 0
for i, j in enumerate(G.node_indexes()):
    if i+offset != j :
        offset += 1
        print(i, 'is missing')
21 is missing
219 is missing

What is the expected behavior?

Consecutive node indexes.

@1ucian0 1ucian0 added the bug Something isn't working label Jun 25, 2021
@mtreinish mtreinish added the good first issue Good for newcomers label Jun 25, 2021
@mtreinish
Copy link
Member

mtreinish commented Jun 25, 2021

It is a documented limitation: https://qiskit.org/documentation/retworkx/stubs/retworkx.generators.hexagonal_lattice_graph.html#retworkx.generators.hexagonal_lattice_graph but I agree it would be better to have all the nodes in order.

It was something I raised in review #277 (comment) and it apparently wasn't a straightforward fix. But if you have a solution for doing this I think it would definitely be a welcome fix.

mtreinish pushed a commit that referenced this issue Jul 28, 2021
This commit modifies hexagonal_lattice_graph and directed_hexagonal_lattice_graph to
create graphs with consecutive node indices. This is possible with minor changes in the
logic of the original source code, roughly we should shift the node indexes by one (or
two in the last column) except the first column that we don't need a shift.

This is important if we ever use these functions to generate a CouplingMap in terra
where the underlying graph assumes consecutive node indices.

Closes #373.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants