-
Notifications
You must be signed in to change notification settings - Fork 0
/
qft.py
64 lines (44 loc) · 1.41 KB
/
qft.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
import math
import random
import sys
import time
from pyqrack import QrackSimulator
def bench_qrack(n):
# This is a discrete Fourier transform, after initializing all qubits randomly but separably.
start = time.perf_counter()
qsim = QrackSimulator(n)
lcv_range = range(n)
# Single-qubit gates
for i in lcv_range:
qsim.u(i, random.uniform(0, 2 * math.pi), random.uniform(0, 2 * math.pi), random.uniform(0, 2 * math.pi))
# GHZ state
# qsim.h(0)
# for i in range(1, n):
# qsim.mcx([i - 1], i)
qsim.qft(list(lcv_range))
end = n - 1
for i in range(n // 2):
qsim.swap(i, end - i)
fidelity = qsim.get_unitary_fidelity()
# Terminal measurement
qsim.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 i 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())