qns.network.protocol package

Submodules

qns.network.protocol.bb84 module

class qns.network.protocol.bb84.BB84RecvApp(src: qns.entity.node.node.QNode, qchannel: qns.entity.qchannel.qchannel.QuantumChannel, cchannel: qns.entity.cchannel.cchannel.ClassicChannel, min_length_for_post_processing=5000, proportion_for_estimating_error=0.4, max_cascade_round=4, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=20, security=0.05)[source]

Bases: qns.entity.node.app.Application

check_basis(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
handleQuantumPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
recv(event: qns.entity.qchannel.qchannel.RecvQubitPacket)[source]
recv_cascade_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv cascade_reply packet,perform next round of cascade,and send cascade_ask packet.

Parameters

event – the cascade_reply packet.

recv_check_error_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv check_error_reply packet,perform privacy amplification,and send privacy_amplification_ask packet.

Parameters

event – the check_error_reply packet.

recv_error_estimate_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv error_estimate_reply packet,perform the first round of cascade,send cascade_ask packet.

Parameters

event – the error_estimate_reply packet.

send_error_estimate_packet()[source]

BB84Recvapp send error estimate ask packet.

class qns.network.protocol.bb84.BB84SendApp(dest: qns.entity.node.node.QNode, qchannel: qns.entity.qchannel.qchannel.QuantumChannel, cchannel: qns.entity.cchannel.cchannel.ClassicChannel, send_rate=1000, min_length_for_post_processing=5000, proportion_for_estimating_error=0.4, max_cascade_round=4, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=20, security=0.05)[source]

Bases: qns.entity.node.app.Application

check_basis(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.simulator.Simulator)[source]

install initial events for this QNode

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

  • simulator (Simulator) – the simulator

recv_cascade_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv cascade_ask packet,calculate the parity value of the corresponding block,and send cascade_reply packet.

Parameters

event – the cascade_ask packet.

recv_check_error_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv check_error_ask packet,check error,and send check_error_reply packet.

Parameters

event – the check_error_ask packet.

recv_error_estimate_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv error estimate packet,and send error_estimate_reply packet.

Parameters

event – the error estimate packet.

recv_privacy_amplification_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv privacy_amplification_ask packet,perform privacy amplification.

Parameters

event – the privacy_amplification_ask packet.

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

Bases: qns.models.qubit.qubit.Qubit

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

The default error model for transmitting this qubit The default behavior is doing nothing

Parameters
  • length (float) – the length of the channel

  • decoherence_rate (float) – the decoherence rate

  • kwargs – other parameters

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

Evenly divided the key block.

Parameters
  • begin – key block begin index.

  • end – key block end index.

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

Shuffle the index.

Parameters

index – the index list.

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

Calculate key block parity.

Parameters

target – target key block.

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 using two given list of binary values.

Parameters
  • N – col num of the Toeplitz matrix.

  • M – row num of the Toeplitz matrix.

  • first_row – first row of the Toeplitz matrix.

  • first_col – first col of the Toeplitz matrix.

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

process the original key through the toeplitz matrix.

Parameters
  • original_key – the original key.

  • toeplitz_matrix – the toeplitz matrix.

qns.network.protocol.classicforward module

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

Bases: qns.entity.node.app.Application

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

handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.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: Optional[int] = None, init_fidelity: float = 0.99)[source]

Bases: qns.entity.node.app.Application

