-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghz_nc.py
52 lines (35 loc) · 1.12 KB
/
ghz_nc.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
# Near-Clifford GHZ state preparation simulation
import math
import random
import sys
import time
from pyqrack import QrackSimulator
def bench_qrack(n):
start = time.perf_counter()
sim = QrackSimulator(n, isTensorNetwork=False, isSchmidtDecompose=False, isStabilizerHybrid=True)
sim.h(0)
for q in range(n - 1):
sim.mcx([q], q + 1)
fidelity = sim.get_unitary_fidelity()
# Terminal measurement
sim.m_all()
return (time.perf_counter() - start, fidelity)
def main():
bench_qrack(1)
max_qb = 24
samples = 1
if len(sys.argv) > 1:
max_qb = int(sys.argv[1])
if len(sys.argv) > 2:
samples = int(sys.argv[2])
for n in range(1, max_qb + 1):
width_results = []
# Run the benchmarks
for _ in range(samples):
width_results.append(bench_qrack(n))
time_result = sum(r[0] for r in width_results) / samples
fidelity_result = sum(r[1] for r in width_results) / samples
print(n, ": ", time_result, " seconds, ", fidelity_result, " out of 1.0 fidelity")
return 0
if __name__ == '__main__':
sys.exit(main())