qns.network.protocol package

Submodules

qns.network.protocol.bb84 module

class qns.network.protocol.bb84.BB84RecvApp(src: QNode, qchannel: QuantumChannel, cchannel: ClassicChannel, length_for_post_processing=512, ratio_for_estimating_error=0.2, max_cascade_round=5, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=50, security=0.05)[source]

Bases: Application

check_basis(event: RecvClassicPacket)[source]

Compare measurement bases in BB84RecvApp based on classical information.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleClassicPacket(node: QNode, event: Event) bool[source]

Handle classical packets in BB84RecvApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvClassicPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleQuantumPacket(node: QNode, event: Event) bool[source]

Handle received Qubits in BB84RecvApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvQubitPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv(event: RecvQubitPacket) bool[source]

Receive Qubits in BB84RecvApp, randomly select measurement bases, and measure Qubits.

Parameters:

event – Simulation event for receiving Qubits.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_cascade_reply_packet(event: RecvClassicPacket)[source]

Handle cascade reply packets in BB84RecvApp and execute subsequent cascade rounds.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_check_error_reply_packet(event: RecvClassicPacket)[source]

Handle error verification reply packets in BB84RecvApp.

Parameters:

event – The check_error_reply packet.

recv_error_estimate_reply_packet(event: RecvClassicPacket) bool[source]

Handle error rate estimation reply packets in BB84RecvApp and start the first cascade round.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

send_error_estimate_packet()[source]

Send error rate estimation packets in BB84RecvApp.

class qns.network.protocol.bb84.BB84SendApp(dest: QNode, qchannel: QuantumChannel, cchannel: ClassicChannel, send_rate=1000, length_for_post_processing=512, ratio_for_estimating_error=0.2, max_cascade_round=5, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=50, security=0.05)[source]

Bases: Application

check_basis(event: RecvClassicPacket) bool[source]

Compare measurement bases in BB84SendApp based on classical information.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleClassicPacket(node: QNode, event: Event) bool[source]

Handle classical packets in BB84SendApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvClassicPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

install(node: QNode, simulator: Simulator)[source]

Deploy BB84SendApp on a node.

Parameters:
  • node – Node.

  • simulator – Simulation scheduler.

recv_cascade_ask_packet(event: RecvClassicPacket) bool[source]

Handle cascade error correction packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_check_error_ask_packet(event: RecvClassicPacket) bool[source]

Handle error verification packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_error_estimate_packet(event: RecvClassicPacket) bool[source]

Handle error rate estimation packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_privacy_amplification_ask_packet(event: RecvClassicPacket) bool[source]

Handle privacy amplification packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

send_qubit()[source]

Randomly prepare and send Qubits in BB84SendApp.

class qns.network.protocol.bb84.QubitWithError(state=array([[1. + 0.j], [0. + 0.j]]), rho: ndarray | None = None, operate_decoherence_rate: float = 0, measure_decoherence_rate: float = 0, name: str | None = None)[source]

Bases: Qubit

transfer_error_model(length: float, decoherence_rate: float = 0, **kwargs)[source]

Noise model for quantum signal transmission, using the collective-rotation noise model.

Parameters:
  • length – Length of the quantum channel in meters.

  • decoherence_rate – Decoherence rate.

qns.network.protocol.bb84.cascade_binary_divide(begin: int, end: int)[source]

Binary divide key block indices.

Parameters:
  • begin – Start index of the key block.

  • end – End index of the key block.

Returns:

Divided key block indices.

Return type:

tuple

qns.network.protocol.bb84.cascade_key_shuffle(index: list)[source]

Randomly shuffle key block indices.

Parameters:

index – List of key block indices.

Returns:

Shuffled key block indices.

Return type:

list

qns.network.protocol.bb84.cascade_parity(target: list)[source]

Calculate the parity of a key block.

Parameters:

target – Key block to calculate.

Returns:

Parity value.

Return type:

int

qns.network.protocol.bb84.pa_generate_toeplitz_matrix(N: int, M: int, first_row: list, first_col: list)[source]

Generate a Toeplitz matrix of size N x M.

Parameters:
  • N – Number of columns in the Toeplitz matrix.

  • M – Number of rows in the Toeplitz matrix.

  • first_row – First row of the Toeplitz matrix.

  • first_col – First column of the Toeplitz matrix.

Returns:

Toeplitz matrix of size N x M.

Return type:

list

qns.network.protocol.bb84.pa_randomize_key(original_key: list, toeplitz_matrix)[source]

Perform privacy amplification using a Toeplitz matrix.

Parameters:
  • original_key – Original key.

  • toeplitz_matrix – Toeplitz matrix.

Returns:

Key after privacy amplification.

Return type:

np_array

qns.network.protocol.classicforward module

class qns.network.protocol.classicforward.ClassicPacketForwardApp(route: RouteImpl)[source]

Bases: Application

This application will generate routing table for classic networks and allow nodes to forward classic packats to the destination.

handleClassicPacket(node: QNode, event: Event)[source]
install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator

qns.network.protocol.entanglement_distribution module

class qns.network.protocol.entanglement_distribution.EntanglementDistributionApp(send_rate: int | None = None, init_fidelity: int = 0.99)[source]

Bases: Application

RecvClassicPacketHandler(node: QNode, event: Event)[source]
RecvQubitHandler(node: QNode, event: Event)[source]
generate_qubit(src: QNode, dst: QNode, transmit_id: str | None = None) QuantumModel[source]
handle_response(packet: RecvClassicPacket)[source]
install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator

