Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions docs/source/tutorial/sequence3min/three_minute.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SeQUeNCe in 3 Minutes

In this introductory three minute tutorial, we will briefly cover the neccesary basics of SeQUeNCe. We will request a one entanglment pair between two quantum routers, Alice and Bob. The goal of this tutorial is to gain a general understanding of SeQUeNCe's topology generator to create a two-node network, attach a single application to the routers, and submit an entangment request through the network manager.
In this introductory three-minute tutorial, we will briefly cover the necessary basics of SeQUeNCe. We will request one entanglement pair between two quantum routers, Alice and Bob. The goal of this tutorial is to gain a general understanding of SeQUeNCe's topology generator to create a two-node network, attach a single application to the routers, and submit an entanglement request through the network manager.

### Step 1: Generate the Two-Node Topology

Expand Down Expand Up @@ -38,52 +38,38 @@ EntanglementGenerationB.set_global_type(SINGLE_HERALDED)
Next, we load the generated JSON file into a `RouterNetTopo`. This constructs the timeline, quantum routers, BSM node, and communication channels defined in the topology file.

```python
network_config = "docs/source/tutorial/threeMinTutorial/two_node.json"

network_topo = RouterNetTopo(network_config)
network_topo = RouterNetTopo(config_source="docs/source/tutorial/sequence3min/two_node.json")
tl = network_topo.get_timeline()
```

### Step 4: Select Alice and Bob, and attach the applications
### Step 4: Attach the Application Module to the Nodes

The topology generator names the two routers `router_0` and `router_1`. In this tutorial, we will refer to these nodes as Alice and Bob.
Loop over the node objects, and then attach the application to the nodes and make the entanglement request.

```python
alice_name = "router_0"
bob_name = "router_1"
alice = None
bob = None
name_to_app = {}
for router in network_topo.get_nodes_by_type(RouterNetTopo.QUANTUM_ROUTER):
if router.name == alice_name:
alice = router
elif router.name == bob_name:
bob = router
alice_app = RequestApp(alice)
bob_app = RequestApp(bob)
name_to_app[router.name] = RequestApp(router)
```

This loop searches the topology for the two quantum routers and stores references to them. These node objects are then used to attach applications and make the entanglement request.


### Step 5: Run the Simulation

Finally, we initialize the timeline, start Alice's request, and run the simulation.
Finally, we initialize the timeline, start Alice's request to Bob, and run the simulation.

```python
tl.init()
start_t = 1 * SECOND
end_t = 2.5 * SECOND
memo_size = 1
fidelity = 0.8
alice_app.start(responder=bob_name, start_t=start_t, end_t=end_t, memo_size=memo_size, fidelity=fidelity)
alice = "router_0"
bob = "router_1"
name_to_app[alice].start(responder=bob, start_t=1 * SECOND, end_t=2.5 * SECOND, memo_size=1, fidelity=0.8)
tl.run()
```

The request asks Alice to establish entanglement with Bob between 1 second and 2.5 seconds of simulated time. After the timeline finishes running, we can check the number of entangled pairs between Alice and Bob and the throughput.
The request asks Alice to establish entanglement with Bob between `1` second and `2.5` seconds of simulation time. It uses `1` quantum memory at Alice and Bob and requires the end-to-end fidelity to be above `0.8`.
After the timeline finishes running, we can check the number of entangled pairs between Alice and Bob and the throughput.

```python
print(f"Entangled pair count between Alice and Bob: {alice_app.memory_counter}")
print(f"The throughput is {alice_app.get_throughput()} pairs per second")
print(f"Entangled pair count between Alice and Bob: {name_to_app[alice].memory_counter}")
print(f"The throughput is {name_to_app[alice].get_throughput()} pairs per second")
```

You will see the following:
Expand All @@ -95,4 +81,4 @@ The throughput is 70.0 pairs per second

---

The full code can be found at [three_minute.py](three_minute.py)
The full code can be found at [three_minute.py](three_minute.py)
29 changes: 8 additions & 21 deletions docs/source/tutorial/sequence3min/three_minute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,23 @@
from sequence.constants import SINGLE_HERALDED, SECOND
from sequence.entanglement_management.generation import EntanglementGenerationA, EntanglementGenerationB


if __name__ == "__main__":

EntanglementGenerationA.set_global_type(SINGLE_HERALDED)
EntanglementGenerationB.set_global_type(SINGLE_HERALDED)

network_config = "docs/source/tutorial/sequence3min/two_node.json"
network_topo = RouterNetTopo(network_config)
network_topo = RouterNetTopo(config_source="docs/source/tutorial/sequence3min/two_node.json")
tl = network_topo.get_timeline()

# Treat router_0 as Alice and router_1 as Bob.
alice_name = "router_0"
bob_name = "router_1"
alice = None
bob = None
name_to_app = {}
for router in network_topo.get_nodes_by_type(RouterNetTopo.QUANTUM_ROUTER):
if router.name == alice_name:
alice = router
elif router.name == bob_name:
bob = router
alice_app = RequestApp(alice)
bob_app = RequestApp(bob)
name_to_app[router.name] = RequestApp(router)

tl.init()
start_t = 1 * SECOND
end_t = 2.5 * SECOND
memo_size = 1
fidelity = 0.8
alice_app.start(responder=bob_name, start_t=start_t, end_t=end_t, memo_size=memo_size, fidelity=fidelity)
alice = "router_0"
bob = "router_1"
name_to_app[alice].start(responder=bob, start_t=1 * SECOND, end_t=2.5 * SECOND, memo_size=1, fidelity=0.8)
tl.run()

print(f"Entangled pair count between Alice and Bob: {alice_app.memory_counter}")
print(f"The throughput is {alice_app.get_throughput()} pairs per second")
print(f"Entangled pair count between Alice and Bob: {name_to_app[alice].memory_counter}")
print(f"The throughput is {name_to_app[alice].get_throughput()} pairs per second")
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, msg_type: SwappingMsgType, receiver: str, **kwargs):
self.expire_time = kwargs.get("expire_time")
self.meas_res = kwargs.get("meas_res")
else:
raise Exception("Entanglement swapping protocol create unkown type of message: %s" % str(msg_type))
raise Exception(f"Entanglement swapping protocol create unkown type of message: {msg_type}")

def __str__(self):
if self.msg_type == SwappingMsgType.SWAP_RES:
Expand Down
2 changes: 1 addition & 1 deletion sequence/topology/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ['node', 'topology', 'qkd_topo', 'router_net_topo', 'quantum_node_net_topo']
__all__ = ['node', 'topology', 'qkd_topo', 'router_net_topo', 'dqc_net_topo']

def __dir__():
return sorted(__all__)