forked from quantum-compiler/quartz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_results.py
76 lines (71 loc) · 2.41 KB
/
extract_results.py
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
import sys
from natsort import natsorted
def extract_results(filename):
with open(filename) as f:
content = f.readlines()
flag = False
tot_time = 0
tot_gate = 0
gate_product = 1
key = ''
result = {}
result_depth = {}
tot_depth = 0
depth_product = 1
for line in content:
line = line.strip()
data = line.split()
if line.startswith('Optimization'):
flag = True
pos = line.find('.qasm')
pos2 = line.rfind(' ', 0, pos)
key = line[pos2 + 1 : pos]
else:
flag = False
if flag:
pos = line.find(':')
pos2 = line.find(',', pos)
pos4 = line.find(':', pos2)
pos5 = line.find(',', pos4)
pos3 = line.find('s', pos2 if pos5 == -1 else pos5)
val = int(line[pos + 2 : pos2])
result[key] = val
tot_gate += val
gate_product *= val
if pos4 == -1:
tot_time += float(line[pos2 + 2 : pos3])
else:
val = int(line[pos4 + 2 : pos5])
result_depth[key] = val
tot_depth += val
depth_product *= val
tot_time += float(line[pos5 + 2 : pos3])
# if len(data) >= 2 and data[1] == 'Timeout.':
# key = data[0].split('.')[0]
# val = data[-1]
# result[key] = val
# tot_gate += int(data[-1])
# gate_product *= int(data[-1])
# tot_time += 86400 # 1-day timeout
print('Gate count:')
for k, v in natsorted(result.items()):
print(k.ljust(15), v)
if len(result_depth) > 0:
print('Circuit depth:')
for k, v in natsorted(result_depth.items()):
print(k.ljust(15), v)
assert len(result_depth) == len(result)
print('tot_gate =', tot_gate)
print('num_circuits =', len(result))
print('geomean_gatecount =', gate_product ** (1 / len(result)))
if len(result_depth) > 0:
print('tot_depth =', tot_depth)
print('geomean_depth =', depth_product ** (1 / len(result)))
print('tot_time =', tot_time)
# for k, v in natsorted(result.items()):
# print(v) # easy paste to google doc
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: python extract_results.py [result file of ./run_*.sh]')
exit()
extract_results(sys.argv[1])