qns.network package

Subpackages

Submodules

qns.network.network module

exception qns.network.network.QNSNetworkError[source]

Bases: Exception

class qns.network.network.QuantumNetwork(topo: Topology | None = None, route: RouteImpl | None = None, classic_topo: ClassicTopology | None = ClassicTopology.Empty, name: str | None = None)[source]

Bases: object

QuantumNetwork includes several quantum nodes, channels and a special topology

add_cchannel(cchannel: ClassicChannel)[source]

add a ClassicChannel into this network.

Parameters:

cchannel (qns.entity.cchannel.cchannel.ClassicChannel) – the inserting ClassicChannel

add_memories(capacity: int = 0, decoherence_rate: float | None = 0, store_error_model_args: dict = {})[source]

Add quantum memories to every nodes in this network

Parameters:
  • capacity (int) – the capacity of the quantum memory

  • decoherence_rate (float) – the decoherence rate

  • store_error_model_args – the arguments for store_error_model

add_node(node: QNode)[source]

add a QNode into this network.

Parameters:

node (qns.entity.node.node.QNode) – the inserting node

add_qchannel(qchannel: QuantumChannel)[source]

add a QuantumChannel into this network.

Parameters:

qchannel (qns.entity.qchannel.qchannel.QuantumChannel) – the inserting QuantumChannel

add_request(src: QNode, dest: QNode, attr: Dict = {})[source]

Add a request (SD-pair) to the network

Parameters:
  • src – the source node

  • dest – the destination node

  • attr – other attributions

build_route()[source]

build static route tables for each nodes

get_cchannel(name: str)[source]

get the ClassicChannel by its name

Parameters:

name (str) – its name

Returns:

the ClassicChannel

get_node(name: str)[source]

get the QNode by its name

Parameters:

name (str) – its name

Returns:

the QNode

get_qchannel(name: str)[source]

get the QuantumChannel by its name

Parameters:

name (str) – its name

Returns:

the QuantumChannel

install(s: Simulator)[source]

install all nodes (including channels, memories and applications) in this network

Parameters:

simulator (qns.simulator.simulator.Simulator) – the simulator

query_route(src: QNode, dest: QNode) List[Tuple[float, QNode, List[QNode]]][source]

query the metric, nexthop and the path

Parameters:
  • src – the source node

  • dest – the destination node

Returns:

A list of route paths. The result should be sortted by the priority. The element is a tuple containing: metric, the next-hop and the whole path.

random_requests(number: int, allow_overlay: bool = False, attr: Dict = {})[source]

Generate random requests

Parameters:
  • number (int) – the number of requests

  • allow_overlay (bool) – allow a node to be the source or destination in multiple requests

  • attr (Dict) – request attributions

qns.network.requests module

class qns.network.requests.Request(src, dest, attr: Dict = {})[source]

Bases: object

A request is a source-destination pair represents a quantum transmitting request.

Module contents

