Swapping

class sequence.entanglement_management.swapping.EntanglementSwappingA(owner: Node, name: str, left_memo: Memory, right_memo: Memory, success_prob: float = 1)

Base class for Entanglement Swapping A protocol.

The default formalism is KET_VECTOR_FORMALISM.

classmethod clear_global_formalism() None

Resets the global formalism to default

classmethod create(owner: Node, name: str, left_memo: Memory, right_memo: Memory, success_prob: float = 1, **kwargs) EntanglementSwappingA

Factory method to create an Entanglement Swapping A protocol instance of the global formalism.

Parameters:
  • owner (Node) – node that protocol instance is attached to.

  • name (str) – label for protocol instance.

  • left_memo (Memory) – memory entangled with a memory on one distant node.

  • right_memo (Memory) – memory entangled with a memory on the other distant node.

  • success_prob (float) – probability of a successful swapping operation (default 1).

Returns:

An instance of the Entanglement Swapping A protocol of the global formalism.

classmethod get_formalism() str

Get the global formalism for all Entanglement Swapping A protocol instances.

Returns:

The global formalism for all Entanglement Swapping A protocol instances.

is_ready() bool

Check if the protocol is ready.

Returns:

True if the protocol is ready to start, False otherwise.

Return type:

bool

classmethod list_protocols() list[str]

List all registered Entanglement Swapping A protocols.

Returns:

A list of names of all registered Entanglement Swapping A protocols.

memory_expire(memory: Memory) None

Method to receive memory expiration events.

Releases held memories on current node. Memories at the remote node are released as well.

Parameters:

memory (Memory) – memory that expired.

Side Effects:

Will invoke update method of attached resource manager. Will invoke release_remote_protocol or release_remote_memory method of resource manager.

received_message(src: str, msg: Message) None

Method to receive messages (should not be used on A protocol).

classmethod register(name: str, protocol_class: type[EntanglementSwappingA] = None) Callable[[type[EntanglementSwappingA]], type[EntanglementSwappingA]] | None

Register a specific type of Entanglement Swapping A protocol.

This method should be used as a decorator to register different types of Entanglement Swapping A protocols. The registered protocol can then be set as the global formalism for all Entanglement Swapping A protocol instances.

Parameters:
  • name (str) – name of the specific type of Entanglement Swapping A protocol.

  • protocol_class (type[EntanglementSwappingA] | None) – the class of the specific type of Entanglement Swapping A protocol. If None, the decorated class will be registered.

Returns:

If protocol_class is None, returns a decorator function. Otherwise, returns None.

classmethod set_formalism(formalism: str) None

Set the global formalism for all Entanglement Swapping A protocol instances.

Parameters:

formalism (str) – global formalism for all Entanglement Swapping A protocol instances.

set_others(protocol: str, node: str, memories: list[str]) None

Method to set other entanglement protocol instance.

Parameters:
  • protocol (str) – other protocol name.

  • node (str) – other node name.

  • memories (list[str]) – the list of memories name used on other node.

abstractmethod start() None

Method to start entanglement swapping process (abstract).

success_probability() float

A simple model for BSM success probability.

Returns:

the probability of a successful swapping operation.

Return type:

float

class sequence.entanglement_management.swapping.EntanglementSwappingA_BDS(owner: Node, name: str, left_memo: Memory, right_memo: Memory, success_prob=1, is_twirled=True)

Entanglement swapping protocol for middle node/router.

The entanglement swapping protocol is an asymmetric protocol. EntanglementSwappingA should be instantiated on the middle node,

where it measures a memory from each pair to be swapped.

Results of measurement and swapping are sent to the end nodes.

Variables:

EntanglementSwappingA.circuit (Circuit): circuit that does swapping operations.

owner

node that protocol instance is attached to.

Type:

Node

name

label for protocol instance.

Type:

str

left_memo

a memory from one pair to be swapped.

Type:

Memory

right_memo

a memory from the other pair to be swapped.

Type:

Memory

left_node

name of node that contains memory entangling with left_memo.

