Skip to content

Instantly share code, notes, and snippets.

@jcmgray
Last active July 25, 2018 12:48
Show Gist options
  • Save jcmgray/79f7c779c85f80ee6e72c1e7a042e0f5 to your computer and use it in GitHub Desktop.
Save jcmgray/79f7c779c85f80ee6e72c1e7a042e0f5 to your computer and use it in GitHub Desktop.
Create quantum circuit file for a single trotterization step of the maxcut QAOA algorithm.
import networkx as nx
reg = 3
n = 100
seed = 0
gamma0 = -0.743043
beta0 = 0.754082
# create the random graph
G = nx.random_regular_graph(reg, n)
# add all the gates
circ = "{}\n".format(n)
for i in range(n):
circ += "H {}\n".format(i)
for i, j in G.edges:
circ += "CNOT {} {}\n".format(i, j)
circ += "Rz {} {}\n".format(gamma0, j)
circ += "CNOT {} {}\n".format(i, j)
for i in range(n):
circ += "Rx {} {}\n".format(beta0, i)
# write the string to file
fname = "{}regRand{}Node{}.qasm".format(reg, n, seed)
with open(fname, mode='w') as file:
file.write(circ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment