Skip to content

Commit bac25b1

Browse files
committed
examples: add an second generation repeater
The idealized quantum repeater from https://arxiv.org/pdf/0809.3629.pdf is modelled with three repeater stations. fixes: #91
1 parent 4c76943 commit bac25b1

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

examples/repeater/swap_and_distil.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from dataclasses import dataclass
2+
3+
from qunetsim.components import Host
4+
from qunetsim.objects import Logger, Qubit
5+
from qunetsim.components import Network
6+
7+
Logger.DISABLED = True
8+
9+
10+
@dataclass()
11+
class Ebit:
12+
val: tuple[int, int]
13+
14+
def __str__(self):
15+
return {
16+
(0, 0): "phi+",
17+
(0, 1): "psi+",
18+
(1, 0): "phi-",
19+
(1, 1): "psi-",
20+
}[self.val]
21+
22+
@staticmethod
23+
def from_bell_measurement(a: Qubit, b: Qubit):
24+
a.cnot(b)
25+
a.H()
26+
return Ebit((a.measure(), b.measure()))
27+
28+
29+
def epr(left, right):
30+
a = Qubit(left)
31+
b = Qubit(right)
32+
33+
a.H()
34+
a.cnot(b)
35+
left.send_qubit(right.host_id, b)
36+
b = right.get_qubit(left.host_id, wait=-1)
37+
38+
return a, b
39+
40+
41+
def main():
42+
network = Network.get_instance()
43+
nodes = ["Alice", "Polly", "Bob"]
44+
45+
network.start(nodes)
46+
network.delay = 0.1
47+
48+
alice = Host("Alice")
49+
alice.add_connection("Polly")
50+
alice.start()
51+
52+
bob = Host("Bob")
53+
bob.add_connection("Polly")
54+
bob.start()
55+
56+
polly = Host("Polly")
57+
polly.add_connection("Alice")
58+
polly.add_connection("Bob")
59+
polly.start()
60+
61+
network.add_host(alice)
62+
network.add_host(polly)
63+
network.add_host(bob)
64+
network.start()
65+
66+
alices = []
67+
bobs = []
68+
for _ in range(10):
69+
# Swap: Build eprs, Polly measures, Polly broadcasts results.
70+
a, p1 = epr(alice, polly)
71+
p2, b = epr(polly, bob)
72+
ebit = Ebit.from_bell_measurement(p1, p2)
73+
polly.send_broadcast(str(ebit))
74+
75+
# Apply local ops to transform |ab> into |Φ+> (modulo phase).
76+
m = alice.get_next_classical(polly.host_id)
77+
if m.content == 'psi-':
78+
a.Y()
79+
80+
m = bob.get_next_classical(polly.host_id)
81+
if m.content == 'psi+':
82+
b.X()
83+
elif m.content == 'phi-':
84+
b.Z()
85+
86+
alices.append(a)
87+
bobs.append(b)
88+
89+
# Check that we're establishing |Φ+>
90+
for i in range(len(alices)):
91+
a = alices[i].measure()
92+
b = bobs[i].measure()
93+
if a == b:
94+
print(f"qubit pair {i} were probably Φ+!")
95+
else:
96+
print(f"qubit pair {i} were probably not Φ+!")
97+
98+
network.stop(True)
99+
100+
101+
if __name__ == "__main__":
102+
main()

0 commit comments

Comments
 (0)