PyQrackIsing 5.5.3__tar.gz → 5.7.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.
Files changed (28) hide show
  1. {pyqrackising-5.5.3/pyqrackising.egg-info → pyqrackising-5.7.0}/PKG-INFO +1 -1
  2. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/README.md +2 -2
  3. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyproject.toml +1 -1
  4. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim.py +21 -11
  5. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_sparse.py +21 -11
  6. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_streaming.py +21 -10
  7. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver.py +9 -8
  8. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_sparse.py +9 -8
  9. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_streaming.py +4 -3
  10. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/tsp.py +84 -8
  11. {pyqrackising-5.5.3 → pyqrackising-5.7.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  12. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/setup.py +1 -1
  13. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/CMakeLists.txt +0 -0
  14. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/LICENSE.md +0 -0
  15. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/MANIFEST.in +0 -0
  16. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/__init__.py +0 -0
  17. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  18. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/generate_tfim_samples.py +0 -0
  19. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/kernels.cl +0 -0
  20. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_util.py +0 -0
  21. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  22. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/tfim_magnetization.py +0 -0
  23. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  24. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-5.5.3 → pyqrackising-5.7.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.5.3
3
+ Version: 5.7.0
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -53,7 +53,7 @@ G = nx.petersen_graph()
53
53
  best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=2, is_alt_gpu_sampling=True)
54
54
  ```
55
55
 
56
- We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is optional, with a default value of `3`, 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.) `is_alt_gpu_sampling` is `False` by default and, if set to `True`, will dispatch almost the entire algorithm on GPU, instead of just the TFIM-heuristic component (although solution quality is often lower). 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.)
56
+ We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is optional, with a default value of `2`, 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.) `is_alt_gpu_sampling` is `False` by default and, if set to `True`, will dispatch almost the entire algorithm on GPU, instead of just the TFIM-heuristic component (although solution quality is often lower). 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
@@ -76,7 +76,7 @@ G = generate_spin_glass_graph(n_nodes=64, seed=42)
76
76
  solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=2, best_guess=None, is_alt_gpu_sampling=True)
77
77
  # solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=6)[0])
78
78
  ```
79
- We also provide `spin_glass_solver_sparse(G)`, for `scipy` **upper-triangular** CSR sparse arrays (or `networkx` graphs). The (integer) default `quality` setting is `3`. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
79
+ We also provide `spin_glass_solver_sparse(G)`, for `scipy` **upper-triangular** CSR sparse arrays (or `networkx` graphs). The (integer) default `quality` setting is `2`. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
80
80
 
81
81
  From the `spin_glass_solver()`, we provide a (recursive) Traveling Salesman Problem (TSP) solver:
