-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyzxrunner.py
More file actions
246 lines (217 loc) · 7.17 KB
/
pyzxrunner.py
File metadata and controls
246 lines (217 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import os
from os import listdir
import re
import sys
from enum import Enum
from runutils import *
def pyzx(path, bench_name, cnot):
cpath = path + bench_name
suffix = ".pyzx"
if cnot:
suffix+=".cnot"
options = {
'timeout': 3600*3,
'size': 6,
'rl': '',
'circuit': cpath + ".qasm",
'outfile' : cpath + suffix + ".output.qasm",
'logfile' : cpath + suffix + ".log",
'grain' : 100000000,
'nopp': '',
'runtool': '',
'greedyonly': ''
}
command = './bin/ct2.mlton.pyzx.bin'
for option, value in options.items():
if value:
command += ' -{} {}'.format(option, value)
else:
command += ' -{}'.format(option)
output_file = cpath + suffix + ".trash.out"
command += ' > {}'.format(output_file)
if cnot:
command += ' -{}'.format('cnotmin')
return command
def get_num_qubits(file):
with open(file, 'r') as f:
for line in f.readlines():
if line.strip().startswith('qreg'): # assume only one qreg
return int(re.findall(r'\d+', line)[-1])
return 0
def lopt_pyzx(path, bench_name, size, grain_per_qubit, cnot):
cpath = path + bench_name
n = get_num_qubits(cpath + ".qasm")
suffix = ".lopt.pyzx.{}.{}.converge".format(size, grain_per_qubit)
if cnot:
suffix+=".cnot"
options = {
'timeout': 3600*3,
'size': size,
'grain': grain_per_qubit * n,
'rl': '',
'circuit': cpath + ".qasm",
'outfile' : cpath + suffix + ".output.qasm",
'logfile' : cpath + suffix + ".log",
'nopp': '',
'greedyonly': ''
}
command = './bin/ct2.mlton.pyzx.bin'
for option, value in options.items():
if value:
command += ' -{} {}'.format(option, value)
else:
command += ' -{}'.format(option)
if cnot:
command += ' -{}'.format('cnotmin')
output_file = cpath + suffix + ".trash.out"
command += ' > {}'.format(output_file)
command += " ; rm -f /mnt/ramdisk/%s.*; rm -f /mnt/ramdisk/optimized_nam_%s.*; "%(bench_name, bench_name)
return command
def lopt_pyzx_size (path, bench_name, suffix, size):
cpath = path + bench_name
suffix+=".lopt.pyzx.size.%d"%(size)
options = {
'timeout': 3600*3,
'size': size,
'rl': '',
'circuit': cpath + ".qasm",
'logfile' : cpath + suffix + ".log",
'nopp': '',
'greedyonly': ''
}
command = './bin/ct2.mlton.pyzx.bin'
for option, value in options.items():
if value:
command += ' -{} {}'.format(option, value)
else:
command += ' -{}'.format(option)
output_file = cpath + suffix + ".lopt.trash.out"
command += ' > {}'.format(output_file)
# command += ' > {}'.format(output_file)
return command
def voqc(path, bench_name, suffix):
cpath = path + bench_name
suffix+=".voqc"
circuit = cpath + ".qasm"
command = '/root/quicr/quicr/optimizer/lib/SQIR/VOQC/_build/default/voqc.exe'
options = {
'i' : circuit,
'o' : cpath + suffix + ".output",
}
for option, value in options.items():
if option == 'circuit':
command += ' {}'.format(value)
elif option == 'dump':
continue
elif value:
command += ' -{} {}'.format(option, value)
else:
raise Exception("voqc doesn't have option less arguments")
output_file = cpath + suffix + ".combined.log"
command += ' > {}'.format(output_file)
return command
def size_exp (bn, sizes):
return list(map (lambda s: lopt_pyzx_size(path, bn, "", s), sizes))
def lopt_voqc (path, bench_name, suffix):
cpath = path + bench_name
suffix+=".lopt"
wtcomb = "voqc"
options = {
'timeout': 3600*3,
# 'wtcomb': wtcomb,
'size': 40,
'nopp': '',
# 'rl': '',
'greedyonly': '',
'circuit' : cpath + ".qasm",
'outfile' : cpath + suffix + "." + wtcomb + ".output",
'logfile' : cpath + suffix + "." + wtcomb + ".log"
}
command = './bin/ct2.mlton.voqc.bin'
for option, value in options.items():
if value:
command += ' -{} {}'.format(option, value)
else:
command += ' -{}'.format(option)
output_file = cpath + "." + wtcomb + ".trash.out"
command += ' > {}'.format(output_file)
# command += ' > {}'.format(output_file)
return command
nwq_list = ["nwq_binary_welded_tree_n17",
"nwq_multiplier_n200",
"nwq_statevector_n4",
"nwq_binary_welded_tree_n21",
"nwq_multiplier_n300",
"nwq_statevector_n6",
"nwq_boolean_satisfaction_n24",
"nwq_multiplier_n400",
"nwq_vqc_n120",
"nwq_boolean_satisfaction_n28",
"nwq_square_root_n21",
"nwq_vqc_n15",
"nwq_boolean_satisfaction_n30",
"nwq_square_root_n30",
"nwq_vqc_n240",
"nwq_boolean_satisfaction_n32",
"nwq_square_root_n42",
"nwq_vqc_n30",
"nwq_boolean_satisfaction_n34",
"nwq_square_root_n54",
"nwq_vqc_n60",
"nwq_multiplier_n100",
"nwq_square_root_n60"
]
path = "feyn_benchmarks/"
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
bench_files = [f for f in files if (f.endswith('.qasm'))]
bench_files = [f for f in bench_files if (not('trash' in f))]
bench_files = [f for f in bench_files if (not('output' in f))]
bench_files = [f for f in bench_files if (not('vqc' in f))]
bench_files = list(set([f.split('.')[0] for f in bench_files]))
bench_files = [f for f in bench_files]
bench_files = sorted(bench_files)
bench_files = [
'gf2^128_mult', 'gf2^32_mult', 'gf2^64_mult', 'grover_n11_from_python',
'grover_n11_from_python_ts2', 'grover_n13_from_python',
'grover_n13_from_python_ts2', 'grover_n15_from_python',
'grover_n15_from_python_ts2', 'grover_n9', 'grover_n9_from_python',
'grover_n9_from_python_ts2', 'hhl_n7_from_python', 'hhl_n9_from_python', 'hwb10',
'hwb11', 'hwb12', 'hwb6', 'hwb8', 'nwq_binary_welded_tree_n17',
'nwq_binary_welded_tree_n21', 'nwq_boolean_satisfaction_n24',
'nwq_boolean_satisfaction_n28',
'nwq_boolean_satisfaction_n32', 'nwq_multiplier_n100',
'nwq_multiplier_n200', 'nwq_multiplier_n300',
'nwq_square_root_n21', 'nwq_square_root_n30', 'nwq_square_root_n42',
'nwq_square_root_n48', 'nwq_square_root_n60',
'nwq_statevector_n4', 'nwq_statevector_n5', 'nwq_statevector_n6',
'qft_n16_from_qiskit', 'qft_n32_from_qiskit', 'qft_n48_from_qiskit',
'qft_n64_from_qiskit', 'qft_n80_from_qiskit', 'qft_n96_from_qiskit',
'shor_7_mod_15_n10_from_python', 'shor_7_mod_15_n12_from_python',
'shor_7_mod_15_n14_from_python', 'shor_7_mod_15_n16_from_python',
'shor_7_mod_15_n18_from_python', 'shor_7_mod_15_n8_from_python'
]
print(bench_files)
# bench_files = ["grover_n15_from_python"]
# bench_files = ["qft_n96_from_qiskit"]
# bench_files = ["nwq_square_root_n30"]
# bench_files = ["grover_n15_from_pythonp"]
sizes = [2, 5, 15, 30, 60, 120, 240, 480, 960, 1920, 3840, 7680]
# bench_files = ["nwq_statevector_n4"]
# bench_files = ["grover_n9_from_python_ts2", "grover_n11_from_python_ts2", "grover_n13_from_python_ts2", "grover_n15_from_python_ts2"]
# bench_files = ["hhl_n9_from_python", "shor_7_mod_15_n16_from_python"]
# bench_files = ["hwb10"]
pyzx_commands = list(map(lambda x: pyzx(path, x, False), bench_files))
lopt_commands = list(map(lambda x: lopt_pyzx(path, x, 200, 1000, False), bench_files))
voqc_commands = list(map (lambda x : voqc(path, x, ""), bench_files))
lopt_voqc_commands = list(map (lambda x : lopt_voqc(path, x, ""), bench_files))
size_commands = size_exp("grover_n15_from_python", sizes)
commands = lopt_commands
# commands = commands[0]
print(commands[0])
print("num commands", len(commands))
if (len(sys.argv) < 2):
print("no arguments\n")
exit()
P = 2 # Maximum parallel commands
results = run_commands(commands, P)
print(results)