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
- 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
- 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
- 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.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.
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
- generate_qubit(src: QNode, dst: QNode, transmit_id: str | None = None) QuantumModel [source]
- handle_response(packet: RecvClassicPacket)[source]
- response_distribution(packet: RecvQubitPacket)[source]
- set_first_epr(epr: QuantumModel, transmit_id: str)[source]
- set_second_epr(epr: QuantumModel, transmit_id: str)[source]
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.
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
- 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
- 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.
- class qns.network.protocol.EntanglementDistributionApp(send_rate: int | None = None, init_fidelity: int = 0.99)[source]
Bases:
Application
- generate_qubit(src: QNode, dst: QNode, transmit_id: str | None = None) QuantumModel [source]
- handle_response(packet: RecvClassicPacket)[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.