dwave-networkx icon indicating copy to clipboard operation
dwave-networkx copied to clipboard

Issue with chimera_layout mistaking single tile for multiple tiles.

Open davage opened this issue 6 years ago • 2 comments

Description The chimera_layout function uses the networkx function diameter, which can be > 2 for some configurations of our chimera graphs.

To Reproduce The example on the demo page is working: https://docs.ocean.dwavesys.com/projects/dwave-networkx/en/latest/reference/drawing.html However the following modification will cause an error in which the code mistakes the connected graph for being from two connected tiles: `import networkx as nx import dwave_networkx as dnx import matplotlib.pyplot as plt

H = nx.Graph() H.add_nodes_from([0, 1, 4, 5, 6, 7]) H.add_edges_from([(0, 4), (0, 5), (0, 6), (0, 7)]) H.add_edges_from([(1, 4)]) pos = dnx.chimera_layout(H) G = dnx.chimera_graph(1,1,4) ind = dnx.find_chimera_indices(G) dnx.draw_chimera(G) dnx.draw_chimera(H, node_color='b', node_shape='*', style='dashed', edge_color='b', width=3) dnx.chimera_layout(H, scale=1., center=None, dim=2) plt.show()`

There are a few similar issues, so it might be a good idea to check a few different cases. This one draws as if 2 is 1. H.add_nodes_from([0, 2, 4, 5, 6, 7]) H.add_edges_from([(0, 4), (0, 5), (0, 6), (0, 7)]) H.add_edges_from([(2, 4), (2, 5), (2, 6), (2, 7)])

Expected behavior Partial chimera graphs should draw correctly.

The first example should draw an extra dashed line from node 1 to node 4.

The second example should produce a chimera graph tile with the 0 node and the 2 node fully connected.

Environment:

  • OS: Windows 10 Pro
  • Python version: 3.7.1

Additional context This issue showed up from a user trying to run the example in drawing chimera graph functions: https://github.com/dwavesystems/dwave_networkx/issues/90

davage avatar Jan 04 '19 22:01 davage

I think this and #90 are non-issues. I found these while trying to do something similar, i.e. create a chimera graph by adding custom nodes and edges.

But I don't expect it to work in the way that is exemplified here because (1) the H graph isn't created as a chimera_graph to begin with. (2) even if it is, adding nodes would need to be done in a way that modifies the corresponding graph dictionary, or invalidates it.

So... either use the method in my next post, or there needs to be ~a Chimera graph class~ (Not the way NetworkX is supposed to be used) or interfaces to incrementally construct Chimera/Pegasus graphs e.g. dnx.add_chimera_nodes_from(H, <nodes>) dnx.add_chimera_edges_from(H, <edges>) dnx.add_pegasus_...

Or... a way to "Chimerify" (?) or "Pegasify" (?) graphs.

joseppinilla avatar Jul 15 '19 19:07 joseppinilla

The way I would do it right now is:

node_list = [0, 1, 4, 5, 6, 7]
edge_list = [(0, 4), (0, 5), (0, 6), (0, 7), (1, 4)]
H = dnx.chimera_graph(1,1,node_list=node_list,edge_list=edge_list)
...
dnx.draw_chimera(H, node_color='b', node_shape='*', style='dashed', edge_color='b', width=3)

joseppinilla avatar Jul 15 '19 19:07 joseppinilla