class qns.network.BarabasiAlbertTopology(nodes_number, new_nodes_egdes: int, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

BarabasiAlbertTopology is a random topology generator based on the Barabasi-Albert model. Each new QNode added has new_nodes_egdes to existing QNodes. The probability of a new QNode connecting to an existing QNode is proportional to the degree of the existing QNode.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.BasicTopology(nodes_number, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

BasicTopology includes nodes_number Qnodes. None of them are connected with each other

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.DijkstraRouteAlgorithm(name: str = 'dijkstra', metric_func: Callable[[QuantumChannel | ClassicChannel], float] | None = None)[source]

Bases: RouteImpl

This is the dijkstra route algorithm implement

INF = inf
build(nodes: List[QNode], channels: List[QuantumChannel | ClassicChannel])[source]

build static route tables for each nodes

Parameters:

channels – a list of quantum channels or classic channels

query(src: QNode, dest: QNode) List[Tuple[float, QNode, List[QNode]]][source]

query the metric, nexthop and the path

Parameters:
  • src – the source node

  • dest – the destination node

Returns:

A list of route paths. The result should be sortted by the priority. The element is a tuple containing: metric, the next-hop and the whole path.

class qns.network.DualBarabasiAlbertTopology(nodes_number, edges_num1: int, edges_num2: int, prob: float, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

DualBarabasiAlbertTopology is a random topology generator based on the Dual Barabasi-Albert model. Each new QNode added has either edges_num1 or edges_num2 edges to existing QNodes. The probability of a new QNode connecting to an existing QNode is proportional to the degree of the existing QNode.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.ErdosRenyiTopology(nodes_number, generate_prob: float, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

ErdosRenyiTopology includes nodes_number Qnodes. The topology is randomly generated following the Erdos-Renyi model(G(n,p) Model). Each pair of Qnodes has a probability generate_prob to be connected by a QuantumChannel.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.GridTopology(nodes_number, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

GridTopology includes nodes_number Qnodes. nodes_number should be a perfect square number. The topology is a square grid pattern, where each node has 4 neighbors.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.LineTopology(nodes_number, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

LineTopology includes nodes_number Qnodes. The topology is a line pattern.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

exception qns.network.NetworkRouteError[source]

Bases: Exception

exception qns.network.QNSNetworkError[source]

Bases: Exception

class qns.network.QuantumNetwork(topo: Topology | None = None, route: RouteImpl | None = None, classic_topo: ClassicTopology | None = ClassicTopology.Empty, name: str | None = None)[source]

Bases: object

QuantumNetwork includes several quantum nodes, channels and a special topology

add_cchannel(cchannel: ClassicChannel)[source]

add a ClassicChannel into this network.

Parameters:

cchannel (qns.entity.cchannel.cchannel.ClassicChannel) – the inserting ClassicChannel

add_memories(capacity: int = 0, decoherence_rate: float | None = 0, store_error_model_args: dict = {})[source]

Add quantum memories to every nodes in this network

Parameters:
  • capacity (int) – the capacity of the quantum memory

  • decoherence_rate (float) – the decoherence rate

  • store_error_model_args – the arguments for store_error_model

add_node(node: QNode)[source]

add a QNode into this network.

Parameters:

node (qns.entity.node.node.QNode) – the inserting node

add_qchannel(qchannel: QuantumChannel)[source]

add a QuantumChannel into this network.

Parameters:

qchannel (qns.entity.qchannel.qchannel.QuantumChannel) – the inserting QuantumChannel

add_request(src: QNode, dest: QNode, attr: Dict = {})[source]

Add a request (SD-pair) to the network

Parameters:
  • src – the source node

  • dest – the destination node

  • attr – other attributions

build_route()[source]

build static route tables for each nodes

get_cchannel(name: str)[source]

get the ClassicChannel by its name

Parameters:

name (str) – its name

Returns:

the ClassicChannel

get_node(name: str)[source]

get the QNode by its name

Parameters:

name (str) – its name

Returns:

the QNode

get_qchannel(name: str)[source]

get the QuantumChannel by its name

Parameters:

name (str) – its name

Returns:

the QuantumChannel

install(s: Simulator)[source]

install all nodes (including channels, memories and applications) in this network

Parameters:

simulator (qns.simulator.simulator.Simulator) – the simulator

query_route(src: QNode, dest: QNode) List[Tuple[float, QNode, List[QNode]]][source]

query the metric, nexthop and the path

Parameters:
  • src – the source node

  • dest – the destination node

Returns:

A list of route paths. The result should be sortted by the priority. The element is a tuple containing: metric, the next-hop and the whole path.

random_requests(number: int, allow_overlay: bool = False, attr: Dict = {})[source]

Generate random requests

Parameters:
  • number (int) – the number of requests

  • allow_overlay (bool) – allow a node to be the source or destination in multiple requests

  • attr (Dict) – request attributions

class qns.network.RandomTopology(nodes_number, lines_number: int, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

RandomTopology includes nodes_number Qnodes. The topology is randomly generated.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.Request(src, dest, attr: Dict = {})[source]

Bases: object

A request is a source-destination pair represents a quantum transmitting request.

class qns.network.RouteImpl(name: str = 'route')[source]

Bases: object

This is the route protocol interface

build(nodes: List[QNode], channels: List[QuantumChannel | ClassicChannel])[source]

build static route tables for each nodes

Parameters:

channels – a list of quantum channels or classic channels

query(src: QNode, dest: QNode) List[Tuple[float, QNode, List[QNode]]][source]

query the metric, nexthop and the path

Parameters:
  • src – the source node

  • dest – the destination node

Returns:

A list of route paths. The result should be sortted by the priority. The element is a tuple containing: metric, the next-hop and the whole path.

class qns.network.Topology(nodes_number: int, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: object

Topology is a factory for QuantumNetwork

add_cchannels(classic_topo: ClassicTopology = ClassicTopology.Empty, nl: List[QNode] = [], ll: List[QuantumChannel] | None = None)[source]

build classic network topology

Parameters:
build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.TreeTopology(nodes_number, children_number: int = 2, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

TreeTopology includes nodes_number Qnodes. The topology is a tree pattern, where each parent has children_num children.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel

class qns.network.WaxmanTopology(nodes_number: int, size: float, alpha: float, beta: float, nodes_apps: List[Application] = [], qchannel_args: Dict = {}, cchannel_args: Dict = {}, memory_args: List[Dict] | None = {})[source]

Bases: Topology

WaxmanTopology is the random topology generator using Waxman’s model.

build() Tuple[List[QNode], List[QuantumChannel]][source]

build the special topology

Returns:

the list of QNodes and the list of QuantumChannel