xloft 0.3.0__py3-none-any.whl → 0.4.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 xloft might be problematic. Click here for more details.
- xloft/__init__.py +7 -2
- {xloft-0.3.0.dist-info → xloft-0.4.0.dist-info}/METADATA +13 -8
- xloft-0.4.0.dist-info/RECORD +9 -0
- xloft/quantum.py +0 -133
- xloft-0.3.0.dist-info/RECORD +0 -10
- /xloft/{humanism.py → human.py} +0 -0
- {xloft-0.3.0.dist-info → xloft-0.4.0.dist-info}/WHEEL +0 -0
- {xloft-0.3.0.dist-info → xloft-0.4.0.dist-info}/licenses/LICENSE +0 -0
xloft/__init__.py
CHANGED
|
@@ -3,12 +3,17 @@
|
|
|
3
3
|
Modules exported by this package:
|
|
4
4
|
|
|
5
5
|
- `namedtuple`: Class imitates the behavior of the _named tuple_.
|
|
6
|
-
- `
|
|
6
|
+
- `human` - A collection of instruments for converting data to format is convenient for humans.
|
|
7
7
|
- `quantum` - A set of tools for quantum calculations.
|
|
8
|
+
Hint: uv add xloft[quantum]
|
|
8
9
|
"""
|
|
9
10
|
|
|
10
11
|
from __future__ import annotations
|
|
11
12
|
|
|
12
|
-
__all__ = (
|
|
13
|
+
__all__ = (
|
|
14
|
+
"to_human_size",
|
|
15
|
+
"NamedTuple",
|
|
16
|
+
)
|
|
13
17
|
|
|
18
|
+
from xloft.human import to_human_size
|
|
14
19
|
from xloft.namedtuple import NamedTuple
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: (XLOFT) X-Library of tools
|
|
5
5
|
Project-URL: Homepage, https://github.com/kebasyaty/xloft
|
|
6
6
|
Project-URL: Repository, https://github.com/kebasyaty/xloft
|
|
@@ -25,6 +25,8 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
|
25
25
|
Classifier: Topic :: Utilities
|
|
26
26
|
Classifier: Typing :: Typed
|
|
27
27
|
Requires-Python: <4.0,>=3.12
|
|
28
|
+
Provides-Extra: quantum
|
|
29
|
+
Requires-Dist: quantum; extra == 'quantum'
|
|
28
30
|
Description-Content-Type: text/markdown
|
|
29
31
|
|
|
30
32
|
<div align="center">
|
|
@@ -60,7 +62,8 @@ Description-Content-Type: text/markdown
|
|
|
60
62
|
<a href="https://github.com/kebasyaty/xloft/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/xloft" alt="GitHub release"></a>
|
|
61
63
|
</p>
|
|
62
64
|
<p align="center">
|
|
63
|
-
|
|
65
|
+
The collection is represented by three modules of `NamedTuple`, `Human` and `Quantum`.
|
|
66
|
+
In the future, new tools can be added.
|
|
64
67
|
</p>
|
|
65
68
|
</p>
|
|
66
69
|
</div>
|
|
@@ -79,6 +82,8 @@ Online browsable documentation is available at [https://kebasyaty.github.io/xlof
|
|
|
79
82
|
|
|
80
83
|
```shell
|
|
81
84
|
uv add xloft
|
|
85
|
+
# For a Quantum module:
|
|
86
|
+
uv add xloft[quantum]
|
|
82
87
|
```
|
|
83
88
|
|
|
84
89
|
## Usage
|
|
@@ -153,10 +158,10 @@ del nt.y # => raise: AttributeCannotBeDelete
|
|
|
153
158
|
del nt._id # => raise: AttributeCannotBeDelete
|
|
154
159
|
```
|
|
155
160
|
|
|
156
|
-
- **
|
|
161
|
+
- **Human**
|
|
157
162
|
|
|
158
163
|
```python
|
|
159
|
-
from xloft
|
|
164
|
+
from xloft import to_human_size
|
|
160
165
|
|
|
161
166
|
|
|
162
167
|
s = to_human_size(200)
|
|
@@ -172,20 +177,20 @@ print(s) # => 1023.999 KB
|
|
|
172
177
|
- **Quantum**
|
|
173
178
|
|
|
174
179
|
```python
|
|
175
|
-
from
|
|
180
|
+
from quantum import LoopMode, QuantumLoop, count_qubits
|
|
176
181
|
|
|
177
182
|
# Counting the number of conceptual qubits of your computer.
|
|
178
183
|
num = count_qubits()
|
|
179
184
|
print(num) # => 16
|
|
180
185
|
|
|
181
|
-
def
|
|
182
|
-
"""
|
|
186
|
+
def task(item):
|
|
187
|
+
"""Quantum."""
|
|
183
188
|
return item * item
|
|
184
189
|
|
|
185
190
|
data = range(10)
|
|
186
191
|
|
|
187
192
|
# Separation of the cycle into quantum algorithms for multiprocessing data processing.
|
|
188
|
-
qloop = QuantumLoop(
|
|
193
|
+
qloop = QuantumLoop(task, data)
|
|
189
194
|
results = qloop.run()
|
|
190
195
|
print(results) # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
191
196
|
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=1bdoDR6AzzL_Rhpp3LLbt6swYlZoZjmfnpJ4sGRr3Ug,518
|
|
2
|
+
xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
|
|
3
|
+
xloft/human.py,sha256=odRbUF_58YuFWC_VQeRDZ-6ifHDiiAH2HNb5G5K6JIM,1106
|
|
4
|
+
xloft/namedtuple.py,sha256=a_l3bZF-L2I7MGxuF2CXzAHgNai-Vyj6SY1ODwxs7TU,6856
|
|
5
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
xloft-0.4.0.dist-info/METADATA,sha256=gEhWCpulkXWJzP8YysZn3tBLCIuyqUpHb-qbqCuFVYk,7358
|
|
7
|
+
xloft-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
xloft-0.4.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
9
|
+
xloft-0.4.0.dist-info/RECORD,,
|
xloft/quantum.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
- `count_qubits()` - Counting the number of qubits of your computer.
|
|
14
|
-
- `LoopMode` - Quantum loop mode.
|
|
15
|
-
- `QuantumLoop` - Separation of the cycle into quantums.
|
|
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
|
-
def count_qubits() -> int:
|
|
28
|
-
"""Counting the number of conceptual qubits of your computer.
|
|
29
|
-
|
|
30
|
-
Conceptual qubit is quantum of algorithm (task) that is executed in
|
|
31
|
-
iterations of a cycle in a separate processor thread.
|
|
32
|
-
|
|
33
|
-
Quantum of algorithm is a function for data processing.
|
|
34
|
-
|
|
35
|
-
Examples:
|
|
36
|
-
>>> from xloft.quantum import count_qubits
|
|
37
|
-
>>> count_qubits()
|
|
38
|
-
16
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
The number of conceptual qubits.
|
|
42
|
-
"""
|
|
43
|
-
return multiprocessing.cpu_count()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class LoopMode(Enum):
|
|
47
|
-
"""Quantum loop mode."""
|
|
48
|
-
|
|
49
|
-
PROCESS_POOL = 1
|
|
50
|
-
THREAD_POOL = 2
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class QuantumLoop:
|
|
54
|
-
"""Separation of the cycle into quantum algorithms for multiprocessing data processing.
|
|
55
|
-
|
|
56
|
-
Args:
|
|
57
|
-
quantum: Function with a task algorithm.
|
|
58
|
-
data: The data that needs to be processed.
|
|
59
|
-
max_workers: The maximum number of processes that can be used to
|
|
60
|
-
execute the given calls. If None or not given then as many
|
|
61
|
-
worker processes will be created as the machine has processors.
|
|
62
|
-
timeout: The maximum number of seconds to wait. If None, then there
|
|
63
|
-
is no limit on the wait time.
|
|
64
|
-
chunksize: The size of the chunks the iterable will be broken into
|
|
65
|
-
before being passed to a child process. This argument is only
|
|
66
|
-
used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
|
|
67
|
-
mode: The operating mode for a quantum loop: LoopMode.PROCESS_POOL | LoopMode.THREAD_POOL.
|
|
68
|
-
|
|
69
|
-
Examples:
|
|
70
|
-
>>> from xloft.quantum import QuantumLoop
|
|
71
|
-
>>> def quantum(item):
|
|
72
|
-
... return item * item
|
|
73
|
-
>>> data = range(10)
|
|
74
|
-
>>> qloop = QuantumLoop(quantum, data)
|
|
75
|
-
>>> qloop.run()
|
|
76
|
-
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
77
|
-
"""
|
|
78
|
-
|
|
79
|
-
def __init__( # noqa: D107
|
|
80
|
-
self,
|
|
81
|
-
quantum: Callable,
|
|
82
|
-
data: Iterable[Any],
|
|
83
|
-
max_workers: int | None = None,
|
|
84
|
-
timeout: float | None = None,
|
|
85
|
-
chunksize: int = 1,
|
|
86
|
-
mode: LoopMode = LoopMode.PROCESS_POOL,
|
|
87
|
-
) -> None:
|
|
88
|
-
self.quantum = quantum
|
|
89
|
-
self.data = data
|
|
90
|
-
self.max_workers = max_workers
|
|
91
|
-
self.timeout = timeout
|
|
92
|
-
self.chunksize = chunksize
|
|
93
|
-
self.mode = mode
|
|
94
|
-
|
|
95
|
-
def process_pool(self) -> list[Any]:
|
|
96
|
-
"""Better suitable for operations for which large processor resources are required."""
|
|
97
|
-
with concurrent.futures.ProcessPoolExecutor(self.max_workers) as executor:
|
|
98
|
-
results = list(
|
|
99
|
-
executor.map(
|
|
100
|
-
self.quantum,
|
|
101
|
-
self.data,
|
|
102
|
-
timeout=self.timeout,
|
|
103
|
-
chunksize=self.chunksize,
|
|
104
|
-
),
|
|
105
|
-
)
|
|
106
|
-
return results # noqa: RET504
|
|
107
|
-
|
|
108
|
-
def thread_pool(self) -> list[Any]:
|
|
109
|
-
"""More suitable for tasks related to input-output
|
|
110
|
-
(for example, network queries, file operations),
|
|
111
|
-
where GIL is freed during input-output operations.""" # noqa: D205, D209
|
|
112
|
-
with concurrent.futures.ThreadPoolExecutor(self.max_workers) as executor:
|
|
113
|
-
results = list(
|
|
114
|
-
executor.map(
|
|
115
|
-
self.quantum,
|
|
116
|
-
self.data,
|
|
117
|
-
timeout=self.timeout,
|
|
118
|
-
chunksize=self.chunksize,
|
|
119
|
-
),
|
|
120
|
-
)
|
|
121
|
-
return results # noqa: RET504
|
|
122
|
-
|
|
123
|
-
def run(self) -> list[Any]:
|
|
124
|
-
"""Run the quantum loop."""
|
|
125
|
-
results: list[Any] = []
|
|
126
|
-
match self.mode.value:
|
|
127
|
-
case 1:
|
|
128
|
-
results = self.process_pool()
|
|
129
|
-
case 2:
|
|
130
|
-
results = self.thread_pool()
|
|
131
|
-
case _ as unreachable:
|
|
132
|
-
assert_never(Never(unreachable))
|
|
133
|
-
return results
|
xloft-0.3.0.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
xloft/__init__.py,sha256=oYQan7jqPh5XKw9msdT290f6fPo4c53p6OkFcCoqi_s,409
|
|
2
|
-
xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
|
|
3
|
-
xloft/humanism.py,sha256=odRbUF_58YuFWC_VQeRDZ-6ifHDiiAH2HNb5G5K6JIM,1106
|
|
4
|
-
xloft/namedtuple.py,sha256=a_l3bZF-L2I7MGxuF2CXzAHgNai-Vyj6SY1ODwxs7TU,6856
|
|
5
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
xloft/quantum.py,sha256=2l7L6ifYvBp5fQUcrdBiuK_QukIohpc2AJm1iFv_igk,4664
|
|
7
|
-
xloft-0.3.0.dist-info/METADATA,sha256=5NIrvvMnloUcCbrDG5s60NNTscPkKLmRMPLDgSLY3sI,7235
|
|
8
|
-
xloft-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
-
xloft-0.3.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
10
|
-
xloft-0.3.0.dist-info/RECORD,,
|
/xloft/{humanism.py → human.py}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|