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

draw_chimera_embedding does not plot the desired embedded graph #188

Open
jlaydevant opened this issue Feb 25, 2021 · 1 comment
Open

draw_chimera_embedding does not plot the desired embedded graph #188

jlaydevant opened this issue Feb 25, 2021 · 1 comment
Labels

Comments

@jlaydevant
Copy link

jlaydevant commented Feb 25, 2021

I want to plot an embedded graph on a chimera lattice with the command dnx.draw_chimera_embedding() of a simple system of 5 or more nodes consecutively connected (but with no loop between the first and last node):
J={(0, 1): 1, (0, 2): 1, (1, 3): 1, (2, 3): 1}

But when I use the drawing command it eventually plots some graphs where some units have more connections than expected and even some graphs are cycle despite the first and last unit should not be connected.

The embedded graph generated by minorminer.find_embedding() if fine so the issue is about the drawing function.

Here is the code to reproduce the issue:

layersList = [1,1,1,1,1]
h, J = {}, {}

comp0, comp1 = 0, layersList[0]

for i in range(len(layersList)-1):
    for k in range(layersList[i]):
        h.update({k + comp0:-1})
        for j in range(layersList[i+1]):
            J.update({(k + comp0, j + comp1):1})
            
    comp0 += layersList[i]
    comp1 += layersList[i+1]
    
for k in range(layersList[-1]):
    h.update({k + comp0:-1})
   
import dwave_networkx as dnx
# select basic graph on which move our computational graph
connectivity_structure = dnx.chimera_graph(2, 2)
    
from minorminer import find_embedding

import matplotlib.pyplot as plt

for k in range(10):
    plt.figure()
    emb = find_embedding(J, connectivity_structure)
    inter = [edge for edge in J]
    dnx.draw_chimera_embedding(connectivity_structure, emb, show_labels = True, interaction_edges = inter, overlapped_embedding = False)
plt.show()

I eventually found a way to overcome this issue on the file /dwave-networkx/dwave_networkx/drawing/qubit_layout.py line 292 where def show(p, q, u, v): return interactions.has_edge(p, q) should be changed to def show(p, q, u, v): return interactions.has_edge(u, v). Then with this changement the code works very fine.

@jlaydevant jlaydevant changed the title draw_chimera_embedding does not plot the embedded graph wanted draw_chimera_embedding does not plot the desired embedded graph Feb 25, 2021
@arcondello
Copy link
Member

Hi @JeremLay , that does appear to be a bug. Would you like to make a PR with your proposed change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants