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

chimera_graph mxn lattice is flattened

Open JoelPasvolsky opened this issue 3 years ago • 4 comments

Description I expected that chimera_graph(m) or chimera_graph(m,m) would have be a m-by-m lattice but instead am getting a row of length mxm.

To Reproduce

>>> c4 = dnx.chimera_graph(4)
>>> c4.nodes
NodeView((0, 4, 5, 6, 7, 1, 2, 3, 32, 36, 37, 38, 39, 33, 34, 35, 64, 68, 69, 70, 71, 65, 66, 67, 96, 100, 101, 102, 103, 97, 98, 99, 8, 12, 13, 14, 15, 9, 10, 11, 40, 44, 45, 46, 47, 41, 42, 43, 72, 76, 77, 78, 79, 73, 74, 75, 104, 108, 109, 110, 111, 105, 106, 107, 16, 20, 21, 22, 23, 17, 18, 19, 48, 52, 53, 54, 55, 49, 50, 51, 80, 84, 85, 86, 87, 81, 82, 83, 112, 116, 117, 118, 119, 113, 114, 115, 24, 28, 29, 30, 31, 25, 26, 27, 56, 60, 61, 62, 63, 57, 58, 59, 88, 92, 93, 94, 95, 89, 90, 91, 120, 124, 125, 126, 127, 121, 122, 123))

This gives:

image

Expected behavior I expected:

image

Environment:

  • OS: WIN10
  • Python version: 3.7.0

Additional context Add any other context about the problem here.

JoelPasvolsky avatar Mar 05 '21 19:03 JoelPasvolsky

I think this is a problem with the inspector and not the chimera graph generator.

import dwave_networkx as dnx
from matplotlib import pyplot as plt

c4 = dnx.chimera_graph(4, 4)
plt.figure(figsize=(5,5))
dnx.draw_chimera(c4)
plt.savefig('c4.png')

c4

boothby avatar Mar 05 '21 19:03 boothby

@boothby, the output of dnx.chimera_graph(4) includes node 40, 44, 45, 46, 47, 41, 42, 43. I had expected C4 nodes to be [0, 1 .. 8x4, 8x16, 8x16+1, ... 8x20, 8x20+1, ...] But I guess that assumes C4 as a subgraph of C16. Thanks!

JoelPasvolsky avatar Mar 05 '21 19:03 JoelPasvolsky

You can get that subgraph as follows:

g = dnx.chimera_graph(16)
c4_nodes = [v for v, d in g.nodes(data=True) if all(x < 4 for x in d['chimera_index'][:2])]
c4 = g.subgraph(c4_nodes)

boothby avatar Mar 05 '21 19:03 boothby

Thanks, @boothby, I just changed the first line to g = dnx.chimera_graph(16, node_list=qpu.nodelist, edge_list=qpu.edgelist) to account for available qubits & couplers, and that works perfectly:

image

JoelPasvolsky avatar Mar 05 '21 19:03 JoelPasvolsky