PyQrackIsing 4.1.1__tar.gz → 4.2.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.
- {pyqrackising-4.1.1/pyqrackising.egg-info → pyqrackising-4.2.0}/PKG-INFO +1 -1
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyproject.toml +1 -1
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/maxcut_tfim.py +6 -31
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/maxcut_tfim_sparse.py +5 -27
- {pyqrackising-4.1.1 → pyqrackising-4.2.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/setup.py +1 -1
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/CMakeLists.txt +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/LICENSE.md +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/MANIFEST.in +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/README.md +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-4.1.1 → pyqrackising-4.2.0}/setup.cfg +0 -0
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "pyqrackising"
|
|
14
|
-
version = "4.
|
|
14
|
+
version = "4.2.0"
|
|
15
15
|
requires-python = ">=3.8"
|
|
16
16
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
17
17
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -108,7 +108,7 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
|
108
108
|
|
|
109
109
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
110
110
|
@njit
|
|
111
|
-
def local_repulsion_choice(
|
|
111
|
+
def local_repulsion_choice(G_m, max_weight, weights, n, m):
|
|
112
112
|
"""
|
|
113
113
|
Pick m nodes out of n with repulsion bias:
|
|
114
114
|
- High-degree nodes are already less likely
|
|
@@ -153,10 +153,9 @@ def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weigh
|
|
|
153
153
|
mask[node] = True
|
|
154
154
|
|
|
155
155
|
# Repulsion: penalize neighbors
|
|
156
|
-
for
|
|
157
|
-
nbr = adjacency_data[j]
|
|
156
|
+
for nbr in range(n):
|
|
158
157
|
if available[nbr]:
|
|
159
|
-
weights[nbr] *=
|
|
158
|
+
weights[nbr] *= 0.5 ** (G_m[node, nbr] / max_weight) # tunable penalty factor
|
|
160
159
|
|
|
161
160
|
return mask
|
|
162
161
|
|
|
@@ -171,33 +170,9 @@ def compute_energy(sample, G_m, n_qubits):
|
|
|
171
170
|
return energy
|
|
172
171
|
|
|
173
172
|
|
|
174
|
-
@njit(parallel=True)
|
|
175
|
-
def compute_adjacency(G_m, size):
|
|
176
|
-
n_qubits = G_m.shape[0]
|
|
177
|
-
nrm = G_m.max()
|
|
178
|
-
adjacency_rows = np.empty(n_qubits + 1, dtype=np.int32)
|
|
179
|
-
adjacency_rows[0] = 0
|
|
180
|
-
adjacency_data = np.empty(size, dtype=np.int32)
|
|
181
|
-
adjacency_vals = np.empty(size, dtype=np.float64)
|
|
182
|
-
k = 0
|
|
183
|
-
for i in prange(n_qubits):
|
|
184
|
-
for j in range(n_qubits):
|
|
185
|
-
if i == j:
|
|
186
|
-
continue
|
|
187
|
-
adjacency_data[k] = j
|
|
188
|
-
adjacency_vals[k] = 0.5 ** (G_m[i, j] / nrm)
|
|
189
|
-
k += 1
|
|
190
|
-
adjacency_rows[i + 1] = k
|
|
191
|
-
|
|
192
|
-
np.resize(adjacency_data, k)
|
|
193
|
-
np.resize(adjacency_vals, k)
|
|
194
|
-
|
|
195
|
-
return adjacency_data, adjacency_vals, adjacency_rows
|
|
196
|
-
|
|
197
|
-
|
|
198
173
|
@njit(parallel=True)
|
|
199
174
|
def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
200
|
-
|
|
175
|
+
max_weight = G_m.max()
|
|
201
176
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
202
177
|
|
|
203
178
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -212,7 +187,7 @@ def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
|
212
187
|
m += 1
|
|
213
188
|
|
|
214
189
|
# Second dimension: permutation within Hamming weight
|
|
215
|
-
sample = local_repulsion_choice(
|
|
190
|
+
sample = local_repulsion_choice(G_m, max_weight, weights, n, m)
|
|
216
191
|
|
|
217
192
|
solutions[s] = sample
|
|
218
193
|
energies[s] = compute_energy(sample, G_m, n)
|
|
@@ -319,7 +294,7 @@ def maxcut_tfim(
|
|
|
319
294
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
320
295
|
|
|
321
296
|
if quality is None:
|
|
322
|
-
quality =
|
|
297
|
+
quality = 8
|
|
323
298
|
|
|
324
299
|
if shots is None:
|
|
325
300
|
# Number of measurement shots
|
|
@@ -108,7 +108,7 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
|
108
108
|
|
|
109
109
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
110
110
|
@njit
|
|
111
|
-
def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m):
|
|
111
|
+
def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, max_weight, weights, n, m):
|
|
112
112
|
"""
|
|
113
113
|
Pick m nodes out of n with repulsion bias:
|
|
114
114
|
- High-degree nodes are already less likely
|
|
@@ -156,7 +156,7 @@ def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weigh
|
|
|
156
156
|
for j in range(adjacency_rows[node], adjacency_rows[node + 1]):
|
|
157
157
|
nbr = adjacency_data[j]
|
|
158
158
|
if available[nbr]:
|
|
159
|
-
weights[nbr] *= adjacency_vals[j] # tunable penalty factor
|
|
159
|
+
weights[nbr] *= 0.5 ** (adjacency_vals[j] / max_weight) # tunable penalty factor
|
|
160
160
|
|
|
161
161
|
return mask
|
|
162
162
|
|
|
@@ -175,32 +175,10 @@ def compute_energy(sample, G_data, G_rows, G_cols):
|
|
|
175
175
|
return energy
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
@njit(parallel=True)
|
|
179
|
-
def compute_adjacency(G_data, G_rows, G_cols):
|
|
180
|
-
n_qubits = G_rows.shape[0] - 1
|
|
181
|
-
nrm = G_data.max()
|
|
182
|
-
adjacency_rows = np.empty(n_qubits + 1, dtype=np.int32)
|
|
183
|
-
adjacency_rows[0] = 0
|
|
184
|
-
adjacency_data = np.empty(G_data.shape[0], dtype=np.int32)
|
|
185
|
-
adjacency_vals = np.empty(G_data.shape[0], dtype=np.float64)
|
|
186
|
-
k = 0
|
|
187
|
-
for i in prange(n_qubits):
|
|
188
|
-
for j in range(G_rows[i], G_rows[i + 1]):
|
|
189
|
-
adjacency_data[k] = G_cols[j]
|
|
190
|
-
adjacency_vals[k] = 0.5 ** (G_data[j] / nrm)
|
|
191
|
-
k += 1
|
|
192
|
-
adjacency_rows[i + 1] = k
|
|
193
|
-
|
|
194
|
-
np.resize(adjacency_data, k)
|
|
195
|
-
np.resize(adjacency_vals, k)
|
|
196
|
-
|
|
197
|
-
return adjacency_data, adjacency_vals, adjacency_rows
|
|
198
|
-
|
|
199
|
-
|
|
200
178
|
@njit(parallel=True)
|
|
201
179
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
202
180
|
n = G_rows.shape[0] - 1
|
|
203
|
-
|
|
181
|
+
max_weight = G_data.max()
|
|
204
182
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
205
183
|
|
|
206
184
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -215,7 +193,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
|
215
193
|
m += 1
|
|
216
194
|
|
|
217
195
|
# Second dimension: permutation within Hamming weight
|
|
218
|
-
sample = local_repulsion_choice(
|
|
196
|
+
sample = local_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, m)
|
|
219
197
|
solutions[s] = sample
|
|
220
198
|
energies[s] = compute_energy(sample, G_data, G_rows, G_cols)
|
|
221
199
|
|
|
@@ -325,7 +303,7 @@ def maxcut_tfim_sparse(
|
|
|
325
303
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
326
304
|
|
|
327
305
|
if quality is None:
|
|
328
|
-
quality =
|
|
306
|
+
quality = 8
|
|
329
307
|
|
|
330
308
|
if shots is None:
|
|
331
309
|
# Number of measurement shots
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='4.
|
|
54
|
+
version='4.2.0',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
57
|
description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)',
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|