PyQrackIsing 8.4.0__tar.gz → 8.5.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 (30) hide show
  1. {pyqrackising-8.4.0/pyqrackising.egg-info → pyqrackising-8.5.0}/PKG-INFO +1 -1
  2. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/README.md +2 -2
  3. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyproject.toml +1 -1
  4. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/maxcut_tfim.py +18 -14
  5. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/maxcut_tfim_sparse.py +19 -15
  6. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/maxcut_tfim_streaming.py +21 -17
  7. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/spin_glass_solver.py +3 -2
  8. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/spin_glass_solver_sparse.py +3 -2
  9. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/spin_glass_solver_streaming.py +3 -2
  10. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/tsp.py +12 -6
  11. {pyqrackising-8.4.0 → pyqrackising-8.5.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  12. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/setup.py +1 -1
  13. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/CMakeLists.txt +0 -0
  14. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/LICENSE.md +0 -0
  15. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/MANIFEST.in +0 -0
  16. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/__init__.py +0 -0
  17. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  18. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  19. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/generate_tfim_samples.py +0 -0
  20. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/kernels.cl +0 -0
  21. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/maxcut_tfim_util.py +0 -0
  22. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  23. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/tfim_magnetization.py +0 -0
  24. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  25. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising/tsp_maxcut.py +0 -0
  26. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-8.4.0 → pyqrackising-8.5.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.4.0
3
+ Version: 8.5.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
@@ -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=5, shots=None, is_spin_glass=False, anneal_t=8.0, anneal_h=8.0)
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, repulsion_base=4.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 `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.)
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. While `anneal_t` and `anneal_h` control how annealing finds the _Hamming weight_ of cuts (i.e., how many nodes end up in either partition), `repulsion_base` similarly controls the steepness of the search basin for optimizing bit-string locality ("like-like" repulsion and "like-unlike" attraction) within each partition. 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.4.0"
15
+ version = "8.5.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"}
@@ -12,7 +12,7 @@ dtype = opencl_context.dtype
12
12
 
13
13
 
14
14
  @njit
15
- def update_repulsion_choice(G_m, max_edge, weights, n, used, node):
15
+ def update_repulsion_choice(G_m, max_edge, weights, n, used, node, repulsion_base):
16
16
  # Select node
17
17
  used[node] = True
18
18
 
@@ -20,12 +20,12 @@ 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] *= 4 ** (-G_m[node, nbr] / max_edge)
23
+ weights[nbr] *= repulsion_base ** (-G_m[node, nbr] / max_edge)
24
24
 
25
25
 
26
26
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
27
27
  @njit
28
- def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m):
28
+ def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m):
29
29
  """
30
30
  Pick m nodes out of n with repulsion bias:
31
31
  - High-degree nodes are already less likely
@@ -51,7 +51,7 @@ def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m):
51
51
  used[node] = True
52
52
  return used
53
53
 
54
- update_repulsion_choice(G_m, max_edge, weights, n, used, node)
54
+ update_repulsion_choice(G_m, max_edge, weights, n, used, node, repulsion_base)
55
55
 
56
56
  for _ in range(1, m - 1):
57
57
  # Count available
@@ -79,7 +79,7 @@ def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m):
79
79
  node += 1
80
80
 
81
81
  # Update answer and weights
82
- update_repulsion_choice(G_m, max_edge, weights, n, used, node)
82
+ update_repulsion_choice(G_m, max_edge, weights, n, used, node, repulsion_base)
83
83
 
84
84
  # Count available
85
85
  total_w = 0.0
@@ -133,7 +133,7 @@ def compute_cut(sample, G_m, n_qubits):
133
133
 
134
134
 
135
135
  @njit(parallel=True)
136
- def sample_for_energy(G_m, max_edge, shots, thresholds, weights):
136
+ def sample_for_energy(G_m, max_edge, shots, thresholds, weights, repulsion_base):
137
137
  shots = max(1, shots >> 1)
138
138
  n = len(G_m)
139
139
  tot_init_weight = weights.sum()
@@ -156,7 +156,7 @@ def sample_for_energy(G_m, max_edge, shots, thresholds, weights):
156
156
  m += 1
157
157
 
158
158
  # Second dimension: permutation within Hamming weight
159
- sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m)
159
+ sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
160
160
  solutions[s] = sample
161
161
  energies[s] = compute_energy(sample, G_m, n)
162
162
 
@@ -171,7 +171,7 @@ def sample_for_energy(G_m, max_edge, shots, thresholds, weights):
171
171
 
172
172
 
173
173
  @njit(parallel=True)
174
- def sample_for_cut(G_m, max_edge, shots, thresholds, weights):
174
+ def sample_for_cut(G_m, max_edge, shots, thresholds, weights, repulsion_base):
175
175
  shots = max(1, shots >> 1)
176
176
  n = len(G_m)
177
177
  tot_init_weight = weights.sum()
@@ -194,7 +194,7 @@ def sample_for_cut(G_m, max_edge, shots, thresholds, weights):
194
194
  m += 1
195
195
 
196
196
  # Second dimension: permutation within Hamming weight
197
- sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m)
197
+ sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
198
198
  solutions[s] = sample
199
199
  cuts[s] = compute_cut(sample, G_m, n)
200
200
 
@@ -233,7 +233,7 @@ def init_J_and_z(G_m):
233
233
 
234
234
 
235
235
  @njit
236
- def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h):
236
+ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
237
237
  J_eff, degrees, max_edge = init_J_and_z(G_m)
238
238
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
239
239
 
@@ -241,9 +241,9 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, an
241
241
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
242
242
 
243
243
  if is_spin_glass:
244
- best_solution, best_value = sample_for_energy(G_m, max_edge, shots, hamming_prob, J_eff)
244
+ best_solution, best_value = sample_for_energy(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base)
245
245
  else:
246
- best_solution, best_value = sample_for_cut(G_m, max_edge, shots, hamming_prob, J_eff)
246
+ best_solution, best_value = sample_for_cut(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base)
247
247
 
248
248
  bit_string, l, r = get_cut(best_solution, nodes)
249
249
 
@@ -256,7 +256,8 @@ def maxcut_tfim(
256
256
  shots=None,
257
257
  is_spin_glass=False,
258
258
  anneal_t=None,
259
- anneal_h=None
259
+ anneal_h=None,
260
+ repulsion_base=None
260
261
  ):
261
262
  wgs = opencl_context.work_group_size
262
263
  nodes = None
@@ -298,4 +299,7 @@ def maxcut_tfim(
298
299
  if anneal_h is None:
299
300
  anneal_h = 8.0
300
301
 
301
- return cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h)
302
+ if repulsion_base is None:
303
+ repulsion_base = 4.0
304
+
305
+ return cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
@@ -12,7 +12,7 @@ dtype = opencl_context.dtype
12
12
 
13
13
 
14
14
  @njit
15
- def update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node):
15
+ def update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node, repulsion_base):
16
16
  # Select node
17
17
  used[node] = True
18
18
 
@@ -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] *= 4 ** (-G_data[j] / max_edge)
24
+ weights[nbr] *= repulsion_base ** (-G_data[j] / max_edge)
25
25
 
26
26
  for nbr in range(node):
27
27
  if used[nbr]:
@@ -30,12 +30,12 @@ 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] *= 4 ** (-G_data[j] / max_edge)
33
+ weights[nbr] *= repulsion_base ** (-G_data[j] / max_edge)
34
34
 
35
35
 
36
36
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
37
37
  @njit
38
- def local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, n, m):
38
+ def local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, repulsion_base, n, m):
39
39
  """
40
40
  Pick m nodes out of n with repulsion bias:
41
41
  - High-degree nodes are already less likely
@@ -61,7 +61,7 @@ def local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_w
61
61
  used[node] = True
62
62
  return used
63
63
 
64
- update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node)
64
+ update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node, repulsion_base)
65
65
 
66
66
  for _ in range(1, m - 1):
67
67
  # Count available
@@ -89,7 +89,7 @@ def local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_w
89
89
  node += 1
90
90
 
91
91
  # Update answer and weights
92
- update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node)
92
+ update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node, repulsion_base)
93
93
 
94
94
  # Count available
95
95
  total_w = 0.0
@@ -145,7 +145,7 @@ 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(max_edge, 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, repulsion_base):
149
149
  shots = max(1, shots >> 1)
150
150
  n = G_rows.shape[0] - 1
151
151
  tot_init_weight = weights.sum()
@@ -168,7 +168,7 @@ def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weigh
168
168
  m += 1
169
169
 
170
170
  # Second dimension: permutation within Hamming weight
171
- sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, n, m)
171
+ sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, repulsion_base, n, m)
172
172
  solutions[s] = sample
173
173
  energies[s] = compute_energy(sample, G_data, G_rows, G_cols, n)
174
174
 
@@ -183,7 +183,7 @@ def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weigh
183
183
 
184
184
 
185
185
  @njit(parallel=True)
186
- def sample_for_cut(max_edge, 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, repulsion_base):
187
187
  shots = max(1, shots >> 1)
188
188
  n = G_rows.shape[0] - 1
189
189
  tot_init_weight = weights.sum()
@@ -206,7 +206,7 @@ def sample_for_cut(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights)
206
206
  m += 1
207
207
 
208
208
  # Second dimension: permutation within Hamming weight
209
- sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, n, m)
209
+ sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, repulsion_base, n, m)
210
210
  solutions[s] = sample
211
211
  cuts[s] = compute_cut(sample, G_data, G_rows, G_cols, n)
212
212
 
@@ -249,7 +249,7 @@ def init_J_and_z(G_data, G_rows, G_cols):
249
249
 
250
250
 
251
251
  @njit
252
- def cpu_footer(shots, quality, n_qubits, max_edge, 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, repulsion_base):
253
253
  J_eff, degrees = init_J_and_z(G_data, G_rows, G_col)
254
254
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
255
255
 
@@ -257,9 +257,9 @@ def cpu_footer(shots, quality, n_qubits, max_edge, G_data, G_rows, G_col, nodes,
257
257
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
258
258
 
259
259
  if is_spin_glass:
260
- best_solution, best_value = sample_for_energy(max_edge, 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, repulsion_base)
261
261
  else:
262
- best_solution, best_value = sample_for_cut(max_edge, 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, repulsion_base)
263
263
 
264
264
  bit_string, l, r = get_cut(best_solution, nodes)
265
265
 
@@ -272,7 +272,8 @@ def maxcut_tfim_sparse(
272
272
  shots=None,
273
273
  is_spin_glass=False,
274
274
  anneal_t=None,
275
- anneal_h=None
275
+ anneal_h=None,
276
+ repulsion_base=None
276
277
  ):
277
278
  wgs = opencl_context.work_group_size
278
279
  nodes = None
@@ -314,9 +315,12 @@ def maxcut_tfim_sparse(
314
315
  if anneal_h is None:
315
316
  anneal_h = 8.0
316
317
 
318
+ if repulsion_base is None:
319
+ repulsion_base = 4.0
320
+
317
321
  max_edge = abs(G_m.max())
318
322
  min_edge = abs(G_m.min())
319
323
  if min_edge > max_edge:
320
324
  max_edge = min_edge
321
325
 
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)
326
+ 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, repulsion_base)
@@ -12,7 +12,7 @@ dtype = opencl_context.dtype
12
12
 
13
13
 
14
14
  @njit
15
- def update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node):
15
+ def update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node, repulsion_base):
16
16
  # Select node
17
17
  used[node] = True
18
18
 
@@ -20,12 +20,12 @@ 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] *= 4 ** (-G_func(nodes[node], nodes[nbr]) / max_edge)
23
+ weights[nbr] *= repulsion_base ** (-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
27
27
  @njit
28
- def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n, m):
28
+ def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m):
29
29
  """
30
30
  Pick m nodes out of n with repulsion bias:
31
31
  - High-degree nodes are already less likely
@@ -51,7 +51,7 @@ def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n,
51
51
  used[node] = True
52
52
  return used
53
53
 
54
- update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node)
54
+ update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node, repulsion_base)
55
55
 
56
56
  for _ in range(1, m - 1):
57
57
  # Count available
@@ -79,7 +79,7 @@ def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n,
79
79
  node += 1
80
80
 
81
81
  # Update answer and weights
82
- update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node)
82
+ update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node, repulsion_base)
83
83
 
84
84
  # Count available
85
85
  total_w = 0.0
@@ -134,7 +134,7 @@ def compute_cut(sample, G_func, nodes, n_qubits):
134
134
 
135
135
 
136
136
  @njit(parallel=True)
137
- def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n):
137
+ def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base):
138
138
  shots = max(1, shots >> 1)
139
139
  tot_init_weight = weights.sum()
140
140
 
@@ -156,7 +156,7 @@ def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, w
156
156
  m += 1
157
157
 
158
158
  # Second dimension: permutation within Hamming weight
159
- sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n, m)
159
+ sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
160
160
  solutions[s] = sample
161
161
  energies[s] = compute_energy(sample, G_func, nodes, n)
162
162
 
@@ -171,7 +171,7 @@ def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, w
171
171
 
172
172
 
173
173
  @njit(parallel=True)
174
- def sample_for_cut(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n):
174
+ def sample_for_cut(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base):
175
175
  shots = max(1, shots >> 1)
176
176
  tot_init_weight = weights.sum()
177
177
 
@@ -193,7 +193,7 @@ def sample_for_cut(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weig
193
193
  m += 1
194
194
 
195
195
  # Second dimension: permutation within Hamming weight
196
- sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n, m)
196
+ sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
197
197
  solutions[s] = sample
198
198
  cuts[s] = compute_cut(sample, G_func, nodes, n)
199
199
 
@@ -232,7 +232,7 @@ def init_J_and_z(G_func, nodes):
232
232
 
233
233
 
234
234
  @njit
235
- def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h):
235
+ def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
236
236
  J_eff, degrees, max_edge = init_J_and_z(G_func, nodes)
237
237
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
238
238
  max_edge = degrees.sum()
@@ -241,9 +241,9 @@ def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t,
241
241
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
242
242
 
243
243
  if is_spin_glass:
244
- best_solution, best_value = sample_for_energy(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits)
244
+ best_solution, best_value = sample_for_energy(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits, repulsion_base)
245
245
  else:
246
- best_solution, best_value = sample_for_cut(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits)
246
+ best_solution, best_value = sample_for_cut(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits, repulsion_base)
247
247
 
248
248
  bit_string, l, r = get_cut(best_solution, nodes)
249
249
 
@@ -257,7 +257,8 @@ def maxcut_tfim_streaming(
257
257
  shots=None,
258
258
  is_spin_glass=False,
259
259
  anneal_t=None,
260
- anneal_h=None
260
+ anneal_h=None,
261
+ repulsion_base=None
261
262
  ):
262
263
  wgs = opencl_context.work_group_size
263
264
  n_qubits = len(nodes)
@@ -279,14 +280,17 @@ def maxcut_tfim_streaming(
279
280
  if quality is None:
280
281
  quality = 5
281
282
 
283
+ if shots is None:
284
+ # Number of measurement shots
285
+ shots = n_qubits << quality
286
+
282
287
  if anneal_t is None:
283
288
  anneal_t = 8.0
284
289
 
285
290
  if anneal_h is None:
286
291
  anneal_h = 8.0
287
292
 
288
- if shots is None:
289
- # Number of measurement shots
290
- shots = n_qubits << quality
293
+ if repulsion_base is None:
294
+ repulsion_base = 4.0
291
295
 
292
- return cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h)
296
+ return cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
@@ -166,7 +166,8 @@ def spin_glass_solver(
166
166
  is_combo_maxcut_gpu=True,
167
167
  is_spin_glass=True,
168
168
  anneal_t=None,
169
- anneal_h=None
169
+ anneal_h=None,
170
+ repulsion_base=None
170
171
  ):
171
172
  dtype = opencl_context.dtype
172
173
  nodes = None
@@ -209,7 +210,7 @@ def spin_glass_solver(
209
210
  elif isinstance(best_guess, list):
210
211
  bitstring = "".join(["1" if b else "0" for b in best_guess])
211
212
  else:
212
- bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h)
213
+ bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
213
214
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
214
215
 
215
216
  if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
@@ -185,7 +185,8 @@ def spin_glass_solver_sparse(
185
185
  is_combo_maxcut_gpu=True,
186
186
  is_spin_glass=True,
187
187
  anneal_t=None,
188
- anneal_h=None
188
+ anneal_h=None,
189
+ repulsion_base=None
189
190
  ):
190
191
  dtype = opencl_context.dtype
191
192
  nodes = None
@@ -228,7 +229,7 @@ def spin_glass_solver_sparse(
228
229
  elif isinstance(best_guess, list):
229
230
  bitstring = "".join(["1" if b else "0" for b in best_guess])
230
231
  else:
231
- bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h)
232
+ bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
232
233
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
233
234
 
234
235
  if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
@@ -74,7 +74,8 @@ def spin_glass_solver_streaming(
74
74
  best_guess=None,
75
75
  is_spin_glass=True,
76
76
  anneal_t=None,
77
- anneal_h=None
77
+ anneal_h=None,
78
+ repulsion_base=None
78
79
  ):
79
80
  dtype = opencl_context.dtype
80
81
  n_qubits = len(nodes)
@@ -101,7 +102,7 @@ def spin_glass_solver_streaming(
101
102
  elif isinstance(best_guess, list):
102
103
  bitstring = "".join(["1" if b else "0" for b in best_guess])
103
104
  else:
104
- bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h)
105
+ bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, quality=quality, shots=shots, is_spin_glass=is_spin_glass, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
105
106
  best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
106
107
 
107
108
  min_energy = compute_energy(best_theta, G_func, nodes)
@@ -629,6 +629,7 @@ def tsp_symmetric(
629
629
  shots=None,
630
630
  anneal_t=None,
631
631
  anneal_h=None,
632
+ repulsion_base=None,
632
633
  monte_carlo=True,
633
634
  k_neighbors=20,
634
635
  is_cyclic=True,
@@ -680,7 +681,7 @@ def tsp_symmetric(
680
681
  for _ in range(multi_start):
681
682
  bits = ([], [])
682
683
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
683
- _, cut_value, bits = maxcut_tfim(G_m, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h)
684
+ _, cut_value, bits = maxcut_tfim(G_m, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
684
685
  if cut_value > best_cut:
685
686
  best_cut = cut_value
686
687
  a, b = bits
@@ -697,8 +698,8 @@ def tsp_symmetric(
697
698
 
698
699
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
699
700
  with ProcessPoolExecutor(max_workers=1) as executor:
700
- f = executor.submit(tsp_symmetric, G_a, None, None, quality, shots, anneal_t, anneal_h, True, 0, False, multi_start, False, True, parallel_level + 1)
701
- sol_b = tsp_symmetric(G_b, None, None, quality, shots, anneal_t, anneal_h, True, 0, False, multi_start, False, True, parallel_level + 1)
701
+ f = executor.submit(tsp_symmetric, G_a, None, None, quality, shots, anneal_t, anneal_h, repulsion_base, True, 0, False, multi_start, False, True, parallel_level + 1)
702
+ sol_b = tsp_symmetric(G_b, None, None, quality, shots, anneal_t, anneal_h, repulsion_base, True, 0, False, multi_start, False, True, parallel_level + 1)
702
703
  sol_a = f.result()
703
704
  else:
704
705
  sol_a = tsp_symmetric(
@@ -707,6 +708,7 @@ def tsp_symmetric(
707
708
  shots=shots,
708
709
  anneal_t=anneal_t,
709
710
  anneal_h=anneal_h,
711
+ repulsion_base=repulsion_base,
710
712
  monte_carlo=monte_carlo,
711
713
  is_cyclic=False,
712
714
  is_top_level=False,
@@ -720,6 +722,7 @@ def tsp_symmetric(
720
722
  shots=shots,
721
723
  anneal_t=anneal_t,
722
724
  anneal_h=anneal_h,
725
+ repulsion_base=repulsion_base,
723
726
  monte_carlo=monte_carlo,
724
727
  is_cyclic=False,
725
728
  is_top_level=False,
@@ -832,6 +835,7 @@ def tsp_asymmetric(
832
835
  shots=None,
833
836
  anneal_t=None,
834
837
  anneal_h=None,
838
+ repulsion_base=None,
835
839
  monte_carlo=True,
836
840
  k_neighbors=20,
837
841
  is_cyclic=True,
@@ -887,7 +891,7 @@ def tsp_asymmetric(
887
891
  for _ in range(multi_start):
888
892
  bits = ([], [])
889
893
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
890
- _, cut_value, bits = maxcut_tfim((G_m + G_m.T) / 2, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h)
894
+ _, cut_value, bits = maxcut_tfim((G_m + G_m.T) / 2, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
891
895
  if cut_value > best_cut:
892
896
  best_cut = cut_value
893
897
  a, b = bits
@@ -904,8 +908,8 @@ def tsp_asymmetric(
904
908
 
905
909
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 2) and (len(b) > 2):
906
910
  with ProcessPoolExecutor(max_workers=1) as executor:
907
- f = executor.submit(tsp_asymmetric, G_a, None, None, quality, shots, anneal_t, anneal_h, True, 0, False, multi_start, False, True, parallel_level + 1)
908
- sol_b = tsp_asymmetric(G_b, None, None, quality, shots, anneal_t, anneal_h, True, 0, False, multi_start, False, True, parallel_level + 1)
911
+ f = executor.submit(tsp_asymmetric, G_a, None, None, quality, shots, anneal_t, anneal_h, repulsion_base, True, 0, False, multi_start, False, True, parallel_level + 1)
912
+ sol_b = tsp_asymmetric(G_b, None, None, quality, shots, anneal_t, anneal_h, repulsion_base, True, 0, False, multi_start, False, True, parallel_level + 1)
909
913
  sol_a = f.result()
910
914
  else:
911
915
  sol_a = tsp_asymmetric(
@@ -914,6 +918,7 @@ def tsp_asymmetric(
914
918
  shots=shots,
915
919
  anneal_t=anneal_t,
916
920
  anneal_h=anneal_h,
921
+ repulsion_base=repulsion_base,
917
922
  monte_carlo=monte_carlo,
918
923
  is_cyclic=False,
919
924
  is_top_level=False,
@@ -927,6 +932,7 @@ def tsp_asymmetric(
927
932
  shots=shots,
928
933
  anneal_t=anneal_t,
929
934
  anneal_h=anneal_h,
935
+ repulsion_base=repulsion_base,
930
936
  monte_carlo=monte_carlo,
931
937
  is_cyclic=False,
932
938
  is_top_level=False,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.4.0
3
+ Version: 8.5.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='8.4.0',
54
+ version='8.5.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