quantum-loop 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of quantum-loop might be problematic. Click here for more details.
- quantum_loop/__init__.py +20 -0
- quantum_loop/loop.py +132 -0
- quantum_loop/py.typed +0 -0
- quantum_loop-0.1.0.dist-info/METADATA +115 -0
- quantum_loop-0.1.0.dist-info/RECORD +7 -0
- quantum_loop-0.1.0.dist-info/WHEEL +4 -0
- quantum_loop-0.1.0.dist-info/licenses/LICENSE +21 -0
quantum_loop/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""A set of tools for quantum calculations.
|
|
2
|
+
|
|
3
|
+
A Qubit in a regular computer is quantum of algorithm that is executed in
|
|
4
|
+
one iteration of a cycle in a separate processor thread.
|
|
5
|
+
|
|
6
|
+
Quantum is a function with an algorithm of task for data processing.
|
|
7
|
+
|
|
8
|
+
In this case, the Qubit is not a single information,
|
|
9
|
+
but it is a concept of the principle of operation of quantum calculations on a regular computer.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
__all__ = (
|
|
15
|
+
"LoopMode",
|
|
16
|
+
"QuantumLoop",
|
|
17
|
+
"count_qubits",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from quantum_loop.loop import LoopMode, QuantumLoop, count_qubits
|
quantum_loop/loop.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""A set of tools for quantum calculations.
|
|
2
|
+
|
|
3
|
+
A Qubit in a regular computer is quantum of algorithm that is executed in
|
|
4
|
+
one iteration of a cycle in a separate processor thread.
|
|
5
|
+
|
|
6
|
+
Quantum is a function with an algorithm of task for data processing.
|
|
7
|
+
|
|
8
|
+
In this case, the Qubit is not a single information,
|
|
9
|
+
but it is a concept of the principle of operation of quantum calculations on a regular computer.
|
|
10
|
+
|
|
11
|
+
The module contains the following tools:
|
|
12
|
+
|
|
13
|
+
- `LoopMode` - Quantum loop mode.
|
|
14
|
+
- `count_qubits()` - Counting the number of conceptual qubits of your computer.
|
|
15
|
+
- `QuantumLoop` - Separation of the cycle into quantum algorithms for multiprocessing data processing.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import concurrent.futures
|
|
21
|
+
import multiprocessing
|
|
22
|
+
from collections.abc import Callable, Iterable
|
|
23
|
+
from enum import Enum
|
|
24
|
+
from typing import Any, Never, assert_never
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class LoopMode(Enum):
|
|
28
|
+
"""Quantum loop mode."""
|
|
29
|
+
|
|
30
|
+
PROCESS_POOL = 1
|
|
31
|
+
THREAD_POOL = 2
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def count_qubits() -> int:
|
|
35
|
+
"""Counting the number of conceptual qubits of your computer.
|
|
36
|
+
|
|
37
|
+
Conceptual qubit is quantum of algorithm (task) that is executed in
|
|
38
|
+
iterations of a cycle in a separate processor thread.
|
|
39
|
+
|
|
40
|
+
Quantum of algorithm is a function for data processing.
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
>>> from xloft.quantum import count_qubits
|
|
44
|
+
>>> count_qubits()
|
|
45
|
+
16
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
The number of conceptual qubits.
|
|
49
|
+
"""
|
|
50
|
+
return multiprocessing.cpu_count()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class QuantumLoop:
|
|
54
|
+
"""Separation of the cycle into quantum algorithms for multiprocessing data processing.
|
|
55
|
+
|
|
56
|
+
Examples:
|
|
57
|
+
>>> from xloft.quantum import QuantumLoop
|
|
58
|
+
>>> def task(item):
|
|
59
|
+
... return item * item
|
|
60
|
+
>>> data = range(10)
|
|
61
|
+
>>> QuantumLoop(task, data).run()
|
|
62
|
+
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
task: Function with a task algorithm.
|
|
66
|
+
data: The data that needs to be processed.
|
|
67
|
+
max_workers: The maximum number of processes that can be used to
|
|
68
|
+
execute the given calls. If None or not given then as many
|
|
69
|
+
worker processes will be created as the machine has processors.
|
|
70
|
+
timeout: The maximum number of seconds to wait. If None, then there
|
|
71
|
+
is no limit on the wait time.
|
|
72
|
+
chunksize: The size of the chunks the iterable will be broken into
|
|
73
|
+
before being passed to a child process. This argument is only
|
|
74
|
+
used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
|
|
75
|
+
mode: The operating mode for a quantum loop: LoopMode.PROCESS_POOL | LoopMode.THREAD_POOL.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
def __init__( # noqa: D107
|
|
79
|
+
self,
|
|
80
|
+
task: Callable,
|
|
81
|
+
data: Iterable[Any],
|
|
82
|
+
max_workers: int | None = None,
|
|
83
|
+
timeout: float | None = None,
|
|
84
|
+
chunksize: int = 1,
|
|
85
|
+
mode: LoopMode = LoopMode.PROCESS_POOL,
|
|
86
|
+
) -> None:
|
|
87
|
+
self.quantum = task
|
|
88
|
+
self.data = data
|
|
89
|
+
self.max_workers = max_workers
|
|
90
|
+
self.timeout = timeout
|
|
91
|
+
self.chunksize = chunksize
|
|
92
|
+
self.mode = mode
|
|
93
|
+
|
|
94
|
+
def process_pool(self) -> list[Any]:
|
|
95
|
+
"""Better suitable for operations for which large processor resources are required."""
|
|
96
|
+
with concurrent.futures.ProcessPoolExecutor(self.max_workers) as executor:
|
|
97
|
+
results = list(
|
|
98
|
+
executor.map(
|
|
99
|
+
self.quantum,
|
|
100
|
+
self.data,
|
|
101
|
+
timeout=self.timeout,
|
|
102
|
+
chunksize=self.chunksize,
|
|
103
|
+
),
|
|
104
|
+
)
|
|
105
|
+
return results # noqa: RET504
|
|
106
|
+
|
|
107
|
+
def thread_pool(self) -> list[Any]:
|
|
108
|
+
"""More suitable for tasks related to input-output
|
|
109
|
+
(for example, network queries, file operations),
|
|
110
|
+
where GIL is freed during input-output operations.""" # noqa: D205, D209
|
|
111
|
+
with concurrent.futures.ThreadPoolExecutor(self.max_workers) as executor:
|
|
112
|
+
results = list(
|
|
113
|
+
executor.map(
|
|
114
|
+
self.quantum,
|
|
115
|
+
self.data,
|
|
116
|
+
timeout=self.timeout,
|
|
117
|
+
chunksize=self.chunksize,
|
|
118
|
+
),
|
|
119
|
+
)
|
|
120
|
+
return results # noqa: RET504
|
|
121
|
+
|
|
122
|
+
def run(self) -> list[Any]:
|
|
123
|
+
"""Run the quantum loop."""
|
|
124
|
+
results: list[Any] = []
|
|
125
|
+
match self.mode.value:
|
|
126
|
+
case 1:
|
|
127
|
+
results = self.process_pool()
|
|
128
|
+
case 2:
|
|
129
|
+
results = self.thread_pool()
|
|
130
|
+
case _ as unreachable:
|
|
131
|
+
assert_never(Never(unreachable))
|
|
132
|
+
return results
|
quantum_loop/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quantum-loop
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A set of tools for quantum calculations.
|
|
5
|
+
Project-URL: Homepage, https://github.com/kebasyaty/quantum-loop
|
|
6
|
+
Project-URL: Repository, https://github.com/kebasyaty/quantum-loop
|
|
7
|
+
Project-URL: Source, https://github.com/kebasyaty/quantum-loop
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/kebasyaty/quantum-loop/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/kebasyaty/quantum-loop/blob/v0/CHANGELOG.md
|
|
10
|
+
Author-email: kebasyaty <kebasyaty@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: loop,quantum,quantum-loop,qubit
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
+
Classifier: Operating System :: POSIX
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: <4.0,>=3.12
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
<div align="center">
|
|
31
|
+
<p align="center">
|
|
32
|
+
<a href="https://github.com/kebasyaty/quantum-loop">
|
|
33
|
+
<img
|
|
34
|
+
height="90"
|
|
35
|
+
alt="Logo"
|
|
36
|
+
src="https://raw.githubusercontent.com/kebasyaty/quantum-loop/main/assets/logo.svg">
|
|
37
|
+
</a>
|
|
38
|
+
</p>
|
|
39
|
+
<p>
|
|
40
|
+
<h1>Quantum Loop</h1>
|
|
41
|
+
<h3>A set of tools for quantum-loop calculations.</h3>
|
|
42
|
+
<p align="center">
|
|
43
|
+
<a href="https://github.com/kebasyaty/quantum-loop/actions/workflows/test.yml" alt="Build Status"><img src="https://github.com/kebasyaty/quantum-loop/actions/workflows/test.yml/badge.svg" alt="Build Status"></a>
|
|
44
|
+
<a href="https://kebasyaty.github.io/quantum-loop/" alt="Docs"><img src="https://img.shields.io/badge/docs-available-brightgreen.svg" alt="Docs"></a>
|
|
45
|
+
<a href="https://pypi.python.org/pypi/quantum-loop/" alt="PyPI pyversions"><img src="https://img.shields.io/pypi/pyversions/quantum-loop.svg" alt="PyPI pyversions"></a>
|
|
46
|
+
<a href="https://pypi.python.org/pypi/quantum-loop/" alt="PyPI status"><img src="https://img.shields.io/pypi/status/quantum-loop.svg" alt="PyPI status"></a>
|
|
47
|
+
<a href="https://pypi.python.org/pypi/quantum-loop/" alt="PyPI version fury.io"><img src="https://badge.fury.io/py/quantum-loop.svg" alt="PyPI version fury.io"></a>
|
|
48
|
+
<br>
|
|
49
|
+
<a href="https://github.com/kebasyaty/quantum-loop/issues"><img src="https://img.shields.io/github/issues/kebasyaty/quantum-loop.svg" alt="GitHub issues"></a>
|
|
50
|
+
<a href="https://pepy.tech/projects/quantum-loop"><img src="https://static.pepy.tech/badge/quantum-loop" alt="PyPI Downloads"></a>
|
|
51
|
+
<a href="https://github.com/kebasyaty/quantum-loop/blob/main/LICENSE" alt="GitHub license"><img src="https://img.shields.io/github/license/kebasyaty/quantum-loop" alt="GitHub license"></a>
|
|
52
|
+
<a href="https://mypy-lang.org/" alt="Types: Mypy"><img src="https://img.shields.io/badge/types-Mypy-202235.svg?color=0c7ebf" alt="Types: Mypy"></a>
|
|
53
|
+
<a href="https://docs.astral.sh/ruff/" alt="Code style: Ruff"><img src="https://img.shields.io/badge/code%20style-Ruff-FDD835.svg" alt="Code style: Ruff"></a>
|
|
54
|
+
<a href="https://github.com/kebasyaty/quantum-loop" alt="PyPI implementation"><img src="https://img.shields.io/pypi/implementation/quantum-loop" alt="PyPI implementation"></a>
|
|
55
|
+
<br>
|
|
56
|
+
<a href="https://pypi.org/project/quantum-loop"><img src="https://img.shields.io/pypi/format/quantum-loop" alt="Format"></a>
|
|
57
|
+
<a href="https://github.com/kebasyaty/quantum-loop"><img src="https://img.shields.io/github/languages/top/kebasyaty/quantum-loop" alt="Top"></a>
|
|
58
|
+
<a href="https://github.com/kebasyaty/quantum-loop"><img src="https://img.shields.io/github/repo-size/kebasyaty/quantum-loop" alt="Size"></a>
|
|
59
|
+
<a href="https://github.com/kebasyaty/quantum-loop"><img src="https://img.shields.io/github/last-commit/kebasyaty/quantum-loop/main" alt="Last commit"></a>
|
|
60
|
+
<a href="https://github.com/kebasyaty/quantum-loop/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/quantum-loop" alt="GitHub release"></a>
|
|
61
|
+
</p>
|
|
62
|
+
<p align="center">
|
|
63
|
+
A Qubit in a regular computer is quantum of algorithm that is executed in
|
|
64
|
+
one iteration of a cycle in a separate processor thread.
|
|
65
|
+
<br>
|
|
66
|
+
Quantum is a function with an algorithm of task for data processing.
|
|
67
|
+
<br>
|
|
68
|
+
In this case, the Qubit is not a single information,
|
|
69
|
+
but it is a concept of the principle of operation of quantum calculations on a regular computer.
|
|
70
|
+
</p>
|
|
71
|
+
</p>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
## Documentation
|
|
75
|
+
|
|
76
|
+
Online browsable documentation is available at [https://kebasyaty.github.io/quantum-loop/](https://kebasyaty.github.io/quantum-loop/ "Documentation").
|
|
77
|
+
|
|
78
|
+
## Requirements
|
|
79
|
+
|
|
80
|
+
[View the list of requirements](https://github.com/kebasyaty/quantum-loop/blob/v0/REQUIREMENTS.md "Requirements").
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
```shell
|
|
85
|
+
uv add quantum-loop
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from quantum_loop import LoopMode, QuantumLoop, count_qubits
|
|
92
|
+
|
|
93
|
+
# Counting the number of conceptual qubits of your computer.
|
|
94
|
+
num = count_qubits()
|
|
95
|
+
print(num) # => 16
|
|
96
|
+
|
|
97
|
+
def task(item):
|
|
98
|
+
"""Quantum."""
|
|
99
|
+
return item * item
|
|
100
|
+
|
|
101
|
+
data = range(10)
|
|
102
|
+
|
|
103
|
+
# Separation of the cycle into quantum algorithms for
|
|
104
|
+
# multiprocessing data processing.
|
|
105
|
+
results = quantum-loopLoop(task, data).run()
|
|
106
|
+
print(results) # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Changelog
|
|
110
|
+
|
|
111
|
+
[View the change history](https://github.com/kebasyaty/quantum-loop/blob/v0/CHANGELOG.md "Changelog").
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
This project is licensed under the [MIT](https://github.com/kebasyaty/quantum-loop/blob/main/LICENSE "MIT").
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
quantum_loop/__init__.py,sha256=CfmdL_nJ6QHGNRYmQ0qlPUVfBdZiUeBULMTHwOp9gvU,594
|
|
2
|
+
quantum_loop/loop.py,sha256=ZkFqqFROC9j5JbwJmej3yL9VJcqElPrrimFTz0Pe3Mk,4679
|
|
3
|
+
quantum_loop/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
quantum_loop-0.1.0.dist-info/METADATA,sha256=A2woqHhxHBAyE-XAhJG9AXuhN4aBqh3NLU2GJ3Pg9D8,5871
|
|
5
|
+
quantum_loop-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
+
quantum_loop-0.1.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
7
|
+
quantum_loop-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gennady Kostyunin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|