qns.entity package
Subpackages
- qns.entity.cchannel package
- qns.entity.memory package
- qns.entity.monitor package
- qns.entity.node package
- qns.entity.operator package
- qns.entity.qchannel package
- qns.entity.timer package
Submodules
qns.entity.entity module
- class qns.entity.entity.Entity(name: str | None = None)[source]
Bases:
object
This is the basic entity class, including memories, channels and nodes.
- handle(event: Event) None [source]
handle
is called to process an receivingEvent
.- Parameters:
event (qns.simulator.event.Event) – the event that send to this entity
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
Module contents
- class qns.entity.Application[source]
Bases:
object
Application can be deployed on the quantum nodes.
- add_handler(handler, EventTypeList: List = [], ByList: List = [])[source]
Add a handler function to the dispather.
- Parameters:
handler – The handler to process the event. It is an object method whose function signature is the same to
handle
function.EventTypeList – a list of Event Class Type. An empty list meaning to match all events.
ByList – a list of Entities, QNodes or Applications, that generates this event. An empty list meaning to match all entities.
- class qns.entity.ClassicChannel(name: str | None = None, node_list: List[QNode] = [], bandwidth: int = 0, delay: float | DelayModel = 0, length: float | None = 0, drop_rate: float = 0, max_buffer_size: int = 0)[source]
Bases:
Entity
ClassicChannel is the channel for classic message
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- send(packet: ClassicPacket, next_hop: QNode)[source]
Send a classic packet to the next_hop
- Parameters:
packet (ClassicPacket) – the packet
next_hop (QNode) – the next hop QNode
- Raises:
qns.entity.cchannel.cchannel.NextHopNotConnectionException – the next_hop is not connected to this channel
- class qns.entity.ClassicPacket(msg: str | bytes | Any, src: QNode | None = None, dest: QNode | None = None)[source]
Bases:
object
ClassicPacket is the message that transfer on a ClassicChannel
- class qns.entity.Entity(name: str | None = None)[source]
Bases:
object
This is the basic entity class, including memories, channels and nodes.
- handle(event: Event) None [source]
handle
is called to process an receivingEvent
.- Parameters:
event (qns.simulator.event.Event) – the event that send to this entity
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- class qns.entity.MemoryReadRequestEvent(memory, key: QuantumModel | str, t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
MemoryReadRequestEvent
is the event that request a memory read
- class qns.entity.MemoryReadResponseEvent(node: QNode, result: QuantumModel | None = None, request: MemoryReadRequestEvent | None = None, t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
MemoryReadResponseEvent
is the event that returns the memory read result
- class qns.entity.MemoryWriteRequestEvent(memory, qubit: QuantumModel, t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
MemoryWriteRequestEvent
is the event that request a memory write
- class qns.entity.MemoryWriteResponseEvent(node: QNode, result: QuantumModel | None = None, request: MemoryReadRequestEvent | None = None, t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
MemoryWriteResponseEvent
is the event that returns the memory write result
- class qns.entity.Monitor(name: str | None = None, network=None)[source]
Bases:
Entity
- add_attribution(name: str, calculate_func: Callable[[Simulator, Any, Event | None], Any]) None [source]
Set an attribution that will be recorded. For example, an attribution could be the throughput, or the fidelity.
- Parameters:
name (str) – the column’s name, e.g., fidelity, throughput, time …
calculate_func (Callable[[Simulator, Optional[QuantumNetwork], Optional[Event]]) – a function to calculate the value, it has three input parameters (Simulator, QuantumNetwork, Event), and it returns the value.
- Usage:
m = Monitor()
# record the event happening time m.add_attribution(“time”, lambda s,n,e: e.t)
# get the ‘name’ attribution of the last node m.add_attribution(“count”, lambda s,network,e: network.nodes[-1].name)
- at_event(event_type) None [source]
Watch network status whenever the event happends
- Parameters:
event_type (Event) – the watching event
- Usage:
# record network status when a node receives a qubit m.at_event(RecvQubitPacket)
- at_period(period_time: float) None [source]
Watch network status at a constant period.
- Parameters:
period_time (float) – the period of watching network status [s]
- Usage:
# record network status every 3 seconds. m.at_period(3)
- handle(event: Event) None [source]
handle
is called to process an receivingEvent
.- Parameters:
event (qns.simulator.event.Event) – the event that send to this entity
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- class qns.entity.MonitorEvent(t: Time | None, monitor, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
the event that notify the monitor to write down network status
- class qns.entity.OperateRequestEvent(operator, qubits: List[QuantumModel] = [], t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
OperateRequestEvent
is the event that request a operator to handle
- class qns.entity.OperateResponseEvent(node: QNode, result: int | List[int] | None = None, request: OperateRequestEvent | None = None, t: Time | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
OperateResponseEvent
is the event that returns the operating result
- class qns.entity.QNode(name: str | None = None, apps: List[Application] | None = None)[source]
Bases:
Entity
QNode is a quantum node in the quantum network
- add_apps(app: Application)[source]
Insert an Application into the app list.
- Parameters:
app (Application) – the inserting application.
- add_cchannel(cchannel)[source]
Add a classic channel in this QNode
- Parameters:
cchannel (ClassicChannel) – the classic channel
- add_memory(memory)[source]
Add a quantum memory in this QNode
- Parameters:
memory (Memory) – the quantum memory
- add_network(network)[source]
add a network object to this node
- Parameters:
network (qns.network.network.Network) – the network object
- add_operator(operator)[source]
Add a quantum operator in this node
- Parameters:
operator (QuantumOperator) – the quantum operator
- add_qchannel(qchannel)[source]
Add a quantum channel in this QNode
- Parameters:
qchannel (QuantumChannel) – the quantum channel
- add_request(request)[source]
add a request to this node
- Parameters:
request (Request) – the inserting request
- get_apps(app_type)[source]
Get an Application that is app_type
- Parameters:
app_type – the class of app_type
- get_cchannel(dst: QNode)[source]
Get the classic channel that connects to the dst
- Parameters:
dst (QNode) – the destination
- get_memory(memory: str | int)[source]
Get the memory by index (in memories) or its name
- Parameters:
memory (Union[str, int]) – the index or name of the memory
- get_qchannel(dst: QNode)[source]
Get the quantum channel that connects to the dst
- Parameters:
dst (QNode) – the destination
- handle(event: Event) None [source]
This function will handle an Event. This event will be passed to every applications in apps list in order.
- Parameters:
event (Event) – the event that happens on this QNode
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- class qns.entity.QuantumChannel(name: str | None = None, node_list: List[QNode] = [], bandwidth: int = 0, delay: float | DelayModel = 0, drop_rate: float = 0, max_buffer_size: int = 0, length: float = 0, decoherence_rate: float | None = 0, transfer_error_model_args: dict = {})[source]
Bases:
Entity
QuantumChannel is the channel for transmitting qubit
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (Simulator) – the simulator
- send(qubit: QuantumModel, next_hop: QNode)[source]
Send a qubit to the next_hop
- Parameters:
qubit (QuantumModel) – the transmitting qubit
next_hop (QNode) – the next hop QNode
- Raises:
NextHopNotConnectionException – the next_hop is not connected to this channel
- class qns.entity.QuantumMemory(name: str | None = None, node: QNode | None = None, capacity: int = 0, decoherence_rate: float | None = 0, store_error_model_args: dict = {}, delay: float | DelayModel = 0)[source]
Bases:
Entity
Quantum memory stores qubits or entangled pairs.
- It has two modes:
Synchronous mode, users can use the
read
andwrite
function to operate the memory directly without delay Asynchronous mode, users can use events to operate memories asynchronously
- property count: int
return the current memory usage
- get(key: QuantumModel | str | int) QuantumModel | None [source]
get a qubit from the memory but without removing it from the memory
- Parameters:
key (Union[QuantumModel, str, int]) – the key. It can be a QuantumModel object, its name or the index number.
- get_store_time(key: QuantumModel | str | int) QuantumModel | None [source]
get the store time of a qubit from the memory
- Parameters:
key (Union[QuantumModel, str, int]) – the key. It can be a QuantumModel object, its name or the index number.
- handle(event: Event) None [source]
handle
is called to process an receivingEvent
.- Parameters:
event (qns.simulator.event.Event) – the event that send to this entity
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- read(key: QuantumModel | str) QuantumModel | None [source]
The API for reading a qubit from the memory
- Parameters:
key (Union[QuantumModel, str]) – the key. It can be a QuantumModel object, its name or the index number.
- write(qm: QuantumModel) bool [source]
The API for storing a qubit to the memory
- Parameters:
qm (QuantumModel) – the QuantumModel, could be a qubit or an entangled pair
- Returns:
whether the qubit is stored successfully
- Return type:
bool
- class qns.entity.QuantumOperator(name: str | None = None, node: QNode | None = None, gate: Callable[[...], None | int | List[int]] | None = None, delay: float | DelayModel = 0)[source]
Bases:
Entity
Quantum operator can perfrom quantum operation or measurements on qubits. It has two modes:
Synchronous mode, users can use the operate function to operate qubits directly without delay Asynchronous mode, users will use events to operate quantum operations asynchronously
- handle(event: Event) None [source]
handle
is called to process an receivingEvent
.- Parameters:
event (qns.simulator.event.Event) – the event that send to this entity
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator
- class qns.entity.RecvClassicPacket(t: Time | None = None, name: str | None = None, cchannel: ClassicChannel | None = None, packet: ClassicPacket | None = None, dest: QNode | None = None, by: Any | None = None)[source]
Bases:
Event
The event for a QNode to receive a classic packet
- class qns.entity.RecvQubitPacket(t: Time | None = None, qchannel: QuantumChannel | None = None, qubit: QuantumModel | None = None, dest: QNode | None = None, name: str | None = None, by: Any | None = None)[source]
Bases:
Event
The event for a QNode to receive a classic packet
- class qns.entity.Timer(name: str, start_time: float, end_time: float = 0, step_time: float = 1, trigger_func=None)[source]
Bases:
Entity
A Timer is an Entity that trigger the function trigger_func one-shot or periodically.
- install(simulator: Simulator) None [source]
install
is called beforesimulator
runs to initialize or set initial events- Parameters:
simulator (qns.simulator.simulator.Simulator) – the simulator