-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdrp_full.py
129 lines (85 loc) · 2.52 KB
/
sdrp_full.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
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
# Demonstrates the use of "Schmidt decomposition rounding parameter" ("SDRP")
import math
import random
import sys
import time
from pyqrack import QrackSimulator
def cx(sim, q1, q2):
sim.mcx([q1], q2)
def cy(sim, q1, q2):
sim.mcy([q1], q2)
def cz(sim, q1, q2):
sim.mcz([q1], q2)
def acx(sim, q1, q2):
sim.macx([q1], q2)
def acy(sim, q1, q2):
sim.macy([q1], q2)
def acz(sim, q1, q2):
sim.macz([q1], q2)
def swap(sim, q1, q2):
sim.swap(q1, q2)
def iswap(sim, q1, q2):
sim.iswap(q1, q2)
def iiswap(sim, q1, q2):
sim.adjiswap(q1, q2)
def pswap(sim, q1, q2):
sim.mcz([q1], q2)
sim.swap(q1, q2)
def mswap(sim, q1, q2):
sim.swap(q1, q2)
sim.mcz([q1], q2)
def nswap(sim, q1, q2):
sim.mcz([q1], q2)
sim.swap(q1, q2)
sim.mcz([q1], q2)
def bench_qrack(width, depth, sdrp):
# This is full-connectivity random circuit.
start = time.perf_counter()
sim = QrackSimulator(width, isTensorNetwork=False)
sim.set_sdrp(sdrp)
lcv_range = range(width)
all_bits = list(lcv_range)
two_bit_gates = swap, pswap, mswap, nswap, iswap, iiswap, cx, cy, cz, acx, acy, acz
for _ in range(depth):
# Single-qubit gates
for i in lcv_range:
sim.u(i, random.uniform(0, 2 * math.pi), random.uniform(0, 2 * math.pi), random.uniform(0, 2 * math.pi))
# 2-qubit couplers
unused_bits = all_bits.copy()
random.shuffle(unused_bits)
while len(unused_bits) > 1:
g = random.choice(two_bit_gates)
b1 = unused_bits.pop()
b2 = unused_bits.pop()
g(sim, b1, b2)
sim.try_separate_2qb(b1, b2)
fidelity = sim.get_unitary_fidelity()
# Terminal measurement
sim.m_all()
return (time.perf_counter() - start, fidelity)
def main():
bench_qrack(1, 1, 0.5)
width = 36
depth = 6
trials = 1
if len(sys.argv) < 5:
raise RuntimeError('Usage: python3 sdrp_full.py [sdrp] [width] [depth] [trials]')
sdrp = float(sys.argv[1])
width = int(sys.argv[2])
depth = int(sys.argv[3])
trials = int(sys.argv[4])
# Run the benchmarks
width_results = []
for _ in range(trials):
width_results.append(bench_qrack(width, depth, sdrp))
print({
'sdrp': sdrp,
'width': width,
'depth': depth,
'trials': trials,
'time': sum(r[0] for r in width_results) / trials,
'fidelity': sum(r[1] for r in width_results) / trials
})
return 0
if __name__ == '__main__':
sys.exit(main())