RecvClassicPacketHandler(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
RecvQubitHandler(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
generate_qubit(src: qns.entity.node.node.QNode, dst: qns.entity.node.node.QNode, transmit_id: Optional[str] = None) qns.models.core.backend.QuantumModel[source]
handle_response(packet: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.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: qns.entity.qchannel.qchannel.RecvQubitPacket)[source]
set_first_epr(epr: qns.models.core.backend.QuantumModel, transmit_id: str)[source]
set_second_epr(epr: qns.models.core.backend.QuantumModel, transmit_id: str)[source]
class qns.network.protocol.entanglement_distribution.Transmit(id: str, src: qns.entity.node.node.QNode, dst: qns.entity.node.node.QNode, first_epr_name: Optional[str] = None, second_epr_name: Optional[str] = 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: Optional[Union[type, Tuple[type]]] = None)[source]

Bases: qns.entity.node.app.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: qns.entity.node.node.QNode, event: qns.simulator.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: qns.entity.node.node.QNode, simulator: qns.simulator.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: qns.entity.node.node.QNode, qchannel: qns.entity.qchannel.qchannel.QuantumChannel, cchannel: qns.entity.cchannel.cchannel.ClassicChannel, min_length_for_post_processing=5000, proportion_for_estimating_error=0.4, max_cascade_round=4, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=20, security=0.05)[source]

Bases: qns.entity.node.app.Application

check_basis(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
handleQuantumPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
recv(event: qns.entity.qchannel.qchannel.RecvQubitPacket)[source]
recv_cascade_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv cascade_reply packet,perform next round of cascade,and send cascade_ask packet.

Parameters

event – the cascade_reply packet.

recv_check_error_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv check_error_reply packet,perform privacy amplification,and send privacy_amplification_ask packet.

Parameters

event – the check_error_reply packet.

recv_error_estimate_reply_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84RecvApp recv error_estimate_reply packet,perform the first round of cascade,send cascade_ask packet.

Parameters

event – the error_estimate_reply packet.

send_error_estimate_packet()[source]

BB84Recvapp send error estimate ask packet.

class qns.network.protocol.BB84SendApp(dest: qns.entity.node.node.QNode, qchannel: qns.entity.qchannel.qchannel.QuantumChannel, cchannel: qns.entity.cchannel.cchannel.ClassicChannel, send_rate=1000, min_length_for_post_processing=5000, proportion_for_estimating_error=0.4, max_cascade_round=4, cascade_alpha=0.73, cascade_beita=2, init_lower_cascade_key_block_size=5, init_upper_cascade_key_block_size=20, security=0.05)[source]

Bases: qns.entity.node.app.Application

check_basis(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.simulator.Simulator)[source]

install initial events for this QNode

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

  • simulator (Simulator) – the simulator

recv_cascade_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv cascade_ask packet,calculate the parity value of the corresponding block,and send cascade_reply packet.

Parameters

event – the cascade_ask packet.

recv_check_error_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv check_error_ask packet,check error,and send check_error_reply packet.

Parameters

event – the check_error_ask packet.

recv_error_estimate_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv error estimate packet,and send error_estimate_reply packet.

Parameters

event – the error estimate packet.

recv_privacy_amplification_ask_packet(event: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]

BB84SendApp recv privacy_amplification_ask packet,perform privacy amplification.

Parameters

event – the privacy_amplification_ask packet.

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

Bases: qns.entity.node.app.Application

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

handleClassicPacket(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.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: Optional[int] = None, init_fidelity: float = 0.99)[source]

Bases: qns.entity.node.app.Application

RecvClassicPacketHandler(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
RecvQubitHandler(node: qns.entity.node.node.QNode, event: qns.simulator.event.Event)[source]
generate_qubit(src: qns.entity.node.node.QNode, dst: qns.entity.node.node.QNode, transmit_id: Optional[str] = None) qns.models.core.backend.QuantumModel[source]
handle_response(packet: qns.entity.cchannel.cchannel.RecvClassicPacket)[source]
install(node: qns.entity.node.node.QNode, simulator: qns.simulator.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: qns.entity.qchannel.qchannel.RecvQubitPacket)[source]
set_first_epr(epr: qns.models.core.backend.QuantumModel, transmit_id: str)[source]
set_second_epr(epr: qns.models.core.backend.QuantumModel, transmit_id: str)[source]
class qns.network.protocol.NodeProcessDelayApp(delay: float = 0, delay_event_list: Optional[Union[type, Tuple[type]]] = None)[source]

Bases: qns.entity.node.app.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: qns.entity.node.node.QNode, event: qns.simulator.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: qns.entity.node.node.QNode, simulator: qns.simulator.simulator.Simulator)[source]

install initial events for this QNode

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

  • simulator (Simulator) – the simulator