quantum-loop 0.2.0__py3-none-any.whl → 0.2.2__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.

ql/__init__.py CHANGED
@@ -12,11 +12,11 @@ but it is a concept of the principle of operation of quantum calculations on a r
12
12
  from __future__ import annotations
13
13
 
14
14
  __all__ = (
15
- "LoopMode",
16
15
  "QuantumLoop",
16
+ "LoopMode",
17
17
  "count_qubits",
18
18
  )
19
19
 
20
20
 
21
- from ql.loop import LoopMode, QuantumLoop
22
- from ql.utils import count_qubits
21
+ from ql.loop import QuantumLoop
22
+ from ql.utils import LoopMode, count_qubits
ql/loop.py CHANGED
@@ -10,8 +10,6 @@ but it is a concept of the principle of operation of quantum calculations on a r
10
10
 
11
11
  The module contains the following tools:
12
12
 
13
- - `LoopMode` - Quantum loop mode.
14
- - `count_qubits()` - Counting the number of conceptual qubits of your computer.
15
13
  - `QuantumLoop` - Separation of the cycle into quantum algorithms for multiprocessing data processing.
16
14
  """
17
15
 
@@ -19,15 +17,9 @@ from __future__ import annotations
19
17
 
20
18
  import concurrent.futures
21
19
  from collections.abc import Callable, Iterable
22
- from enum import Enum
23
20
  from typing import Any, Never, assert_never
24
21
 
25
-
26
- class LoopMode(Enum):
27
- """Quantum loop mode."""
28
-
29
- PROCESS_POOL = 1
30
- THREAD_POOL = 2
22
+ from ql.utils import LoopMode
31
23
 
32
24
 
33
25
  class QuantumLoop:
@@ -47,11 +39,8 @@ class QuantumLoop:
47
39
  max_workers: The maximum number of processes that can be used to
48
40
  execute the given calls. If None or not given then as many
49
41
  worker processes will be created as the machine has processors.
50
- timeout: The maximum number of seconds to wait. If None, then there
51
- is no limit on the wait time.
52
- chunksize: The size of the chunks the iterable will be broken into
53
- before being passed to a child process. This argument is only
54
- used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
42
+ timeout: The number of seconds to wait for the result if the future isn't done.
43
+ If None, then there is no limit on the wait time.
55
44
  mode: The operating mode for a quantum loop: LoopMode.PROCESS_POOL | LoopMode.THREAD_POOL.
56
45
  """
57
46
 
@@ -61,43 +50,43 @@ class QuantumLoop:
61
50
  data: Iterable[Any],
62
51
  max_workers: int | None = None,
63
52
  timeout: float | None = None,
64
- chunksize: int = 1,
65
53
  mode: LoopMode = LoopMode.PROCESS_POOL,
66
54
  ) -> None:
67
- self.quantum = task
55
+ self.task = task
68
56
  self.data = data
69
57
  self.max_workers = max_workers
70
58
  self.timeout = timeout
71
- self.chunksize = chunksize
72
59
  self.mode = mode
73
60
 
74
61
  def process_pool(self) -> list[Any]:
75
62
  """Better suitable for operations for which large processor resources are required."""
63
+ task = self.task
64
+ data = self.data
65
+ timeout = self.timeout
66
+ results: list[Any] = []
76
67
  with concurrent.futures.ProcessPoolExecutor(self.max_workers) as executor:
77
- results = list(
78
- executor.map(
79
- self.quantum,
80
- self.data,
81
- timeout=self.timeout,
82
- chunksize=self.chunksize,
83
- ),
84
- )
85
- return results # noqa: RET504
68
+ for item in data:
69
+ future = executor.submit(task, item)
70
+ result = future.result(timeout)
71
+ if result is not None:
72
+ results.append(result)
73
+ return results
86
74
 
87
75
  def thread_pool(self) -> list[Any]:
88
76
  """More suitable for tasks related to input-output
89
77
  (for example, network queries, file operations),
90
78
  where GIL is freed during input-output operations.""" # noqa: D205, D209
79
+ task = self.task
80
+ data = self.data
81
+ timeout = self.timeout
82
+ results: list[Any] = []
91
83
  with concurrent.futures.ThreadPoolExecutor(self.max_workers) as executor:
