Loop
A set of tools for quantum calculations.
A Qubit in a regular computer is quantum of algorithm that is executed in one iteration of a cycle in a separate processor thread.
Quantum is a function with an algorithm of task for data processing.
In this case, the Qubit is not a single information, but it is a concept of the principle of operation of quantum calculations on a regular computer.
The module contains the following tools:
QuantumLoop- Separation of the cycle into quantum algorithms for multiprocessing data processing.
QuantumLoop
¶
Separation of the cycle into quantum algorithms for multiprocessing data processing.
Examples:
>>> from ql import QuantumLoop
>>> def task(num: int) -> int | None:
... return num * num if num % 2 == 0 else None
>>> data = range(1, 10)
>>> QuantumLoop(task, data).run()
[4, 16, 36, 64]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Callable
|
Function with a task algorithm. |
required |
data
|
Iterable[Any]
|
The data that needs to be processed. |
required |
max_workers
|
int | None
|
The maximum number of processes that can be used to execute the given calls. If None or not given then as many worker processes will be created as the machine has processors. |
None
|
timeout
|
float | None
|
The number of seconds to wait for the result if the future isn't done. If None, then there is no limit on the wait time. |
None
|
mode
|
LoopMode
|
The operating mode for a quantum loop: LoopMode.PROCESS_POOL | LoopMode.THREAD_POOL. |
PROCESS_POOL
|
Source code in src/ql/loop.py
process_pool()
¶
Better suitable for operations for which large processor resources are required.
Source code in src/ql/loop.py
run()
¶
Run the quantum loop.
Source code in src/ql/loop.py
thread_pool()
¶
More suitable for tasks related to input-output (for example, network queries, file operations), where GIL is freed during input-output operations.