Last active
July 25, 2018 12:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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