92
- results = list(
93
- executor.map(
94
- self.quantum,
95
- self.data,
96
- timeout=self.timeout,
97
- chunksize=self.chunksize,
98
- ),
99
- )
100
- return results # noqa: RET504
84
+ for item in data:
85
+ future = executor.submit(task, item)
86
+ result = future.result(timeout)
87
+ if result is not None:
88
+ results.append(result)
89
+ return results
101
90
 
102
91
  def run(self) -> list[Any]:
103
92
  """Run the quantum loop."""
ql/utils.py CHANGED
@@ -1,8 +1,22 @@
1
- """Utils."""
1
+ """Utils.
2
+
3
+ The module contains the following tools:
4
+
5
+ - `LoopMode` - Quantum loop mode.
6
+ - `count_qubits()` - Counting the number of conceptual qubits of your computer.
7
+ """
2
8
 
3
9
  from __future__ import annotations
4
10
 
5
11
  import multiprocessing
12
+ from enum import Enum
13
+
14
+
15
+ class LoopMode(Enum):
16
+ """Quantum loop mode."""
17
+
18
+ PROCESS_POOL = 1
19
+ THREAD_POOL = 2
6
20
 
7
21
 
8
22
  def count_qubits() -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantum-loop
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A set of tools for quantum calculations.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/quantum-loop
6
6
  Project-URL: Repository, https://github.com/kebasyaty/quantum-loop
@@ -94,22 +94,28 @@ uv add quantum-loop
94
94
  ## Usage
95
95
 
96
96
  ```python
97
- from ql import LoopMode, QuantumLoop, count_qubits
97
+ from ql import QuantumLoop, count_qubits
98
98
 
99
- # Counting the number of conceptual qubits of your computer.
100
- num = count_qubits()
101
- print(num) # => 16
102
99
 
103
- def task(item):
100
+ def task(num: int) -> int | None:
104
101
  """Quantum."""
105
- return item * item
102
+ return num * num if num % 2 == 0 else None
106
103
 
107
- data = range(10)
108
104
 
109
- # Separation of the cycle into quantum algorithms for
110
- # multiprocessing data processing.
111
- results = QuantumLoop(task, data).run()
112
- print(results) # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
105
+ def main() -> None:
106
+ # Counting the number of conceptual qubits of your computer.
107
+ num = count_qubits()
108
+ print(num) # => 16
109
+
110
+ # Separation of the cycle into quantum algorithms for
111
+ # multiprocessing data processing.
112
+ data = range(1, 10)
113
+ results = QuantumLoop(task, data).run()
114
+ print(results) # => [4, 16, 36, 64]
115
+
116
+
117
+ if __name__ == "__main__":
118
+ main()
113
119
  ```
114
120
 
115
121
  ## Changelog
@@ -0,0 +1,8 @@
1
+ ql/__init__.py,sha256=NLJqDzx9z_phVVusAGUxDyKJhW35_1Ex0PoiZbvStsQ,607
2
+ ql/loop.py,sha256=4gU1lv_YbDfB3Ed03gzmFIhwOKlOwCCsw0zCfTUE4bI,3778
3
+ ql/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ ql/utils.py,sha256=7q9hj1Z3Yqmo2t4EpXDu5aQ8AaRpS984TsjHbiNaeCA,868
5
+ quantum_loop-0.2.2.dist-info/METADATA,sha256=VjBC02si27KKEXmuTpLTzfXppY2j6lMWcFBGP0Cx44o,5990
6
+ quantum_loop-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ quantum_loop-0.2.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ quantum_loop-0.2.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- ql/__init__.py,sha256=ZRQ0z14P0H_TEUnAspjNJuWxDul-S03U8iVa5Tg8SQc,607
2
- ql/loop.py,sha256=Lcx_b_FQHOnf7HDJKAll8rzU_6f8EU4V5ozaLPj5kMI,4132
3
- ql/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- ql/utils.py,sha256=MPRUYSlD8DN7Hb28X3ru9bBnsiQ39IPAQ0w23sikRZM,579
5
- quantum_loop-0.2.0.dist-info/METADATA,sha256=rLcA5Xzn4paiSAmOn2cCjwaQDotIElojhYdqFUAU6mM,5883
6
- quantum_loop-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- quantum_loop-0.2.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- quantum_loop-0.2.0.dist-info/RECORD,,