Skip to content

Commit

Permalink
examples: add an second generation repeater
Browse files Browse the repository at this point in the history
The idealized quantum repeater from https://arxiv.org/pdf/0809.3629.pdf
is modelled with three repeater stations.

fixes: tqsd#91
  • Loading branch information
atomgardner committed Jun 10, 2023
1 parent 4c76943 commit bac25b1
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions examples/repeater/swap_and_distil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from dataclasses import dataclass

from qunetsim.components import Host
from qunetsim.objects import Logger, Qubit
from qunetsim.components import Network

Logger.DISABLED = True


@dataclass()
class Ebit:
val: tuple[int, int]

def __str__(self):
return {
(0, 0): "phi+",
(0, 1): "psi+",
(1, 0): "phi-",
(1, 1): "psi-",
}[self.val]

@staticmethod
def from_bell_measurement(a: Qubit, b: Qubit):
a.cnot(b)
a.H()
return Ebit((a.measure(), b.measure()))


def epr(left, right):
a = Qubit(left)
b = Qubit(right)

a.H()
a.cnot(b)
left.send_qubit(right.host_id, b)
b = right.get_qubit(left.host_id, wait=-1)

return a, b


def main():
network = Network.get_instance()
nodes = ["Alice", "Polly", "Bob"]

network.start(nodes)
network.delay = 0.1

alice = Host("Alice")
alice.add_connection("Polly")
alice.start()

bob = Host("Bob")
bob.add_connection("Polly")
bob.start()

polly = Host("Polly")
polly.add_connection("Alice")
polly.add_connection("Bob")
polly.start()

network.add_host(alice)
network.add_host(polly)
network.add_host(bob)
network.start()

alices = []
bobs = []
for _ in range(10):
# Swap: Build eprs, Polly measures, Polly broadcasts results.
a, p1 = epr(alice, polly)
p2, b = epr(polly, bob)
ebit = Ebit.from_bell_measurement(p1, p2)
polly.send_broadcast(str(ebit))

# Apply local ops to transform |ab> into |Φ+> (modulo phase).
m = alice.get_next_classical(polly.host_id)
if m.content == 'psi-':
a.Y()

m = bob.get_next_classical(polly.host_id)
if m.content == 'psi+':
b.X()
elif m.content == 'phi-':
b.Z()

alices.append(a)
bobs.append(b)

# Check that we're establishing |Φ+>
for i in range(len(alices)):
a = alices[i].measure()
b = bobs[i].measure()
if a == b:
print(f"qubit pair {i} were probably Φ+!")
else:
print(f"qubit pair {i} were probably not Φ+!")

network.stop(True)


if __name__ == "__main__":
main()

0 comments on commit bac25b1

Please sign in to comment.