Drawing

Tools to visualize Chimera lattices and weighted graph problems on them.

Note

Some functionality requires NumPy and/or Matplotlib.

Chimera Graph Functions

chimera_layout(G[, scale, center, dim]) Positions the nodes of graph G in a Chimera cross topology.
draw_chimera(G, **kwargs) Draws graph G in a Chimera cross topology.

Example

This example uses the chimera_layout() function to show the positions of nodes of a simple 5-node NetworkX graph in a Chimera lattice. It then uses the chimera_graph() and draw_chimera() functions to display those positions on a Chimera unit cell.

>>> import networkx as nx
>>> import dwave_networkx as dnx
>>> import matplotlib.pyplot as plt
>>> H = nx.Graph()
>>> H.add_nodes_from([0, 4, 5, 6, 7])
>>> H.add_edges_from([(0, 4), (0, 5), (0, 6), (0, 7)])
>>> pos=dnx.chimera_layout(H)
>>> pos
{0: array([ 0. , -0.5]),
 4: array([ 0.5,  0. ]),
 5: array([ 0.5 , -0.25]),
 6: array([ 0.5 , -0.75]),
 7: array([ 0.5, -1. ])}
>>> # Show graph H on a Chimera unit cell
>>> plt.ion()
>>> G=dnx.chimera_graph(1, 1, 4)  # Draw a Chimera unit cell
>>> dnx.draw_chimera(G)
>>> dnx.draw_chimera(H, node_color='b', node_shape='*', style='dashed', edge_color='b', width=3)
>>> # matplotlib commands to add labels to graphic not shown
Graph H overlaid on a Chimera unit cell.

Graph H (blue) overlaid on a Chimera unit cell (red nodes and black edges).