forked from tqsd/QuNetSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: tqsd#91
- Loading branch information
1 parent
4c76943
commit bac25b1
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |