pyqrack-cuda 1.41.1__tar.gz → 1.42.0__tar.gz
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.
- {pyqrack_cuda-1.41.1/pyqrack_cuda.egg-info → pyqrack_cuda-1.42.0}/PKG-INFO +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/__init__.py +7 -6
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/neuron_activation_fn.py +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/pauli.py +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_circuit.py +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_neuron.py +2 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_neuron_torch_layer.py +32 -9
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_simulator.py +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/quimb_circuit_type.py +1 -1
- pyqrack_cuda-1.42.0/pyqrack/stats/__init__.py +6 -0
- pyqrack_cuda-1.42.0/pyqrack/stats/load_quantized_data.py +33 -0
- pyqrack_cuda-1.42.0/pyqrack/stats/quantize_by_range.py +51 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0/pyqrack_cuda.egg-info}/PKG-INFO +1 -1
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack_cuda.egg-info/SOURCES.txt +3 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/setup.py +2 -2
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/LICENSE +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/MANIFEST.in +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/Makefile +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/README.md +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyproject.toml +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_system/__init__.py +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack/qrack_system/qrack_system.py +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack_cuda.egg-info/dependency_links.txt +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack_cuda.egg-info/not-zip-safe +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack_cuda.egg-info/requires.txt +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/pyqrack_cuda.egg-info/top_level.txt +0 -0
- {pyqrack_cuda-1.41.1 → pyqrack_cuda-1.42.0}/setup.cfg +0 -0
@@ -1,13 +1,14 @@
|
|
1
|
-
# (C) Daniel Strano and the Qrack contributors 2017-
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
2
|
#
|
3
3
|
# Use of this source code is governed by an MIT-style license that can be
|
4
4
|
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
5
5
|
|
6
|
-
from .qrack_system import QrackSystem, Qrack
|
7
|
-
from .qrack_simulator import QrackSimulator
|
8
|
-
from .qrack_neuron import QrackNeuron
|
9
|
-
from .qrack_neuron_torch_layer import QrackNeuronTorchLayer
|
10
|
-
from .qrack_circuit import QrackCircuit
|
11
6
|
from .pauli import Pauli
|
12
7
|
from .neuron_activation_fn import NeuronActivationFn
|
13
8
|
from .quimb_circuit_type import QuimbCircuitType
|
9
|
+
from .qrack_circuit import QrackCircuit
|
10
|
+
from .qrack_neuron import QrackNeuron
|
11
|
+
from .qrack_neuron_torch_layer import QrackTorchNeuron, QrackNeuronFunction, QrackNeuronTorchLayer
|
12
|
+
from .qrack_simulator import QrackSimulator
|
13
|
+
from .qrack_system import QrackSystem, Qrack
|
14
|
+
from .stats.quantize_by_range import quantize_by_range
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# (C) Daniel Strano and the Qrack contributors 2017-
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
2
|
#
|
3
3
|
# Use of this source code is governed by an MIT-style license that can be
|
4
4
|
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# (C) Daniel Strano and the Qrack contributors 2017-
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
2
|
#
|
3
3
|
# Use of this source code is governed by an MIT-style license that can be
|
4
4
|
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
@@ -9,6 +9,7 @@ import sys
|
|
9
9
|
from .qrack_system import Qrack
|
10
10
|
from .neuron_activation_fn import NeuronActivationFn
|
11
11
|
|
12
|
+
|
12
13
|
class QrackNeuron:
|
13
14
|
"""Class that exposes the QNeuron class of Qrack
|
14
15
|
|
@@ -1,5 +1,10 @@
|
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
|
+
#
|
1
3
|
# Initial draft by Elara (OpenAI custom GPT)
|
2
4
|
# Refined and architecturally clarified by Dan Strano
|
5
|
+
#
|
6
|
+
# Use of this source code is governed by an MIT-style license that can be
|
7
|
+
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
3
8
|
|
4
9
|
_IS_TORCH_AVAILABLE = True
|
5
10
|
try:
|
@@ -24,6 +29,11 @@ def powerset(iterable):
|
|
24
29
|
|
25
30
|
|
26
31
|
class QrackTorchNeuron(nn.Module):
|
32
|
+
"""Torch wrapper for QrackNeuron
|
33
|
+
|
34
|
+
Attributes:
|
35
|
+
neuron(QrackNeuron): QrackNeuron backing this torch wrapper
|
36
|
+
"""
|
27
37
|
def __init__(self, neuron: QrackNeuron) -> None:
|
28
38
|
super().__init__()
|
29
39
|
self.neuron = neuron
|
@@ -36,6 +46,7 @@ class QrackTorchNeuron(nn.Module):
|
|
36
46
|
|
37
47
|
|
38
48
|
class QrackNeuronFunction(Function if _IS_TORCH_AVAILABLE else object):
|
49
|
+
"""Static forward/backward/apply functions for QrackTorchNeuron"""
|
39
50
|
@staticmethod
|
40
51
|
def forward(ctx, neuron: object):
|
41
52
|
# Save for backward
|
@@ -63,20 +74,32 @@ class QrackNeuronFunction(Function if _IS_TORCH_AVAILABLE else object):
|
|
63
74
|
|
64
75
|
|
65
76
|
class QrackNeuronTorchLayer(nn.Module if _IS_TORCH_AVAILABLE else object):
|
66
|
-
|
67
|
-
|
77
|
+
"""Torch layer wrapper for QrackNeuron (with power set of neurons between inputs and outputs)"""
|
78
|
+
def __init__(self, simulator: object, input_indices: list[int], output_indices: list[int],
|
79
|
+
activation: int = int(NeuronActivationFn.Generalized_Logistic), parameters: list[float] = None):
|
80
|
+
"""
|
81
|
+
Initialize a QrackNeuron layer for PyTorch with a power set of neurons connecting inputs to outputs.
|
82
|
+
The inputs and outputs must take the form of discrete, binary features (loaded manually into the backing QrackSimulator)
|
83
|
+
|
84
|
+
Args:
|
85
|
+
sim (QrackSimulator): Simulator into which predictor features are loaded
|
86
|
+
input_indices (list[int]): List of input bits
|
87
|
+
output_indices (list[int]): List of output bits
|
88
|
+
activation (int): Integer corresponding to choice of activation function from NeuronActivationFn
|
89
|
+
parameters (list[float]): (Optional) Flat list of initial neuron parameters, corresponding to little-endian basis states of power set of input indices, repeated for each output index (with empty set being constant bias)
|
90
|
+
"""
|
68
91
|
super(QrackNeuronTorchLayer, self).__init__()
|
69
92
|
self.simulator = simulator
|
70
93
|
self.input_indices = input_indices
|
71
|
-
self.
|
94
|
+
self.output_indices = output_indices
|
72
95
|
self.activation = NeuronActivationFn(activation)
|
73
96
|
self.fn = QrackNeuronFunction.apply if _IS_TORCH_AVAILABLE else lambda x: QrackNeuronFunction.forward(object(), x)
|
74
97
|
|
75
98
|
# Create neurons from all powerset input combinations, projecting to coherent output qubits
|
76
99
|
self.neurons = nn.ModuleList([
|
77
|
-
QrackTorchNeuron(QrackNeuron(simulator, list(input_subset),
|
100
|
+
QrackTorchNeuron(QrackNeuron(simulator, list(input_subset), output_id, activation))
|
78
101
|
for input_subset in powerset(input_indices)
|
79
|
-
for output_id in
|
102
|
+
for output_id in output_indices
|
80
103
|
])
|
81
104
|
|
82
105
|
# Set Qrack's internal parameters:
|
@@ -93,8 +116,8 @@ class QrackNeuronTorchLayer(nn.Module if _IS_TORCH_AVAILABLE else object):
|
|
93
116
|
|
94
117
|
def forward(self, _):
|
95
118
|
# Assume quantum outputs should overwrite the simulator state
|
96
|
-
for output_id in
|
97
|
-
if self.simulator.m(
|
119
|
+
for output_id in self.output_indices:
|
120
|
+
if self.simulator.m(output_id):
|
98
121
|
self.simulator.x(output_id)
|
99
122
|
self.simulator.h(output_id)
|
100
123
|
|
@@ -113,8 +136,8 @@ class QrackNeuronTorchLayer(nn.Module if _IS_TORCH_AVAILABLE else object):
|
|
113
136
|
|
114
137
|
# These are classical views over quantum state; simulator still maintains full coherence
|
115
138
|
outputs = [
|
116
|
-
self.simulator.prob(
|
117
|
-
for output_id in
|
139
|
+
self.simulator.prob(output_id)
|
140
|
+
for output_id in self.output_indices
|
118
141
|
]
|
119
142
|
|
120
143
|
return torch.tensor(outputs, dtype=torch.float32)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# (C) Daniel Strano and the Qrack contributors 2017-
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
2
|
#
|
3
3
|
# Use of this source code is governed by an MIT-style license that can be
|
4
4
|
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style license that can be
|
4
|
+
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
5
|
+
|
6
|
+
from .quantize_by_range import quantize_by_range
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
|
+
#
|
3
|
+
# Load quantized data into a QrackSimulator
|
4
|
+
#
|
5
|
+
# Use of this source code is governed by an MIT-style license that can be
|
6
|
+
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
7
|
+
|
8
|
+
|
9
|
+
def load_data(sim, index_bits, value_bits, data):
|
10
|
+
"""
|
11
|
+
Take discretized features from quantize_by_range and load into a QrackSimulator
|
12
|
+
|
13
|
+
Args:
|
14
|
+
sim (QrackSimulator): Simulator into which to load data
|
15
|
+
index_bits (list[int]): List of index bits, least-to-most significant
|
16
|
+
value_bits (list[int]): List of value bits, least-to-most significant
|
17
|
+
data (list[list[bool]]): Data to load, row-major
|
18
|
+
|
19
|
+
Raises:
|
20
|
+
Value error: Length of value_bits does not match data feature column count!
|
21
|
+
"""
|
22
|
+
if (len(data) > 0) and (len(value_bits) != len(data[0])):
|
23
|
+
raise ValueError("Length of value_bits does not match data feature column count!")
|
24
|
+
|
25
|
+
for i in range(index_bits):
|
26
|
+
if sim.m(i):
|
27
|
+
sim.x(i)
|
28
|
+
sim.h(i)
|
29
|
+
|
30
|
+
if len(data) == 0:
|
31
|
+
return
|
32
|
+
|
33
|
+
sim.lda(list(range(index_bits)), list(range(value_bits)), data)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
|
2
|
+
#
|
3
|
+
# Use of this source code is governed by an MIT-style license that can be
|
4
|
+
# found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
5
|
+
|
6
|
+
try:
|
7
|
+
# Written by Elara (custom OpenAI GPT)
|
8
|
+
import numpy as np
|
9
|
+
|
10
|
+
def quantize_by_range(data: np.ndarray, feature_indices: list[int], bits: int) -> np.ndarray:
|
11
|
+
"""
|
12
|
+
Discretize selected features of a dataset into binary variables using numpy.linspace binning.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
data (np.ndarray): Input data of shape (n_samples, n_features).
|
16
|
+
feature_indices (list[int]): Indices of features to discretize.
|
17
|
+
bits (int): Number of bits to represent each discretized feature (e.g., 2 bits = 4 quantiles).
|
18
|
+
|
19
|
+
Returns:
|
20
|
+
np.ndarray: Transformed data with selected features replaced by binary bit columns.
|
21
|
+
"""
|
22
|
+
n_samples, n_features = data.shape
|
23
|
+
n_bins = 2 ** bits
|
24
|
+
|
25
|
+
new_features = []
|
26
|
+
for i in range(n_features):
|
27
|
+
if i in feature_indices:
|
28
|
+
min_val, max_val = data[:, i].min(), data[:, i].max()
|
29
|
+
thresholds = np.linspace(min_val, max_val, n_bins + 1)[1:-1]
|
30
|
+
bins = np.digitize(data[:, i], bins=thresholds)
|
31
|
+
bin_bits = ((bins[:, None] & (1 << np.arange(bits)[::-1])) > 0).astype(int)
|
32
|
+
new_features.append(bin_bits)
|
33
|
+
else:
|
34
|
+
new_features.append(data[:, i][:, None]) # Keep original
|
35
|
+
|
36
|
+
return np.hstack(new_features)
|
37
|
+
except ImportError:
|
38
|
+
def quantize_by_range(data, feature_indices: list[int], bits: int):
|
39
|
+
"""
|
40
|
+
Discretize selected features of a dataset into binary variables using numpy.linspace binning.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
data (np.ndarray): Input data of shape (n_samples, n_features).
|
44
|
+
feature_indices (list[int]): Indices of features to discretize.
|
45
|
+
bits (int): Number of bits to represent each discretized feature (e.g., 2 bits = 4 quantiles).
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
np.ndarray: Transformed data with selected features replaced by binary bit columns.
|
49
|
+
"""
|
50
|
+
raise NotImplementedError("You must have numpy installed to use quantize_by_percentile()!")
|
51
|
+
|
@@ -14,6 +14,9 @@ pyqrack/qrack_simulator.py
|
|
14
14
|
pyqrack/quimb_circuit_type.py
|
15
15
|
pyqrack/qrack_system/__init__.py
|
16
16
|
pyqrack/qrack_system/qrack_system.py
|
17
|
+
pyqrack/stats/__init__.py
|
18
|
+
pyqrack/stats/load_quantized_data.py
|
19
|
+
pyqrack/stats/quantize_by_range.py
|
17
20
|
pyqrack_cuda.egg-info/PKG-INFO
|
18
21
|
pyqrack_cuda.egg-info/SOURCES.txt
|
19
22
|
pyqrack_cuda.egg-info/dependency_links.txt
|
@@ -7,7 +7,7 @@ from setuptools import setup
|
|
7
7
|
from setuptools.command.build_py import build_py
|
8
8
|
|
9
9
|
|
10
|
-
VERSION = "1.
|
10
|
+
VERSION = "1.42.0"
|
11
11
|
|
12
12
|
# Read long description from README.
|
13
13
|
README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')
|
@@ -27,7 +27,7 @@ class Build(build_py):
|
|
27
27
|
setup(
|
28
28
|
name='pyqrack-cuda',
|
29
29
|
version=VERSION,
|
30
|
-
packages=['pyqrack', 'pyqrack.qrack_system'],
|
30
|
+
packages=['pyqrack', 'pyqrack.qrack_system', 'pyqrack.stats'],
|
31
31
|
cmdclass={"build_py": Build},
|
32
32
|
description="pyqrack - Pure Python vm6502q/qrack Wrapper",
|
33
33
|
long_description=README,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|