82
82
  ```py
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "5.5.3"
15
+ version = "5.7.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"}
@@ -22,7 +22,7 @@ def update_repulsion_choice(G_m, max_weight, weights, n, used, node):
22
22
  for nbr in range(n):
23
23
  if used[nbr]:
24
24
  continue
25
- weights[nbr] *= max(2e-7, 1 - G_m[node, nbr] / max_weight)
25
+ weights[nbr] *= max(2e-8, 1 - G_m[node, nbr] / max_weight)
26
26
 
27
27
 
28
28
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -84,10 +84,9 @@ def compute_energy(sample, G_m, n_qubits):
84
84
 
85
85
 
86
86
  @njit(parallel=True)
87
- def sample_for_solution(G_m, shots, thresholds, J_eff):
87
+ def sample_for_solution(G_m, shots, thresholds, weights):
88
88
  n = len(G_m)
89
89
  max_weight = G_m.max()
90
- weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
91
90
 
92
91
  solutions = np.empty((shots, n), dtype=np.bool_)
93
92
  energies = np.empty(shots, dtype=np.float32)
@@ -218,7 +217,12 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
218
217
 
219
218
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
220
219
 
221
- best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, J_eff)
220
+ degrees = None
221
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
222
+ weights = J_eff.astype(np.float64)
223
+ J_eff = None
224
+
225
+ best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights)
222
226
 
223
227
  bit_string, l, r = get_cut(best_solution, nodes)
224
228
 
@@ -226,10 +230,10 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
226
230
 
227
231
 
228
232
  @njit
229
- def gpu_footer(shots, n_qubits, G_m, J_eff, hamming_prob, nodes):
233
+ def gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes):
230
234
  fix_cdf(hamming_prob)
231
235
 
232
- best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, J_eff)
236
+ best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights)
233
237
 
234
238
  bit_string, l, r = get_cut(best_solution, nodes)
235
239
 
@@ -240,8 +244,9 @@ def maxcut_tfim(
240
244
  G,
241
245
  quality=None,
242
246
  shots=None,
243
- is_alt_gpu_sampling = False,
244
- is_g_buf_reused = False
247
+ is_alt_gpu_sampling=False,
248
+ is_g_buf_reused=False,
249
+ is_base_maxcut_gpu=True
245
250
  ):
246
251
  nodes = None
247
252
  n_qubits = 0
@@ -270,7 +275,7 @@ def maxcut_tfim(
270
275
  return "01", weight, ([nodes[0]], [nodes[1]])
271
276
 
272
277
  if quality is None:
273
- quality = 3
278
+ quality = 2
274
279
 
275
280
  if shots is None:
276
281
  # Number of measurement shots
@@ -279,7 +284,7 @@ def maxcut_tfim(
279
284
  n_steps = 2 << quality
280
285
  grid_size = n_steps * n_qubits
281
286
 
282
- if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
287
+ if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
283
288
  return cpu_footer(shots, quality, n_qubits, G_m, nodes)
284
289
 
285
290
  J_eff, degrees = init_J_and_z(G_m)
@@ -341,7 +346,12 @@ def maxcut_tfim(
341
346
  theta_buf = None
342
347
 
343
348
  if not is_alt_gpu_sampling:
344
- return gpu_footer(shots, n_qubits, G_m, J_eff, hamming_prob, nodes)
349
+ degrees = None
350
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
351
+ weights = J_eff.astype(np.float64)
352
+ J_eff = None
353
+
354
+ return gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes)
345
355
 
346
356
  fix_cdf(hamming_prob)
347
357
  best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
@@ -52,7 +52,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
52
52
  end = G_rows[nbr + 1]
53
53
  j = binary_search(G_cols[start:end], node) + start
54
54
  if j < end:
55
- weights[nbr] *= max(2e-7, 1 - G_data[j] / max_weight)
55
+ weights[nbr] *= max(2e-8, 1 - G_data[j] / max_weight)
56
56
 
57
57
 
58
58
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -116,10 +116,9 @@ def compute_energy(sample, G_data, G_rows, G_cols):
116
116
 
117
117
 
118
118
  @njit(parallel=True)
119
- def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
119
+ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights):
120
120
  n = G_rows.shape[0] - 1
121
121
  max_weight = G_data.max()
122
- weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
123
122
 
124
123
  solutions = np.empty((shots, n), dtype=np.bool_)
125
124
  energies = np.empty(shots, dtype=np.float32)
@@ -271,7 +270,12 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
271
270
 
272
271
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
273
272
 
274
- best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, J_eff)
273
+ degrees = None
274
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
275
+ weights = J_eff.astype(np.float64)
276
+ J_eff = None
277
+
278
+ best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, weights)
275
279
 
276
280
  bit_string, l, r = get_cut(best_solution, nodes)
277
281
 
@@ -279,10 +283,10 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
279
283
 
280
284
 
281
285
  @njit
282
- def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, J_eff, hamming_prob, nodes):
286
+ def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, weights, hamming_prob, nodes):
283
287
  fix_cdf(hamming_prob)
284
288
 
285
- best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, J_eff)
289
+ best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, weights)
286
290
 
287
291
  bit_string, l, r = get_cut(best_solution, nodes)
288
292
 
@@ -305,8 +309,9 @@ def maxcut_tfim_sparse(
305
309
  G,
306
310
  quality=None,
307
311
  shots=None,
308
- is_alt_gpu_sampling = False,
309
- is_g_buf_reused = False
312
+ is_alt_gpu_sampling=False,
313
+ is_g_buf_reused=False,
314
+ is_base_maxcut_gpu=True
310
315
  ):
311
316
  nodes = None
312
317
  n_qubits = 0
@@ -335,7 +340,7 @@ def maxcut_tfim_sparse(
335
340
  return "01", weight, ([nodes[0]], [nodes[1]])
336
341
 
337
342
  if quality is None:
338
- quality = 3
343
+ quality = 2
339
344
 
340
345
  if shots is None:
341
346
  # Number of measurement shots
@@ -344,7 +349,7 @@ def maxcut_tfim_sparse(
344
349
  n_steps = 2 << quality
345
350
  grid_size = n_steps * n_qubits
346
351
 
347
- if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
352
+ if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
348
353
  return cpu_footer(shots, quality, n_qubits, G_m.data, G_m.indptr, G_m.indices, nodes)
349
354
 
350
355
  J_eff, degrees = init_J_and_z(G_m.data, G_m.indptr, G_m.indices)
@@ -406,7 +411,12 @@ def maxcut_tfim_sparse(
406
411
  theta_buf = None
407
412
 
408
413
  if not is_alt_gpu_sampling:
409
- return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, J_eff, hamming_prob, nodes)
414
+ degrees = None
415
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
416
+ weights = J_eff.astype(np.float64)
417
+ J_eff = None
418
+
419
+ return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, weights, hamming_prob, nodes)
410
420
 
411
421
  fix_cdf(hamming_prob)
412
422
  best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
@@ -22,7 +22,7 @@ def update_repulsion_choice(G_func, G_func_args_tuple, nodes, max_weight, weight
22
22
  for nbr in range(n):
23
23
  if used[nbr]:
24
24
  continue
25
- weights[nbr] *= max(2e-7, 1 - G_func((nodes[node], nodes[nbr]), G_func_args_tuple) / max_weight)
25
+ weights[nbr] *= max(2e-8, 1 - G_func((nodes[node], nodes[nbr]), G_func_args_tuple) / max_weight)
26
26
 
27
27
 
28
28
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -87,9 +87,7 @@ def compute_energy(sample, G_func, G_func_args_tuple, nodes, n_qubits):
87
87
 
88
88
 
89
89
  @njit(parallel=True)
90
- def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thresholds, degrees_sum, J_eff, n):
91
- weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
92
-
90
+ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thresholds, degrees_sum, weights, n):
93
91
  solutions = np.empty((shots, n), dtype=np.bool_)
94
92
  energies = np.empty(shots, dtype=np.float32)
95
93
 
@@ -151,7 +149,13 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
151
149
 
152
150
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
153
151
 
154
- best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, degrees.sum(), J_eff, n_qubits)
152
+ max_weight = degrees.sum()
153
+ degrees = None
154
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
155
+ weights = J_eff.astype(np.float64)
156
+ J_eff = None
157
+
158
+ best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, weights, n_qubits)
155
159
 
156
160
  bit_string, l, r = get_cut(best_solution, nodes)
157
161
 
@@ -159,10 +163,10 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
159
163
 
160
164
 
161
165
  @njit
162
- def gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, J_eff, degrees, hamming_prob):
166
+ def gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights, degrees, hamming_prob, max_weight):
163
167
  fix_cdf(hamming_prob)
164
168
 
165
- best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, degrees.sum(), J_eff, n_qubits)
169
+ best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, weights, n_qubits)
166
170
 
167
171
  bit_string, l, r = get_cut(best_solution, nodes)
168
172
 
@@ -175,6 +179,7 @@ def maxcut_tfim_streaming(
175
179
  G_func_args_tuple=None,
176
180
  quality=None,
177
181
  shots=None,
182
+ is_base_maxcut_gpu=True
178
183
  ):
179
184
  n_qubits = len(nodes)
180
185
 
@@ -193,7 +198,7 @@ def maxcut_tfim_streaming(
193
198
  return "01", weight, ([nodes[0]], [nodes[1]])
194
199
 
195
200
  if quality is None:
196
- quality = 3
201
+ quality = 2
197
202
 
198
203
  if shots is None:
199
204
  # Number of measurement shots
@@ -202,7 +207,7 @@ def maxcut_tfim_streaming(
202
207
  n_steps = 2 << quality
203
208
  grid_size = n_steps * n_qubits
204
209
 
205
- if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
210
+ if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
206
211
  return cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes)
207
212
 
208
213
  J_eff, degrees, G_max = init_J_and_z(G_func, G_func_args_tuple, nodes)
@@ -263,4 +268,10 @@ def maxcut_tfim_streaming(
263
268
  deg_buf = None
264
269
  theta_buf = None
265
270
 
266
- return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, J_eff, degrees, hamming_prob)
271
+ max_weight = degrees.sum()
272
+ degrees = None
273
+ J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
274
+ weights = J_eff.astype(np.float64)
275
+ J_eff = None
276
+
277
+ return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights, degrees, hamming_prob, max_weight)
@@ -119,12 +119,11 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy):
119
119
  queue.finish()
120
120
 
121
121
  # Find global minimum
122
- min_idx = np.argmin(min_energy_host)
123
- energy = min_energy_host[min_idx]
122
+ energy = min_energy_host.min()
124
123
  if min_energy < energy:
125
124
  return min_energy
126
125
 
127
- best_i = min_index_host[min_idx]
126
+ best_i = np.random.choice(np.where(min_energy_host == energy)[0])
128
127
 
129
128
  flip_index_start = best_i * k
130
129
  indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
@@ -140,7 +139,9 @@ def spin_glass_solver(
140
139
  quality=None,
141
140
  shots=None,
142
141
  best_guess=None,
143
- is_alt_gpu_sampling=False
142
+ is_alt_gpu_sampling=False,
143
+ is_base_maxcut_gpu=True,
144
+ is_combo_maxcut_gpu=True
144
145
  ):
145
146
  nodes = None
146
147
  n_qubits = 0
@@ -169,7 +170,7 @@ def spin_glass_solver(
169
170
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
170
171
 
171
172
  if quality is None:
172
- quality = 3
173
+ quality = 2
173
174
 
174
175
  bitstring = ""
175
176
  if isinstance(best_guess, str):
@@ -179,10 +180,10 @@ def spin_glass_solver(
179
180
  elif isinstance(best_guess, list):
180
181
  bitstring = "".join(["1" if b else "0" for b in best_guess])
181
182
  else:
182
- bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True)
183
+ bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True, is_base_maxcut_gpu=is_base_maxcut_gpu)
183
184
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
184
185
 
185
- if IS_OPENCL_AVAILABLE:
186
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
186
187
  if not (opencl_context.G_m_buf is None):
187
188
  G_m_buf = opencl_context.G_m_buf
188
189
  else:
@@ -210,7 +211,7 @@ def spin_glass_solver(
210
211
  else:
211
212
  combos = combos_list[k - 1]
212
213
 
213
- if IS_OPENCL_AVAILABLE:
214
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
214
215
  energy = run_bootstrap_opencl(best_theta, G_m_buf, combos, k, min_energy)
215
216
  else:
216
217
  energy = bootstrap(best_theta, G_m, combos, k, min_energy)
@@ -124,12 +124,11 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
124
124
  queue.finish()
125
125
 
126
126
  # Find global minimum
127
- min_idx = np.argmin(min_energy_host)
128
- energy = min_energy_host[min_idx]
127
+ energy = min_energy_host.min()
129
128
  if min_energy < energy:
130
129
  return min_energy
131
130
 
132
- best_i = min_index_host[min_idx]
131
+ best_i = np.random.choice(np.where(min_energy_host == energy)[0])
133
132
 
134
133
  flip_index_start = best_i * k
135
134
  indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
@@ -157,7 +156,9 @@ def spin_glass_solver_sparse(
157
156
  quality=None,
158
157
  shots=None,
159
158
  best_guess=None,
160
- is_alt_gpu_sampling=False
159
+ is_alt_gpu_sampling=False,
160
+ is_base_maxcut_gpu=True,
161
+ is_combo_maxcut_gpu=True
161
162
  ):
162
163
  nodes = None
163
164
  n_qubits = 0
@@ -186,7 +187,7 @@ def spin_glass_solver_sparse(
186
187
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
187
188
 
188
189
  if quality is None:
189
- quuality = 3
190
+ quuality = 2
190
191
 
191
192
  bitstring = ""
192
193
  if isinstance(best_guess, str):
@@ -196,10 +197,10 @@ def spin_glass_solver_sparse(
196
197
  elif isinstance(best_guess, list):
197
198
  bitstring = "".join(["1" if b else "0" for b in best_guess])
198
199
  else:
199
- bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True)
200
+ bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True, is_base_maxcut_gpu=is_base_maxcut_gpu)
200
201
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
201
202
 
202
- if IS_OPENCL_AVAILABLE:
203
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
203
204
  if not (opencl_context.G_data_buf is None):
204
205
  G_data_buf = opencl_context.G_data_buf
205
206
  G_rows_buf = opencl_context.G_rows_buf
@@ -231,7 +232,7 @@ def spin_glass_solver_sparse(
231
232
  else:
232
233
  combos = combos_list[k - 1]
233
234
 
234
- if IS_OPENCL_AVAILABLE:
235
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
235
236
  energy = run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, combos, k, min_energy)
236
237
  else:
237
238
  energy = bootstrap(best_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, min_energy)
@@ -66,7 +66,8 @@ def spin_glass_solver_streaming(
66
66
  G_func_args_tuple=None,
67
67
  quality=None,
68
68
  shots=None,
69
- best_guess=None
69
+ best_guess=None,
70
+ is_base_maxcut_gpu=True
70
71
  ):
71
72
  n_qubits = len(nodes)
72
73
 
@@ -85,7 +86,7 @@ def spin_glass_solver_streaming(
85
86
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
86
87
 
87
88
  if quality is None:
88
- quality = 3
89
+ quality = 2
89
90
 
90
91
  bitstring = ""
91
92
  if isinstance(best_guess, str):
@@ -95,7 +96,7 @@ def spin_glass_solver_streaming(
95
96
  elif isinstance(best_guess, list):
96
97
  bitstring = "".join(["1" if b else "0" for b in best_guess])
97
98
  else:
98
- bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, G_func_args_tuple=G_func_args_tuple, quality=quality, shots=shots)
99
+ bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, G_func_args_tuple=G_func_args_tuple, quality=quality, shots=shots, is_base_maxcut_gpu=is_base_maxcut_gpu)
99
100
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
100
101
 
101
102
  min_energy = compute_energy(best_theta, G_func, G_func_args_tuple, nodes)
@@ -497,7 +497,21 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
497
497
  return [nodes[x] for x in best_path], best_weight
498
498
 
499
499
 
500
- def tsp_symmetric(G, start_node=None, end_node=None, quality=None, shots=None, is_alt_gpu_sampling=False, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
500
+ def tsp_symmetric(
501
+ G,
502
+ start_node=None,
503
+ end_node=None,
504
+ quality=None,
505
+ shots=None,
506
+ is_alt_gpu_sampling=False,
507
+ is_base_maxcut_gpu=True,
508
+ is_combo_maxcut_gpu=True,
509
+ monte_carlo=True,
510
+ k_neighbors=20,
511
+ is_cyclic=True,
512
+ multi_start=1,
513
+ is_top_level=True
514
+ ):
501
515
  nodes = None
502
516
  n_nodes = 0
503
517
  G_m = None
@@ -540,7 +554,7 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=None, shots=None, i
540
554
  for _ in range(multi_start):
541
555
  bits = ([], [])
542
556
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
543
- _, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling)
557
+ _, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_base_maxcut_gpu=is_base_maxcut_gpu, is_combo_maxcut_gpu=is_combo_maxcut_gpu)
544
558
  if energy < best_energy:
545
559
  best_energy = energy
546
560
  a, b = bits
@@ -555,8 +569,32 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=None, shots=None, i
555
569
 
556
570
  G_a, G_b = init_G_a_b(G_m, a, b)
557
571
 
558
- sol_a = tsp_symmetric(G_a, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
559
- sol_b = tsp_symmetric(G_b, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
572
+ sol_a = tsp_symmetric(
573
+ G_a,
574
+ quality=quality,
575
+ shots=shots,
576
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
577
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
578
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
579
+ monte_carlo=monte_carlo,
580
+ is_cyclic=False,
581
+ is_top_level=False,
582
+ k_neighbors=0,
583
+ multi_start=multi_start
584
+ )
585
+ sol_b = tsp_symmetric(
586
+ G_b,
587
+ quality=quality,
588
+ shots=shots,
589
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
590
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
591
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
592
+ monte_carlo=monte_carlo,
593
+ is_cyclic=False,
594
+ is_top_level=False,
595
+ k_neighbors=0,
596
+ multi_start=multi_start
597
+ )
560
598
 
561
599
  return tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c[0] if len(c) else None)
562
600
 
@@ -643,7 +681,21 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
643
681
  return [nodes[x] for x in final_path], best_weight
644
682
 
645
683
 
646
- def tsp_asymmetric(G, start_node=None, end_node=None, quality=None, shots=None, is_alt_gpu_sampling=False, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
684
+ def tsp_asymmetric(
685
+ G,
686
+ start_node=None,
687
+ end_node=None,
688
+ quality=None,
689
+ shots=None,
690
+ is_alt_gpu_sampling=False,
691
+ is_base_maxcut_gpu=True,
692
+ is_combo_maxcut_gpu=True,
693
+ monte_carlo=True,
694
+ k_neighbors=20,
695
+ is_cyclic=True,
696
+ multi_start=1,
697
+ is_top_level=True
698
+ ):
647
699
  nodes = None
648
700
  n_nodes = 0
649
701
  G_m = None
@@ -690,7 +742,7 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=None, shots=None,
690
742
  for _ in range(multi_start):
691
743
  bits = ([], [])
692
744
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
693
- _, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling)
745
+ _, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_base_maxcut_gpu=is_base_maxcut_gpu, is_combo_maxcut_gpu=is_combo_maxcut_gpu)
694
746
  if energy < best_energy:
695
747
  best_energy = energy
696
748
  a, b = bits
@@ -705,7 +757,31 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=None, shots=None,
705
757
 
706
758
  G_a, G_b = init_G_a_b(G_m, a, b)
707
759
 
708
- sol_a = tsp_asymmetric(G_a, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
709
- sol_b = tsp_asymmetric(G_b, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
760
+ sol_a = tsp_asymmetric(
761
+ G_a,
762
+ quality=quality,
763
+ shots=shots,
764
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
765
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
766
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
767
+ monte_carlo=monte_carlo,
768
+ is_cyclic=False,
769
+ is_top_level=False,
770
+ k_neighbors=0,
771
+ multi_start=multi_start
772
+ )
773
+ sol_b = tsp_asymmetric(
774
+ G_b,
775
+ quality=quality,
776
+ shots=shots,
777
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
778
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
779
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
780
+ monte_carlo=monte_carlo,
781
+ is_cyclic=False,
782
+ is_top_level=False,
783
+ k_neighbors=0,
784
+ multi_start=multi_start
785
+ )
710
786
 
711
787
  return tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c[0] if len(c) else None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.5.3
3
+ Version: 5.7.0
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='5.5.3',
54
+ version='5.7.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