import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from blueqat import Circuit
from blueqat.utils import qaoa
from blueqat.pauli import X,Y,Z
from blueqat.pauli import qubo_bit as q
Copy
import networkx as nx
import matplotlib.pyplot as plt
n = 10
m = 30
seed = 15
options = {'node_size': 100}
G = nx.gnm_random_graph(n, m, seed = seed)
nx.draw(G, **options)
<Figure size 432x288 with 1 Axes>
Copy
hamiltonian = sum(q(e[0])*q(e[1]) + q(e[0]+n)*q(e[1]+n) for e in G.edges)
step = 1
#mixer and init state
mixer = 0.0
init = Circuit()
for i in range(n):
mixer += 0.5*X[i]*X[i+n] + 0.5*Y[i]*Y[i+n]
init.h[i].cx[i,i+n].x[i]
result = qaoa(hamiltonian, step, init, mixer)
b = result.circuit.run(shots=10)
sample = b.most_common(1)[0][0]
print("sample:"+ str(sample))
nx.draw(G, **options, node_color=[int(s) for s in list(sample[:n])])