# Simulation of Fidelity in Entanglement-Based Networks with Repeater Chains
## 6 Case Study: Analysis of a Repeater Chain  
As a case study for the programming environment described, we deployed the repeater quantum chain represented in Figure 3, where intermediate switches are equipped with some memory positions and are responsible for performing the swapping. Also, the final end node in the communication, on the right, executes the measurements in the correct protocol. Additionally, purification may be deployed in intermediate and/or end nodes to improve fidelity. Every QR contains quantum and classical communication ports on the left and the right, and a quantum program, which executes gates in a quantum processor--mainly instruction-gates linked to the protocols and measurements. The topology is created (Algorithm 1) from a network configuration file by adding end nodes and switches and then, for the linear topology in our case study, by setting up the connections and linking the ports to the memory positions. Then, protocols are associated with nodes in the master simulation script (Algorithm 2); for our case study, a specific protocol (repeaterProtocol has been designed and developed. Apart from deploying quantum protocols over the topology, the script also collects (dataCollector performance and quality data, for instance, in order to apply a routing strategy based on VL availability and end-to-end fidelity. Figure 3: Scheme for the quantum communication scenario, including the main quantum mechanism, swapping and correct protocols and purification. ```
1:functionsetup_network(number_of_switches, distances, num_positions)
2:network=Network(\"linear_network\")
3:EndNodeend_nodes[]
4:Switchswitch_nodes[]
5:nodes=[end_nodes[0]]+switch_nodes+[end_nodes[1]]
6:network_add_nodes(nodes)
7:fori in range(len(nodes)-1)do
8:left, right=nodes[i], nodes[i + 1]
9:conn=ClassicalConnection(distances[i])
10:network_add_connection(left, right, cconn)
11:forj in range(num_positions//2)do
12:qconn=QuantumConnection(j, distances[i])
13:network_add_connection(left, right, qconn)
14:left.ports.forward_in(left.qmemory.ports[])
15:right.ports.forward_in(right.qmemory.ports[])
16:endfor
17:endfor
18:returnnetwork
19:endfunction
```  
**Algorithm 1** Setup Network  
For our chained topology, the repeater protocol is implemented as a protocol that runs locally in all the nodes of the topology so that different sub-protocols can be launched in the single nodes. The repeater protocol (Algorithm 3) is responsible for launching sub-protocols for entanglement swapping (intermediate nodes) and the sub-protocol for applying corrections at the end-node (Bob on the right). With respect to the original NetSquid developments, we have deployed a scalable, configurable and extensible module. Although the original code structure is kept, our module allows for the configuration of the memory positions available for communication; a class to register the fidelity and use that information to decide on which positions perform BSM and optimize resources; compatibility with purification protocols; and a complete revamp of the noise model (depolarization). As an illustration, Figure 4 shows the software architecture of the protocols at the nodes (end nodes and repeaters QR_1 to QR_n) for a given virtual link if purification is not required in the case of a repeater chain (not proper switches). There is one instance of SwapProtocol at each switch traversed, and one instance of CorrectProtocol at the destination end node. However, if purification is required, the number of links is doubled, coordinating two SwapProtocols at each switch, two CorrectProtocols at the end node and the DistilProtocol at each source and destination end node. Node_A and node_B are equipped with some quantum memory to store the pending requests (qubits to teleport from Alice to Bob). For each request of a virtual link between source and destination (node_A and node_B in the figure), the routing strategy will coordinate the other protocols to create the virtual link and, upon completion, it will notify the requester.