Skip to content

Instantly share code, notes, and snippets.

@ssghost
Created February 16, 2019 14:55
Show Gist options
  • Save ssghost/e30616ae93e4e1049e45ce6f2eacd5d9 to your computer and use it in GitHub Desktop.
Save ssghost/e30616ae93e4e1049e45ce6f2eacd5d9 to your computer and use it in GitHub Desktop.
Dwave QPUComputing Test Code
import networkx as nx
import dwave_networkx as dnx
import matplotlib.pyplot as plt
from dwave.system.samplers import DWaveSampler
from dwave.system.composites import EmbeddingComposite
sampler = EmbeddingComposite(DWaveSampler(config_file='~/Library/Application Support/dwave/dwave.conf', solver='DW_2000Q_2_1'))
G = nx.Graph()
G.add_edges_from([(1,2),(1,4),(1,5),(2,3),(2,5),(2,7),(3,4),(3,6),(4,5),(5,6),(5,7)])
S = dnx.maximum_independent_set(G, sampler=sampler, num_reads=100)
print('MIS size found is', len(S))
print(S)
k = G.subgraph(S)
notS = list(set(G.nodes())-set(S))
othersubgraph = G.subgraph(notS)
pos = nx.spring_layout(G)
plt.figure()
nx.draw(G, pos=pos)
nx.draw(k, pos=pos)
nx.draw(othersubgraph, pos=pos, node_cplor='b')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment