PyQrackIsing 8.3.1__tar.gz → 8.4.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-8.3.1/pyqrackising.egg-info → pyqrackising-8.4.0}/PKG-INFO +1 -1
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/README.md +2 -2
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyproject.toml +1 -1
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/maxcut_tfim.py +20 -12
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/maxcut_tfim_sparse.py +14 -11
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/maxcut_tfim_streaming.py +6 -5
- {pyqrackising-8.3.1 → pyqrackising-8.4.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/setup.py +1 -1
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/CMakeLists.txt +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/LICENSE.md +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/MANIFEST.in +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-8.3.1 → pyqrackising-8.4.0}/setup.cfg +0 -0
|
@@ -50,10 +50,10 @@ from pyqrackising import maxcut_tfim
|
|
|
50
50
|
import networkx as nx
|
|
51
51
|
|
|
52
52
|
G = nx.petersen_graph()
|
|
53
|
-
best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=
|
|
53
|
+
best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=5, shots=None, is_spin_glass=False, anneal_t=8.0, anneal_h=8.0)
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs), and `maxcut_tfim_streaming(G_func, nodes)` for `numba` JIT streaming weights function definitions. The (integer) `quality` setting is optional, with a default value of `
|
|
56
|
+
We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs), and `maxcut_tfim_streaming(G_func, nodes)` for `numba` JIT streaming weights function definitions. The (integer) `quality` setting is optional, with a default value of `5`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) `anneal_t` and `anneal_h` control the physical maximum annealing time and `h` transverse field parameter, as in Trotterized Ising model. If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
|
|
57
57
|
|
|
58
58
|
Based on a combination of the TFIM-inspired MAXCUT solver and another technique for finding ground-state energy in quantum chemistry that we call the _"binary Clifford eigensolver,"_ we also provide an (approximate) spin glass ground-state solver:
|
|
59
59
|
```py
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "8.
|
|
15
|
+
version = "8.4.0"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
18
18
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -20,7 +20,7 @@ def update_repulsion_choice(G_m, max_edge, weights, n, used, node):
|
|
|
20
20
|
for nbr in range(n):
|
|
21
21
|
if used[nbr]:
|
|
22
22
|
continue
|
|
23
|
-
weights[nbr] *=
|
|
23
|
+
weights[nbr] *= 4 ** (-G_m[node, nbr] / max_edge)
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -133,10 +133,9 @@ def compute_cut(sample, G_m, n_qubits):
|
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
@njit(parallel=True)
|
|
136
|
-
def sample_for_energy(G_m, shots, thresholds, weights):
|
|
136
|
+
def sample_for_energy(G_m, max_edge, shots, thresholds, weights):
|
|
137
137
|
shots = max(1, shots >> 1)
|
|
138
138
|
n = len(G_m)
|
|
139
|
-
max_edge = G_m.max()
|
|
140
139
|
tot_init_weight = weights.sum()
|
|
141
140
|
|
|
142
141
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -172,10 +171,9 @@ def sample_for_energy(G_m, shots, thresholds, weights):
|
|
|
172
171
|
|
|
173
172
|
|
|
174
173
|
@njit(parallel=True)
|
|
175
|
-
def sample_for_cut(G_m, shots, thresholds, weights):
|
|
174
|
+
def sample_for_cut(G_m, max_edge, shots, thresholds, weights):
|
|
176
175
|
shots = max(1, shots >> 1)
|
|
177
176
|
n = len(G_m)
|
|
178
|
-
max_edge = G_m.max()
|
|
179
177
|
tot_init_weight = weights.sum()
|
|
180
178
|
|
|
181
179
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -215,27 +213,37 @@ def init_J_and_z(G_m):
|
|
|
215
213
|
n_qubits = len(G_m)
|
|
216
214
|
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
217
215
|
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
216
|
+
G_max = -float("inf")
|
|
218
217
|
for n in prange(n_qubits):
|
|
219
|
-
degree =
|
|
220
|
-
J =
|
|
218
|
+
degree = 0
|
|
219
|
+
J = 0.0
|
|
220
|
+
for m in range(n_qubits):
|
|
221
|
+
val = G_m[n, m]
|
|
222
|
+
if val != 0.0:
|
|
223
|
+
degree += 1
|
|
224
|
+
J += val
|
|
225
|
+
val = abs(val)
|
|
226
|
+
if val > G_max:
|
|
227
|
+
G_max = val
|
|
228
|
+
J = -J / degree if degree > 0 else 0
|
|
221
229
|
degrees[n] = degree
|
|
222
230
|
J_eff[n] = J
|
|
223
231
|
|
|
224
|
-
return J_eff, degrees
|
|
232
|
+
return J_eff, degrees, G_max
|
|
225
233
|
|
|
226
234
|
|
|
227
235
|
@njit
|
|
228
236
|
def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h):
|
|
229
|
-
J_eff, degrees = init_J_and_z(G_m)
|
|
237
|
+
J_eff, degrees, max_edge = init_J_and_z(G_m)
|
|
230
238
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
231
239
|
|
|
232
240
|
degrees = None
|
|
233
241
|
J_eff = 1.0 / (1.0 + epsilon - J_eff)
|
|
234
242
|
|
|
235
243
|
if is_spin_glass:
|
|
236
|
-
best_solution, best_value = sample_for_energy(G_m, shots, hamming_prob, J_eff)
|
|
244
|
+
best_solution, best_value = sample_for_energy(G_m, max_edge, shots, hamming_prob, J_eff)
|
|
237
245
|
else:
|
|
238
|
-
best_solution, best_value = sample_for_cut(G_m, shots, hamming_prob, J_eff)
|
|
246
|
+
best_solution, best_value = sample_for_cut(G_m, max_edge, shots, hamming_prob, J_eff)
|
|
239
247
|
|
|
240
248
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
241
249
|
|
|
@@ -278,7 +286,7 @@ def maxcut_tfim(
|
|
|
278
286
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
279
287
|
|
|
280
288
|
if quality is None:
|
|
281
|
-
quality =
|
|
289
|
+
quality = 5
|
|
282
290
|
|
|
283
291
|
if shots is None:
|
|
284
292
|
# Number of measurement shots
|
|
@@ -21,7 +21,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used,
|
|
|
21
21
|
nbr = G_cols[j]
|
|
22
22
|
if used[nbr]:
|
|
23
23
|
continue
|
|
24
|
-
weights[nbr] *=
|
|
24
|
+
weights[nbr] *= 4 ** (-G_data[j] / max_edge)
|
|
25
25
|
|
|
26
26
|
for nbr in range(node):
|
|
27
27
|
if used[nbr]:
|
|
@@ -30,7 +30,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used,
|
|
|
30
30
|
end = G_rows[nbr + 1]
|
|
31
31
|
j = binary_search(G_cols[start:end], node) + start
|
|
32
32
|
if j < end:
|
|
33
|
-
weights[nbr] *=
|
|
33
|
+
weights[nbr] *= 4 ** (-G_data[j] / max_edge)
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -145,10 +145,9 @@ def compute_cut(sample, G_data, G_rows, G_cols, n_qubits):
|
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
@njit(parallel=True)
|
|
148
|
-
def sample_for_energy(G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
148
|
+
def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
149
149
|
shots = max(1, shots >> 1)
|
|
150
150
|
n = G_rows.shape[0] - 1
|
|
151
|
-
max_edge = G_data.max()
|
|
152
151
|
tot_init_weight = weights.sum()
|
|
153
152
|
|
|
154
153
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -184,10 +183,9 @@ def sample_for_energy(G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
|
184
183
|
|
|
185
184
|
|
|
186
185
|
@njit(parallel=True)
|
|
187
|
-
def sample_for_cut(G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
186
|
+
def sample_for_cut(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
188
187
|
shots = max(1, shots >> 1)
|
|
189
188
|
n = G_rows.shape[0] - 1
|
|
190
|
-
max_edge = G_data.max()
|
|
191
189
|
tot_init_weight = weights.sum()
|
|
192
190
|
|
|
193
191
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -251,7 +249,7 @@ def init_J_and_z(G_data, G_rows, G_cols):
|
|
|
251
249
|
|
|
252
250
|
|
|
253
251
|
@njit
|
|
254
|
-
def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_col, nodes, is_spin_glass, anneal_t, anneal_h):
|
|
252
|
+
def cpu_footer(shots, quality, n_qubits, max_edge, G_data, G_rows, G_col, nodes, is_spin_glass, anneal_t, anneal_h):
|
|
255
253
|
J_eff, degrees = init_J_and_z(G_data, G_rows, G_col)
|
|
256
254
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
257
255
|
|
|
@@ -259,9 +257,9 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_col, nodes, is_spin_g
|
|
|
259
257
|
J_eff = 1.0 / (1.0 + epsilon - J_eff)
|
|
260
258
|
|
|
261
259
|
if is_spin_glass:
|
|
262
|
-
best_solution, best_value = sample_for_energy(G_data, G_rows, G_col, shots, hamming_prob, J_eff)
|
|
260
|
+
best_solution, best_value = sample_for_energy(max_edge, G_data, G_rows, G_col, shots, hamming_prob, J_eff)
|
|
263
261
|
else:
|
|
264
|
-
best_solution, best_value = sample_for_cut(G_data, G_rows, G_col, shots, hamming_prob, J_eff)
|
|
262
|
+
best_solution, best_value = sample_for_cut(max_edge, G_data, G_rows, G_col, shots, hamming_prob, J_eff)
|
|
265
263
|
|
|
266
264
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
267
265
|
|
|
@@ -304,7 +302,7 @@ def maxcut_tfim_sparse(
|
|
|
304
302
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
305
303
|
|
|
306
304
|
if quality is None:
|
|
307
|
-
quality =
|
|
305
|
+
quality = 5
|
|
308
306
|
|
|
309
307
|
if shots is None:
|
|
310
308
|
# Number of measurement shots
|
|
@@ -316,4 +314,9 @@ def maxcut_tfim_sparse(
|
|
|
316
314
|
if anneal_h is None:
|
|
317
315
|
anneal_h = 8.0
|
|
318
316
|
|
|
319
|
-
|
|
317
|
+
max_edge = abs(G_m.max())
|
|
318
|
+
min_edge = abs(G_m.min())
|
|
319
|
+
if min_edge > max_edge:
|
|
320
|
+
max_edge = min_edge
|
|
321
|
+
|
|
322
|
+
return cpu_footer(shots, quality, n_qubits, max_edge, G_m.data, G_m.indptr, G_m.indices, nodes, is_spin_glass, anneal_t, anneal_h)
|
|
@@ -20,7 +20,7 @@ def update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node):
|
|
|
20
20
|
for nbr in range(n):
|
|
21
21
|
if used[nbr]:
|
|
22
22
|
continue
|
|
23
|
-
weights[nbr] *=
|
|
23
|
+
weights[nbr] *= 4 ** (-G_func(nodes[node], nodes[nbr]) / max_edge)
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -221,6 +221,7 @@ def init_J_and_z(G_func, nodes):
|
|
|
221
221
|
if val != 0.0:
|
|
222
222
|
degree += 1
|
|
223
223
|
J += val
|
|
224
|
+
val = abs(val)
|
|
224
225
|
if val > G_max:
|
|
225
226
|
G_max = val
|
|
226
227
|
J = -J / degree if degree > 0 else 0
|
|
@@ -232,7 +233,7 @@ def init_J_and_z(G_func, nodes):
|
|
|
232
233
|
|
|
233
234
|
@njit
|
|
234
235
|
def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h):
|
|
235
|
-
J_eff, degrees,
|
|
236
|
+
J_eff, degrees, max_edge = init_J_and_z(G_func, nodes)
|
|
236
237
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
237
238
|
max_edge = degrees.sum()
|
|
238
239
|
|
|
@@ -240,9 +241,9 @@ def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t,
|
|
|
240
241
|
J_eff = 1.0 / (1.0 + epsilon - J_eff)
|
|
241
242
|
|
|
242
243
|
if is_spin_glass:
|
|
243
|
-
best_solution, best_value = sample_for_energy(G_func, nodes,
|
|
244
|
+
best_solution, best_value = sample_for_energy(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits)
|
|
244
245
|
else:
|
|
245
|
-
best_solution, best_value = sample_for_cut(G_func, nodes,
|
|
246
|
+
best_solution, best_value = sample_for_cut(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits)
|
|
246
247
|
|
|
247
248
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
248
249
|
|
|
@@ -276,7 +277,7 @@ def maxcut_tfim_streaming(
|
|
|
276
277
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
277
278
|
|
|
278
279
|
if quality is None:
|
|
279
|
-
quality =
|
|
280
|
+
quality = 5
|
|
280
281
|
|
|
281
282
|
if anneal_t is None:
|
|
282
283
|
anneal_t = 8.0
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='8.
|
|
54
|
+
version='8.4.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|