new_distribution()[source]
request_distrbution(transmit_id: str)[source]
response_distribution(packet: RecvQubitPacket)[source]
set_first_epr(epr: QuantumModel, transmit_id: str)[source]
set_second_epr(epr: QuantumModel, transmit_id: str)[source]
class qns.network.protocol.entanglement_distribution.Transmit(id: str, src: QNode, dst: QNode, first_epr_name: str | None = None, second_epr_name: str | None = None)[source]

Bases: object

qns.network.protocol.node_process_delay module

class qns.network.protocol.node_process_delay.NodeProcessDelayApp(delay: float = 0, delay_event_list: type | Tuple[type] | None = None)[source]

Bases: Application

This application will add an addition delay whenever the node received an event. It is used to represent the processing delay on quantum nodes.

check_in_delay_event_list(event) bool[source]
handle(node: QNode, event: Event) bool[source]

process the event on the node.

Parameters:
  • node (QNode) – the node that will handle this event

  • event (Event) – the event

Returns:

if skip is True, further applications will not handle this event

Return type:

skip (bool, None)

install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator

Module contents

class qns.network.protocol.BB84RecvApp(src: QNode, qchannel: QuantumChannel, cchannel: ClassicChannel, length_for_post_processing=512, ratio_for_estimating_error=0.2, max_cascade_round=5, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=50, security=0.05)[source]

Bases: Application

check_basis(event: RecvClassicPacket)[source]

Compare measurement bases in BB84RecvApp based on classical information.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleClassicPacket(node: QNode, event: Event) bool[source]

Handle classical packets in BB84RecvApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvClassicPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleQuantumPacket(node: QNode, event: Event) bool[source]

Handle received Qubits in BB84RecvApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvQubitPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv(event: RecvQubitPacket) bool[source]

Receive Qubits in BB84RecvApp, randomly select measurement bases, and measure Qubits.

Parameters:

event – Simulation event for receiving Qubits.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_cascade_reply_packet(event: RecvClassicPacket)[source]

Handle cascade reply packets in BB84RecvApp and execute subsequent cascade rounds.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_check_error_reply_packet(event: RecvClassicPacket)[source]

Handle error verification reply packets in BB84RecvApp.

Parameters:

event – The check_error_reply packet.

recv_error_estimate_reply_packet(event: RecvClassicPacket) bool[source]

Handle error rate estimation reply packets in BB84RecvApp and start the first cascade round.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

send_error_estimate_packet()[source]

Send error rate estimation packets in BB84RecvApp.

class qns.network.protocol.BB84SendApp(dest: QNode, qchannel: QuantumChannel, cchannel: ClassicChannel, send_rate=1000, length_for_post_processing=512, ratio_for_estimating_error=0.2, max_cascade_round=5, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=50, security=0.05)[source]

Bases: Application

check_basis(event: RecvClassicPacket) bool[source]

Compare measurement bases in BB84SendApp based on classical information.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

handleClassicPacket(node: QNode, event: Event) bool[source]

Handle classical packets in BB84SendApp.

Parameters:
  • node – Node.

  • event – Simulation event of type RecvClassicPacket.

Returns:

Whether the simulation event was handled.

Return type:

bool

install(node: QNode, simulator: Simulator)[source]

Deploy BB84SendApp on a node.

Parameters:
  • node – Node.

  • simulator – Simulation scheduler.

recv_cascade_ask_packet(event: RecvClassicPacket) bool[source]

Handle cascade error correction packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_check_error_ask_packet(event: RecvClassicPacket) bool[source]

Handle error verification packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_error_estimate_packet(event: RecvClassicPacket) bool[source]

Handle error rate estimation packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

recv_privacy_amplification_ask_packet(event: RecvClassicPacket) bool[source]

Handle privacy amplification packets in BB84SendApp.

Parameters:

event – Simulation event for receiving classical packets.

Returns:

Whether the simulation event was handled.

Return type:

bool

send_qubit()[source]

Randomly prepare and send Qubits in BB84SendApp.

class qns.network.protocol.ClassicPacketForwardApp(route: RouteImpl)[source]

Bases: Application

This application will generate routing table for classic networks and allow nodes to forward classic packats to the destination.

handleClassicPacket(node: QNode, event: Event)[source]
install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator

class qns.network.protocol.EntanglementDistributionApp(send_rate: int | None = None, init_fidelity: int = 0.99)[source]

Bases: Application

RecvClassicPacketHandler(node: QNode, event: Event)[source]
RecvQubitHandler(node: QNode, event: Event)[source]
generate_qubit(src: QNode, dst: QNode, transmit_id: str | None = None) QuantumModel[source]
handle_response(packet: RecvClassicPacket)[source]
install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator

new_distribution()[source]
request_distrbution(transmit_id: str)[source]
response_distribution(packet: RecvQubitPacket)[source]
set_first_epr(epr: QuantumModel, transmit_id: str)[source]
set_second_epr(epr: QuantumModel, transmit_id: str)[source]
class qns.network.protocol.NodeProcessDelayApp(delay: float = 0, delay_event_list: type | Tuple[type] | None = None)[source]

Bases: Application

This application will add an addition delay whenever the node received an event. It is used to represent the processing delay on quantum nodes.

check_in_delay_event_list(event) bool[source]
handle(node: QNode, event: Event) bool[source]

process the event on the node.

Parameters:
  • node (QNode) – the node that will handle this event

  • event (Event) – the event

Returns:

if skip is True, further applications will not handle this event

Return type:

skip (bool, None)

install(node: QNode, simulator: Simulator)[source]

install initial events for this QNode

Parameters:
  • node (QNode) – the node that will handle this event

  • simulator (Simulator) – the simulator