protocols module

class protocols.ContinuousDistillationProtocol(ctrl_node, qnode_1, qnode_2, routing_table, max_attempts=10, timeout=1500, max_distillations=3)[source]

Bases: Protocol

Continuous entanglement distillation protocol.

This protocol repeatedly attempts to establish entanglement between two quantum nodes, performs qubit swapping, and applies entanglement purification (EPL-style distillation) in multiple rounds. The goal is to iteratively improve the fidelity of the shared entangled state.

Parameters:
  • ctrl_node (Node) – Control node responsible for managing routing and coordination.

  • qnode_1 (Node) – First quantum node participating in entanglement and distillation.

  • qnode_2 (Node) – Second quantum node participating in entanglement and distillation.

  • routing_table (dict) – Table defining routing information for entanglement attempts.

  • max_attempts (int, optional) – Maximum number of entanglement attempts per phase (default: 10).

  • timeout (int, optional) – Timeout for entanglement attempts in nanoseconds (default: 1500).

  • max_distillations (int, optional) – Maximum number of distillation iterations to perform (default: 3).

run(self)[source]

Generator or function that runs the protocol.

Starting the protocol will execute this function. If a generator it will run it up to the first yield. All yields should return a EventExpression, the generator will only continue when the expression has been triggered.

If a function is returned, this protocol may still yield on the generator of its sub-protocols.

Sub-protocols are not started automatically when this method is overridden. Either start them manually in the overridden run() or call start_subprotocols() to start them all at once.

Returns:

If this method returns a generator, then the final return of the generator will be set as the value of FINISHED.

Return type:

Any

class protocols.EntanglementProtocol(ctrl_node, source, target, timeout=1500, perform_correction=True)[source]

Bases: NodeProtocol

Protocol for establishing entanglement between two quantum network nodes.

This protocol runs on a source node and attempts to establish an entangled Bell pair with the target node. Optionally, it applies local correction operations based on the Bell state received from the control node.

Parameters:
  • source (netsquid.nodes.Node) – Node running the protocol and emitting photons.

  • target (netsquid.nodes.Node) – Destination node intended for entanglement.

  • ctrl_node (ControlNode) – Central control node managing entanglement routing and corrections.

  • timeout (int) – Maximum waiting time (in simulation time units) before aborting.

  • perform_correction (bool) – Whether to apply local Pauli corrections after entanglement.

  • protocol_log (str) – Protocol identifier string for logging purposes.

Examples

>>> from simulation import setup_simple_network
>>> _, ctrl_node, [qnode_1, qnode_2] = setup_simple_network(
...     dampening_parameter=0.1,
...     routing={"qin0": "qout0", "qin1": "qout1", "qin2": "qout2"},
...     ideal_switch=False,
...     ideal_qpu=False,
...     visibility=0.9
... ) # Setup network
>>> entanglement_protocol = EntanglementProtocol(
...     ctrl_node=ctrl_node,
...     source=qnode_1,
...     target=qnode_2,
...     timeout=400,
...     perform_correction=True,
... ) # Setup entanglement protocol
>>> entanglement_protocol.start() # Run protocol
run(self)[source]

Generator or function that runs the protocol.

Starting the protocol will execute this function. If a generator it will run it up to the first yield. All yields should return a EventExpression, the generator will only continue when the expression has been triggered.

If a function is returned, this protocol may still yield on the generator of its sub-protocols.

Sub-protocols are not started automatically when this method is overridden. Either start them manually in the overridden run() or call start_subprotocols() to start them all at once.

Returns:

If this method returns a generator, then the final return of the generator will be set as the value of FINISHED.

Return type:

Any

class protocols.EntanglementRetryProto(ctrl_node, qnode_1, qnode_2, routing_table, max_attempts=10, timeout=1500)[source]

Bases: Protocol

A higher-level protocol that retries entanglement attempts until success or until reaching a maximum attempt limit.

This wrapper manages two EntanglementProtocol instances (one per node) and coordinates retries across both until a valid Bell pair is established.

Parameters:
  • routing_table (dict) – Placeholder routing table for entanglement setup (not yet used).

  • max_attempts (int) – Maximum number of entanglement attempts.

  • timeout (int) – Timeout per entanglement attempt (ns).

  • attempts (int) – Number of entanglement attempts the protocol performs before giving up.

  • qnode_1 (netsquid.nodes.Node) – First node in the entanglement attempt.

  • qnode_2 (netsquid.nodes.Node) – Second node in the entanglement attempt.

  • subprotocol_qnode_1 (EntanglementProtocol) – Entanglement protocol instance running on qnode_1.

  • subprotocol_qnode_2 (EntanglementProtocol) – Entanglement protocol instance running on qnode_2.

run(self)[source]

Generator or function that runs the protocol.

Starting the protocol will execute this function. If a generator it will run it up to the first yield. All yields should return a EventExpression, the generator will only continue when the expression has been triggered.

If a function is returned, this protocol may still yield on the generator of its sub-protocols.

Sub-protocols are not started automatically when this method is overridden. Either start them manually in the overridden run() or call start_subprotocols() to start them all at once.

Returns:

If this method returns a generator, then the final return of the generator will be set as the value of FINISHED.

Return type:

Any