PyQrackIsing 4.1.0__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.0/pyqrackising.egg-info → pyqrackising-4.2.0}/PKG-INFO +1 -1
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyproject.toml +1 -1
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/maxcut_tfim.py +6 -34
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/maxcut_tfim_sparse.py +5 -28
- {pyqrackising-4.1.0 → pyqrackising-4.2.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/setup.py +1 -1
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/CMakeLists.txt +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/LICENSE.md +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/MANIFEST.in +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/README.md +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-4.1.0 → pyqrackising-4.2.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-4.1.0 → 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,36 +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
|
-
val = G_m[i, j]
|
|
188
|
-
if val <= 0.0:
|
|
189
|
-
continue
|
|
190
|
-
adjacency_data[k] = j
|
|
191
|
-
adjacency_vals[k] = 0.5 ** (val / nrm)
|
|
192
|
-
k += 1
|
|
193
|
-
adjacency_rows[i + 1] = k
|
|
194
|
-
|
|
195
|
-
np.resize(adjacency_data, k)
|
|
196
|
-
np.resize(adjacency_vals, k)
|
|
197
|
-
|
|
198
|
-
return adjacency_data, adjacency_vals, adjacency_rows
|
|
199
|
-
|
|
200
|
-
|
|
201
173
|
@njit(parallel=True)
|
|
202
174
|
def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
203
|
-
|
|
175
|
+
max_weight = G_m.max()
|
|
204
176
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
205
177
|
|
|
206
178
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -215,7 +187,7 @@ def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
|
215
187
|
m += 1
|
|
216
188
|
|
|
217
189
|
# Second dimension: permutation within Hamming weight
|
|
218
|
-
sample = local_repulsion_choice(
|
|
190
|
+
sample = local_repulsion_choice(G_m, max_weight, weights, n, m)
|
|
219
191
|
|
|
220
192
|
solutions[s] = sample
|
|
221
193
|
energies[s] = compute_energy(sample, G_m, n)
|
|
@@ -322,7 +294,7 @@ def maxcut_tfim(
|
|
|
322
294
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
323
295
|
|
|
324
296
|
if quality is None:
|
|
325
|
-
quality =
|
|
297
|
+
quality = 8
|
|
326
298
|
|
|
327
299
|
if shots is None:
|
|
328
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,33 +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
|
-
if G_data[j] > 0.0:
|
|
190
|
-
adjacency_data[k] = G_cols[j]
|
|
191
|
-
adjacency_vals[k] = 0.5 ** (G_data[j] / nrm)
|
|
192
|
-
k += 1
|
|
193
|
-
adjacency_rows[i + 1] = k
|
|
194
|
-
|
|
195
|
-
np.resize(adjacency_data, k)
|
|
196
|
-
np.resize(adjacency_vals, k)
|
|
197
|
-
|
|
198
|
-
return adjacency_data, adjacency_vals, adjacency_rows
|
|
199
|
-
|
|
200
|
-
|
|
201
178
|
@njit(parallel=True)
|
|
202
179
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
203
180
|
n = G_rows.shape[0] - 1
|
|
204
|
-
|
|
181
|
+
max_weight = G_data.max()
|
|
205
182
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
206
183
|
|
|
207
184
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -216,7 +193,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
|
216
193
|
m += 1
|
|
217
194
|
|
|
218
195
|
# Second dimension: permutation within Hamming weight
|
|
219
|
-
sample = local_repulsion_choice(
|
|
196
|
+
sample = local_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, m)
|
|
220
197
|
solutions[s] = sample
|
|
221
198
|
energies[s] = compute_energy(sample, G_data, G_rows, G_cols)
|
|
222
199
|
|
|
@@ -326,7 +303,7 @@ def maxcut_tfim_sparse(
|
|
|
326
303
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
327
304
|
|
|
328
305
|
if quality is None:
|
|
329
|
-
quality =
|
|
306
|
+
quality = 8
|
|
330
307
|
|
|
331
308
|
if shots is None:
|
|
332
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
|