-
Notifications
You must be signed in to change notification settings - Fork 0
/
entanglement-breaking.py
80 lines (53 loc) · 1.78 KB
/
entanglement-breaking.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
# Example of entanglement-breaking channel
import math
import statistics
import sys
from pyqrack import QrackSimulator
def calc_xeb(ideal_probs, split_probs):
n_pow = len(ideal_probs)
u_u = statistics.mean(ideal_probs)
numer = 0
denom = 0
for i in range(n_pow):
split = split_probs[i]
ideal = ideal_probs[i]
# XEB / EPLG
denom += (ideal - u_u) ** 2
numer += (ideal - u_u) * (split - u_u)
return numer / denom
def calc_fidelity(ideal_ket, split_ket):
s = sum([x * y.conjugate() for x, y in zip(ideal_ket, split_ket)])
return (s * s.conjugate()).real
def main():
control = QrackSimulator(2)
experiment = QrackSimulator(2, isTensorNetwork=False, isStabilizerHybrid=False)
# Prepare a Bell pair.
control.h(1)
control.mcx([1], 2)
experiment.h(1)
experiment.mcx([1], 2)
# Apply an entanglement-breaking channel
experiment.separate([1])
# L2 fidelity should be 50%:
ideal_ket = control.out_ket()
split_ket = experiment.out_ket()
for i in range(len(ideal_ket)):
print("<" + str(i) + "|ideal>: " + str(ideal_ket[i]))
print()
for i in range(len(ideal_ket)):
print("<" + str(i) + "|split>: " + str(split_ket[i]))
print()
print("Fidelity: " + str(calc_fidelity(ideal_ket, split_ket)))
print()
# Cross entropy should be 0
ideal_probs = control.out_probs()
split_probs = experiment.out_probs()
for i in range(len(ideal_probs)):
print("|<" + str(i) + "|ideal>|^2: " + str(ideal_probs[i]))
print()
for i in range(len(ideal_probs)):
print("|<" + str(i) + "|split>|^2: " + str(split_probs[i]))
print()
print("XEB: " + str(calc_xeb(ideal_probs, split_probs)))
if __name__ == '__main__':
sys.exit(main())