qns.entity.memory package

Submodules

qns.entity.memory.event module

class qns.entity.memory.event.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.event.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.event.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.event.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

invoke() None[source]

Invoke the event, should be implemented

qns.entity.memory.memory module

exception qns.entity.memory.memory.OutOfMemoryException[source]

Bases: Exception

The exception that the memory is full

class qns.entity.memory.memory.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 and write 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 receiving Event.

Parameters:

event (qns.simulator.event.Event) – the event that send to this entity

install(simulator: Simulator) None[source]

install is called before simulator runs to initialize or set initial events

Parameters:

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

is_full() bool[source]

check whether the memory is full

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

Module contents

class qns.entity.memory.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.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

invoke() None[source]

Invoke the event, should be implemented

class qns.entity.memory.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 and write 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 receiving Event.

Parameters:

event (qns.simulator.event.Event) – the event that send to this entity

install(simulator: Simulator) None[source]

install is called before simulator runs to initialize or set initial events

Parameters:

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

is_full() bool[source]

check whether the memory is full

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