Type:

str

left_remote_memo

name of memory that entangles with left_memo.

Type:

str

right_node

name of node that contains memory entangling with right_memo.

Type:

str

right_remote_memo

name of memory that entangles with right_memo.

Type:

str

success_prob

probability of a successful swapping operation.

Type:

float

is_success

flag to show the result of swapping.

Type:

bool

left_protocol_name

name of left protocol.

Type:

str

right_protocol_name

name of right protocol.

Type:

str

is_twirled

whether the input and output states are twirled into Werner form (default True).

Type:

bool

start() None

Method to start entanglement swapping protocol.

Will run circuit and send measurement results to other protocols.

Side Effects:

Will call update_resource_manager method. Will send messages to other protocols.

swapping_res() list[float]

Method to calculate the resulting entangled state conditioned on successful swapping, for BDS formalism.

Returns:

resultant bell diagonal state entries.

Return type:

list[float]

class sequence.entanglement_management.swapping.EntanglementSwappingA_Circuit(owner: Node, name: str, left_memo: Memory, right_memo: Memory, success_prob=1, degradation=0.95)

Entanglement swapping protocol for middle router.

The entanglement swapping protocol is an asymmetric protocol. EntanglementSwappingA_Circuit should be instantiated on the middle node, where it measures a memory from each pair to be swapped. Results of measurement and swapping are sent to the end routers.

Variables:

EntanglementSwappingA_Circuit.circuit (Circuit): circuit that does swapping operations.

owner

node that protocol instance is attached to.

Type:

Node

name

label for protocol instance.

Type:

str

left_memo

a memory from one pair to be swapped.

Type:

Memory

right_memo

a memory from the other pair to be swapped.

Type:

Memory

left_node

name of node that contains memory entangling with left_memo.

Type:

str

left_remote_memo

name of memory that entangles with left_memo.

Type:

str

right_node

name of node that contains memory entangling with right_memo.

Type:

str

right_remote_memo

name of memory that entangles with right_memo.

Type:

str

success_prob

probability of a successful swapping operation.

Type:

float

degradation

degradation factor of memory fidelity after swapping.

Type:

float

is_success

flag to show the result of swapping

Type:

bool

left_protocol_name

name of left protocol.

Type:

str

right_protocol_name

name of right protocol.

Type:

str

start() None

Method to start entanglement swapping protocol.

Will run circuit and send measurement results to other protocols.

Side Effects:

Will call update_resource_manager method. Will send messages to other protocols.

updated_fidelity(f1: float, f2: float) float

A simple model updating fidelity of entanglement.

Parameters:
  • f1 (float) – fidelity 1.

  • f2 (float) – fidelity 2.

Returns:

fidelity of swapped entanglement.

Return type:

float

class sequence.entanglement_management.swapping.EntanglementSwappingB(owner: Node, name: str, hold_memo: Memory)

Base class for Entanglement Swapping B protocol.

The default formalism is KET_VECTOR_FORMALISM.

classmethod create(owner: Node, name: str, hold_memo: Memory, **kwargs) EntanglementSwappingB

Factory method to create an Entanglement Swapping B protocol instance of the global formalism.

classmethod get_formalism() str

Get the global formalism for all Entanglement Swapping B protocol instances.

Returns:

The global formalism for all Entanglement Swapping B protocol instances.

is_ready() bool

Method to check if protocol is ready to start (abstract).

Returns:

if protocol is ready or not.

Return type:

bool

memory_expire(memory: Memory) None

Method to deal with expired memories.

Parameters:

memory (Memory) – memory that expired.

Side Effects:

Will update memory in attached resource manager.

abstractmethod received_message(src: str, msg: EntanglementSwappingMessage) None

Method to receive messages from EntanglementSwappingA.

Parameters:
classmethod register(name: str, protocol_class: type[EntanglementSwappingB] = None) Callable[[type[EntanglementSwappingB]], type[EntanglementSwappingB]] | None

Register a specific type of Entanglement Swapping B protocol.

