qns.entity.memory package
Submodules
qns.entity.memory.event module
- class qns.entity.memory.event.MemoryReadRequestEvent(memory, key: Union[qns.models.core.backend.QuantumModel, str], t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryReadRequestEvent
is the event that request a memory read
- class qns.entity.memory.event.MemoryReadResponseEvent(node: qns.entity.node.node.QNode, result: Optional[qns.models.core.backend.QuantumModel] = None, request: Optional[qns.entity.memory.event.MemoryReadRequestEvent] = None, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryReadResponseEvent
is the event that returns the memory read result
- class qns.entity.memory.event.MemoryWriteRequestEvent(memory, qubit: qns.models.core.backend.QuantumModel, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryWriteRequestEvent
is the event that request a memory write
- class qns.entity.memory.event.MemoryWriteResponseEvent(node: qns.entity.node.node.QNode, result: Optional[qns.models.core.backend.QuantumModel] = None, request: Optional[qns.entity.memory.event.MemoryReadRequestEvent] = None, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryWriteResponseEvent
is the event that returns the memory write result
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: Optional[str] = None, node: Optional[qns.entity.node.node.QNode] = None, capacity: int = 0, decoherence_rate: Optional[float] = 0, store_error_model_args: dict = {}, delay: Union[float, qns.models.delay.delay.DelayModel] = 0)[source]
Bases:
qns.entity.entity.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: Union[qns.models.core.backend.QuantumModel, str, int]) Optional[qns.models.core.backend.QuantumModel] [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: Union[qns.models.core.backend.QuantumModel, str, int]) Optional[qns.models.core.backend.QuantumModel] [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: qns.simulator.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: qns.simulator.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: Union[qns.models.core.backend.QuantumModel, str]) Optional[qns.models.core.backend.QuantumModel] [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: qns.models.core.backend.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: Union[qns.models.core.backend.QuantumModel, str], t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryReadRequestEvent
is the event that request a memory read
- class qns.entity.memory.MemoryReadResponseEvent(node: qns.entity.node.node.QNode, result: Optional[qns.models.core.backend.QuantumModel] = None, request: Optional[qns.entity.memory.event.MemoryReadRequestEvent] = None, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryReadResponseEvent
is the event that returns the memory read result
- class qns.entity.memory.MemoryWriteRequestEvent(memory, qubit: qns.models.core.backend.QuantumModel, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryWriteRequestEvent
is the event that request a memory write
- class qns.entity.memory.MemoryWriteResponseEvent(node: qns.entity.node.node.QNode, result: Optional[qns.models.core.backend.QuantumModel] = None, request: Optional[qns.entity.memory.event.MemoryReadRequestEvent] = None, t: Optional[qns.simulator.ts.Time] = None, name: Optional[str] = None, by: Optional[Any] = None)[source]
Bases:
qns.simulator.event.Event
MemoryWriteResponseEvent
is the event that returns the memory write result
- class qns.entity.memory.QuantumMemory(name: Optional[str] = None, node: Optional[qns.entity.node.node.QNode] = None, capacity: int = 0, decoherence_rate: Optional[float] = 0, store_error_model_args: dict = {}, delay: Union[float, qns.models.delay.delay.DelayModel] = 0)[source]
Bases:
qns.entity.entity.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: Union[qns.models.core.backend.QuantumModel, str, int]) Optional[qns.models.core.backend.QuantumModel] [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: Union[qns.models.core.backend.QuantumModel, str, int]) Optional[qns.models.core.backend.QuantumModel] [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: qns.simulator.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: qns.simulator.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: Union[qns.models.core.backend.QuantumModel, str]) Optional[qns.models.core.backend.QuantumModel] [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: qns.models.core.backend.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