This method should be used as a decorator to register different types of Entanglement Swapping B protocols.

Parameters:
  • name (str) – name of the specific type of Entanglement Swapping B protocol.

  • protocol_class (type[EntanglementSwappingB] | None) – the class of the specific type of Entanglement Swapping B protocol. If None, the decorated class will be registered.

Returns:

If protocol_class is None, returns a decorator function. Otherwise, returns None.

release() None

Method to release attached memories.

classmethod set_formalism(formalism: str) None

Set the global formalism for all Entanglement Swapping B protocol instances.

Valid Built-formalisms:
  1. Bell Diagonal -> bds

  2. Circuit -> circuit (DEFAULT)

Parameters:

formalism (str) – global formalism for all Entanglement Swapping B protocol instances.

set_others(protocol: str, node: str, memories: list[str]) None

Method to set other entanglement protocol instance.

Parameters:
  • protocol (str) – other protocol name.

  • node (str) – other node name.

  • memories (list[str]) – the list of memory names used on other node.

start() None

Method to start entanglement protocol process (abstract).

class sequence.entanglement_management.swapping.EntanglementSwappingB_BDS(own: Node, name: str, hold_memo: Memory)

Entanglement swapping protocol for end node/router.

The entanglement swapping protocol is an asymmetric protocol. EntanglementSwappingB should be instantiated on the end nodes, where it waits for swapping results from the middle node.

Variables:

EntanglementSwappingB.x_cir (Circuit): circuit that corrects state with an x gate. EntanglementSwappingB.z_cir (Circuit): circuit that corrects state with z gate. EntanglementSwappingB.x_z_cir (Circuit): circuit that corrects state with an x and z gate.

own

node that protocol instance is attached to.

Type:

QuantumRouter

name

name of protocol instance.

Type:

str

memory

memory to swap.

Type:

Memory

remote_protocol_name

name of another protocol to communicate with for swapping.

Type:

str

remote_node_name

name of node hosting the other protocol.

Type:

str

received_message(src: str, msg: EntanglementSwappingMessage) None

Method to receive messages from EntanglementSwappingA.

Parameters:
Side Effects:

Will invoke update_resource_manager method.

class sequence.entanglement_management.swapping.EntanglementSwappingB_Circuit(owner: Node, name: str, hold_memo: Memory)

Entanglement swapping protocol for end router.

The entanglement swapping protocol is an asymmetric protocol. EntanglementSwappingB_Circuit should be instantiated on the end nodes, where it waits for swapping results from the middle node.

Variables:

EntanglementSwappingB_Circuit.x_cir (Circuit): circuit that corrects state with an x gate. EntanglementSwappingB_Circuit.z_cir (Circuit): circuit that corrects state with z gate. EntanglementSwappingB_Circuit.x_z_cir (Circuit): circuit that corrects state with an x and z gate.

own

node that protocol instance is attached to.

Type:

QuantumRouter

name

name of protocol instance.

Type:

str

memory

memory to swap.

Type:

Memory

remote_protocol_name

name of another protocol to communicate with for swapping.

Type:

str

remote_node_name

name of node hosting the other protocol.

Type:

str

received_message(src: str, msg: EntanglementSwappingMessage) None

Method to receive messages from EntanglementSwappingA.

Parameters:
Side Effects:

Will invoke update_resource_manager method.

class sequence.entanglement_management.swapping.EntanglementSwappingMessage(msg_type: SwappingMsgType, receiver: str, **kwargs)

Message used by entanglement swapping protocols.

This message contains all information passed between swapping protocol instances.

msg_type

defines the message type.

Type:

SwappingMsgType

receiver

name of destination protocol instance.

Type:

str

fidelity

fidelity of the newly swapped memory pair.

Type:

float

remote_node

name of the distant node holding the entangled memory of the new pair.

Type:

str

remote_memo

index of the entangled memory on the remote node.

Type:

int

expire_time

expiration time of the new memory pair.

Type:

int

class sequence.entanglement_management.swapping.SwappingMsgType(*values)

Defines possible message types for entanglement generation.