PyQrackIsing 8.14.5__tar.gz → 8.14.6__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-8.14.5/pyqrackising.egg-info → pyqrackising-8.14.6}/PKG-INFO +1 -1
  2. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyproject.toml +1 -1
  3. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/maxcut_tfim.py +3 -3
  4. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/maxcut_tfim_sparse.py +3 -3
  5. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/maxcut_tfim_streaming.py +2 -2
  6. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/maxcut_tfim_util.py +21 -33
  7. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/spin_glass_solver.py +19 -21
  8. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/spin_glass_solver_sparse.py +18 -20
  9. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/spin_glass_solver_streaming.py +19 -21
  10. {pyqrackising-8.14.5 → pyqrackising-8.14.6/pyqrackising.egg-info}/PKG-INFO +1 -1
  11. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/setup.py +1 -1
  12. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/LICENSE.md +0 -0
  13. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/MANIFEST.in +0 -0
  14. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/README.md +0 -0
  15. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/__init__.py +0 -0
  16. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  17. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/generate_tfim_samples.py +0 -0
  18. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/kernels.cl +0 -0
  19. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/spin_glass_solver_util.py +0 -0
  20. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.14.5 → pyqrackising-8.14.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.5
3
+ Version: 8.14.6
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
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "pyqrackising"
13
- version = "8.14.5"
13
+ version = "8.14.6"
14
14
  requires-python = ">=3.8"
15
15
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
16
16
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -80,7 +80,7 @@ def compute_energy(sample, G_m, n_qubits):
80
80
 
81
81
  @njit
82
82
  def compute_cut(sample, G_m, n_qubits):
83
- l, r = get_cut_base(sample)
83
+ l, r = get_cut_base(sample, n_qubits)
84
84
  cut = 0
85
85
  for u in l:
86
86
  for v in r:
@@ -214,7 +214,7 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, an
214
214
 
215
215
  best_solution, best_value = sample_measurement(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
216
216
 
217
- bit_string, l, r = get_cut(best_solution, nodes)
217
+ bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
218
218
 
219
219
  return bit_string, best_value, (l, r)
220
220
 
@@ -350,7 +350,7 @@ def maxcut_tfim(
350
350
 
351
351
  best_solution, best_value = sample_for_opencl(G_m, G_m_buf, max_edge, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass, is_segmented, segment_size, theta_segment_size)
352
352
 
353
- bit_string, l, r = get_cut(best_solution, nodes)
353
+ bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
354
354
 
355
355
  if best_value < 0.0:
356
356
  # Best cut is trivial partition, all/empty
@@ -91,7 +91,7 @@ def compute_energy(sample, G_data, G_rows, G_cols, n_qubits):
91
91
 
92
92
  @njit
93
93
  def compute_cut(sample, G_data, G_rows, G_cols, n_qubits):
94
- l, r = get_cut_base(sample)
94
+ l, r = get_cut_base(sample, n_qubits)
95
95
  s = l if len(l) < len(r) else r
96
96
  cut = 0
97
97
  for u in s:
@@ -227,7 +227,7 @@ def cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_max, G_data, G_rows,
227
227
 
228
228
  best_solution, best_value = sample_measurement(G_data, G_rows, G_cols, G_max, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
229
229
 
230
- bit_string, l, r = get_cut(best_solution, nodes)
230
+ bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
231
231
 
232
232
  return bit_string, best_value, (l, r)
233
233
 
@@ -417,7 +417,7 @@ def maxcut_tfim_sparse(
417
417
 
418
418
  best_solution, best_value = sample_for_opencl(G_m.data, G_m.indptr, G_m.indices, G_data_buf, G_rows_buf, G_cols_buf, G_max, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass, is_segmented, segment_size, theta_segment_size)
419
419
 
420
- bit_string, l, r = get_cut(best_solution, nodes)
420
+ bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
421
421
 
422
422
  if best_value < 0.0:
423
423
  # Best cut is trivial partition, all/empty
@@ -74,7 +74,7 @@ def compute_energy(sample, G_func, nodes, n_qubits):
74
74
 
75
75
  @njit
76
76
  def compute_cut(sample, G_func, nodes, n_qubits):
77
- l, r = get_cut_base(sample)
77
+ l, r = get_cut_base(sample, n_qubits)
78
78
  cut = 0
79
79
  for u in l:
80
80
  for v in r:
@@ -178,7 +178,7 @@ def cpu_footer(shots, quality, n_qubits, G_min, G_func, nodes, is_spin_glass, an
178
178
 
179
179
  best_solution, best_value = sample_measurement(G_func, nodes, max_edge, shots, hamming_prob, degrees_sum, J_eff, n_qubits, repulsion_base, is_spin_glass)
180
180
 
181
- bit_string, l, r = get_cut(best_solution, nodes)
181
+ bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
182
182
 
183
183
  return bit_string, best_value, (l, r)
184
184
 
@@ -111,7 +111,6 @@ except ImportError:
111
111
  opencl_context = OpenCLContext(compute_units, IS_OPENCL_AVAILABLE, work_group_size, dtype, epsilon, max_alloc, ctx, queue, bootstrap_kernel, bootstrap_sparse_kernel, bootstrap_segmented_kernel, bootstrap_sparse_segmented_kernel, calculate_cut_kernel, calculate_cut_sparse_kernel, calculate_cut_segmented_kernel, calculate_cut_sparse_segmented_kernel)
112
112
 
113
113
 
114
-
115
114
  def setup_opencl(l, g, args_np):
116
115
  ctx = opencl_context.ctx
117
116
  queue = opencl_context.queue
@@ -150,10 +149,10 @@ def make_G_m_buf(G_m, is_segmented, segment_size):
150
149
  _G_m = np.reshape(G_m, (o_shape,))
151
150
  if n_shape != o_shape:
152
151
  np.resize(_G_m, (n_shape,))
153
- _G_m_segments = np.split(_G_m, 4)
152
+ G_m_segments = np.split(_G_m, 4)
154
153
  G_m_buf = [
155
154
  cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=seg)
156
- for seg in _G_m_segments
155
+ for seg in G_m_segments
157
156
  ]
158
157
  else:
159
158
  G_m_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=G_m)
@@ -172,10 +171,10 @@ def make_G_m_csr_buf(G_m, is_segmented, segment_size):
172
171
  _G_data = np.reshape(G_m.data, (o_shape,))
173
172
  if n_shape != o_shape:
174
173
  np.resize(_G_data, (n_shape,))
175
- _G_data_segments = np.split(_G_data, 4)
174
+ G_data_segments = np.split(_G_data, 4)
176
175
  G_data_buf = [
177
176
  cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=seg)
178
- for seg in _G_data_segments
177
+ for seg in G_data_segments
179
178
  ]
180
179
  _G_data = None
181
180
  _G_data_segments = None
@@ -191,10 +190,10 @@ def make_theta_buf(theta, is_segmented, shots, n):
191
190
  if is_segmented:
192
191
  n_shape = (((shots + 3) >> 2) << 2) * ((n + 31) >> 5)
193
192
  theta = np.reshape(theta, (n_shape,))
194
- _theta_segments = np.split(theta, 4)
193
+ theta_segments = np.split(theta, 4)
195
194
  theta_buf = [
196
195
  cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=seg)
197
- for seg in _theta_segments
196
+ for seg in theta_segments
198
197
  ]
199
198
  else:
200
199
  theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
@@ -218,10 +217,10 @@ def convert_bool_to_uint(samples):
218
217
 
219
218
 
220
219
  @njit
221
- def get_cut(solution, nodes):
220
+ def get_cut(solution, nodes, n):
222
221
  bit_string = ""
223
222
  l, r = [], []
224
- for i in range(len(solution)):
223
+ for i in range(n):
225
224
  if solution[i]:
226
225
  bit_string += "1"
227
226
  r.append(nodes[i])
@@ -233,9 +232,9 @@ def get_cut(solution, nodes):
233
232
 
234
233
 
235
234
  @njit
236
- def get_cut_base(solution):
235
+ def get_cut_base(solution, n):
237
236
  l, r = [], []
238
- for i in range(len(solution)):
237
+ for i in range(n):
239
238
  if solution[i]:
240
239
  r.append(i)
241
240
  else:
@@ -363,23 +362,17 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, tot_t, h_mult):
363
362
  for i in range(n_bias):
364
363
  hamming_prob[i] += bias[i] - last_bias[i]
365
364
 
366
- cum_prob = fix_cdf(hamming_prob)
367
-
368
- return cum_prob
369
-
370
- @njit
371
- def fix_cdf(hamming_prob):
372
365
  hamming_prob /= hamming_prob.sum() - (hamming_prob[0] + hamming_prob[-1])
373
366
  tot_prob = 0.0
374
- n_bias = len(hamming_prob) - 2
367
+ n_bias -= 2
375
368
  cum_prob = np.empty(n_bias, dtype=np.float64)
376
369
  for i in range(n_bias):
377
370
  tot_prob += hamming_prob[i + 1]
378
- cum_prob[i] = tot_prob
379
- cum_prob[-1] = 2.0
371
+ cum_prob[i] = 2.0 if (1.0 - tot_prob) <= epsilon else tot_prob
380
372
 
381
373
  return cum_prob
382
374
 
375
+
383
376
  @njit
384
377
  def sample_mag(cum_prob):
385
378
  p = np.random.random()
@@ -400,13 +393,13 @@ def sample_mag(cum_prob):
400
393
  return m + 1
401
394
 
402
395
  @njit
403
- def init_bit_pick(weights, tot_init_weight, n):
404
- r = np.random.rand()
396
+ def init_bit_pick(weights, p, n):
397
+ p *= np.random.rand()
405
398
  cum = 0.0
406
399
  node = 0
407
400
  for i in range(n):
408
401
  cum += weights[i]
409
- if (tot_init_weight * r) < cum:
402
+ if p < cum:
410
403
  node = i
411
404
  break
412
405
 
@@ -415,27 +408,22 @@ def init_bit_pick(weights, tot_init_weight, n):
415
408
  @njit
416
409
  def bit_pick(weights, used, n):
417
410
  # Count available
418
- total_w = 0.0
411
+ p = 0.0
419
412
  for i in range(n):
420
413
  if used[i]:
421
414
  continue
422
- total_w += weights[i]
415
+ p += weights[i]
423
416
 
424
417
  # Normalize & sample
425
- r = np.random.rand()
418
+ p *= np.random.rand()
426
419
  cum = 0.0
427
- node = -1
420
+ node = 0
428
421
  for i in range(n):
429
422
  if used[i]:
430
423
  continue
431
424
  cum += weights[i]
432
- if (total_w * r) < cum:
425
+ if p < cum:
433
426
  node = i
434
427
  break
435
428
 
436
- if node == -1:
437
- node = 0
438
- while used[node]:
439
- node += 1
440
-
441
429
  return node
@@ -18,8 +18,8 @@ except ImportError:
18
18
 
19
19
 
20
20
  @njit
21
- def evaluate_cut_edges(theta_bits, G_m):
22
- l, r = get_cut_base(theta_bits)
21
+ def evaluate_cut_edges(theta_bits, G_m, n):
22
+ l, r = get_cut_base(theta_bits, n)
23
23
  cut = 0
24
24
  for u in l:
25
25
  for v in r:
@@ -29,34 +29,32 @@ def evaluate_cut_edges(theta_bits, G_m):
29
29
 
30
30
 
31
31
  @njit
32
- def compute_energy(theta_bits, G_m):
33
- n_qubits = len(G_m)
32
+ def compute_energy(theta_bits, G_m, n):
34
33
  energy = 0
35
- for u in range(n_qubits):
34
+ for u in range(n):
36
35
  u_bit = theta_bits[u]
37
- for v in range(u + 1, n_qubits):
36
+ for v in range(u + 1, n):
38
37
  energy += G_m[u, v] if u_bit == theta_bits[v] else -G_m[u, v]
39
38
 
40
39
  return energy
41
40
 
42
41
 
43
42
  @njit
44
- def bootstrap_worker(theta, G_m, indices, is_spin_glass):
43
+ def bootstrap_worker(theta, G_m, indices, is_spin_glass, n):
45
44
  local_theta = theta.copy()
46
45
  for i in indices:
47
46
  local_theta[i] = not local_theta[i]
48
- energy = compute_energy(local_theta, G_m) if is_spin_glass else -evaluate_cut_edges(local_theta, G_m)
47
+ energy = compute_energy(local_theta, G_m, n) if is_spin_glass else -evaluate_cut_edges(local_theta, G_m, n)
49
48
 
50
49
  return energy
51
50
 
52
51
 
53
52
  @njit(parallel=True)
54
- def bootstrap(best_theta, G_m, indices_array, k, min_energy, dtype, is_spin_glass):
55
- n = len(indices_array) // k
53
+ def bootstrap(best_theta, G_m, indices_array, k, min_energy, dtype, is_spin_glass, n):
56
54
  energies = np.empty(n, dtype=dtype)
57
55
  for i in prange(n):
58
56
  j = i * k
59
- energies[i] = bootstrap_worker(best_theta, G_m, indices_array[j : j + k], is_spin_glass)
57
+ energies[i] = bootstrap_worker(best_theta, G_m, indices_array[j : j + k], is_spin_glass, n)
60
58
 
61
59
  energy = energies.min()
62
60
  if energy < min_energy:
@@ -133,13 +131,13 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy, i
133
131
  return best_energy
134
132
 
135
133
 
136
- def log_intermediate(theta, G_m, nodes, min_energy, is_spin_glass):
134
+ def log_intermediate(theta, G_m, nodes, min_energy, is_spin_glass, n):
137
135
  bitstring, l, r = get_cut_from_bit_array(theta, nodes)
138
136
  if is_spin_glass:
139
- cut_value = evaluate_cut_edges(theta, G_m)
137
+ cut_value = evaluate_cut_edges(theta, G_m, n)
140
138
  else:
141
139
  cut_value = -min_energy
142
- min_energy = compute_energy(theta, G_m)
140
+ min_energy = compute_energy(theta, G_m, n)
143
141
  print(bitstring, float(cut_value), (l, r), float(min_energy))
144
142
 
145
143
 
@@ -207,10 +205,10 @@ def spin_glass_solver(
207
205
  if max_order is None:
208
206
  max_order = n_qubits
209
207
 
210
- min_energy = compute_energy(best_theta, G_m) if is_spin_glass else -evaluate_cut_edges(best_theta, G_m)
208
+ min_energy = compute_energy(best_theta, G_m, n_qubits) if is_spin_glass else -evaluate_cut_edges(best_theta, G_m, n_qubits)
211
209
 
212
210
  if is_log:
213
- log_intermediate(best_theta, G_m, nodes, min_energy, is_spin_glass)
211
+ log_intermediate(best_theta, G_m, nodes, min_energy, is_spin_glass, n_qubits)
214
212
 
215
213
  combos_list = []
216
214
  reheat_theta = best_theta.copy()
@@ -238,7 +236,7 @@ def spin_glass_solver(
238
236
  opencl_args = setup_opencl(n_qubits, combo_count, np.array([n_qubits, k, combo_count, is_spin_glass, segment_size], dtype=np.int32))
239
237
  energy = run_bootstrap_opencl(reheat_theta, G_m_buf, combos, k, reheat_min_energy, is_segmented, *opencl_args)
240
238
  else:
241
- energy = bootstrap(reheat_theta, G_m, combos, k, reheat_min_energy, dtype, is_spin_glass)
239
+ energy = bootstrap(reheat_theta, G_m, combos, k, reheat_min_energy, dtype, is_spin_glass, n_qubits)
242
240
 
243
241
  if energy < reheat_min_energy:
244
242
  reheat_min_energy = energy
@@ -246,7 +244,7 @@ def spin_glass_solver(
246
244
  if correction_quality < (k + 1):
247
245
  correction_quality = k + 1
248
246
  if is_log:
249
- log_intermediate(reheat_theta, G_m, nodes, reheat_min_energy, is_spin_glass)
247
+ log_intermediate(reheat_theta, G_m, nodes, reheat_min_energy, is_spin_glass, n_qubits)
250
248
 
251
249
  break
252
250
 
@@ -263,15 +261,15 @@ def spin_glass_solver(
263
261
  bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
264
262
  for bit in bits_to_flip:
265
263
  reheat_theta[bit] = not reheat_theta[bit]
266
- reheat_min_energy = compute_energy(reheat_theta, G_m) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_m)
264
+ reheat_min_energy = compute_energy(reheat_theta, G_m, n_qubits) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_m, n_qubits)
267
265
 
268
266
  opencl_context.G_m_buf = None
269
267
 
270
268
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
271
269
  if is_spin_glass:
272
- cut_value = evaluate_cut_edges(best_theta, G_m)
270
+ cut_value = evaluate_cut_edges(best_theta, G_m, n_qubits)
273
271
  else:
274
272
  cut_value = -min_energy
275
- min_energy = compute_energy(best_theta, G_m)
273
+ min_energy = compute_energy(best_theta, G_m, n_qubits)
276
274
 
277
275
  return bitstring, float(cut_value), (l, r), float(min_energy)
@@ -19,8 +19,8 @@ except ImportError:
19
19
 
20
20
 
21
21
  @njit
22
- def evaluate_cut_edges(theta_bits, G_data, G_rows, G_cols):
23
- l, r = get_cut_base(theta_bits)
22
+ def evaluate_cut_edges(theta_bits, G_data, G_rows, G_cols, n):
23
+ l, r = get_cut_base(theta_bits, n)
24
24
  s = l if len(l) < len(r) else r
25
25
  cut = 0
26
26
  for u in s:
@@ -34,10 +34,9 @@ def evaluate_cut_edges(theta_bits, G_data, G_rows, G_cols):
34
34
 
35
35
 
36
36
  @njit
37
- def compute_energy(sample, G_data, G_rows, G_cols):
38
- n_qubits = G_rows.shape[0] - 1
37
+ def compute_energy(sample, G_data, G_rows, G_cols, n):
39
38
  energy = 0
40
- for u in range(n_qubits):
39
+ for u in range(n):
41
40
  for col in range(G_rows[u], G_rows[u + 1]):
42
41
  v = G_cols[col]
43
42
  energy += (G_data[col] if sample[u] == sample[v] else -G_data[col])
@@ -46,22 +45,21 @@ def compute_energy(sample, G_data, G_rows, G_cols):
46
45
 
47
46
 
48
47
  @njit
49
- def bootstrap_worker(theta, G_data, G_rows, G_cols, indices, is_spin_glass):
48
+ def bootstrap_worker(theta, G_data, G_rows, G_cols, indices, is_spin_glass, n):
50
49
  local_theta = theta.copy()
51
50
  for i in indices:
52
51
  local_theta[i] = not local_theta[i]
53
- energy = compute_energy(local_theta, G_data, G_rows, G_cols) if is_spin_glass else -evaluate_cut_edges(local_theta, G_data, G_rows, G_cols)
52
+ energy = compute_energy(local_theta, G_data, G_rows, G_cols, n) if is_spin_glass else -evaluate_cut_edges(local_theta, G_data, G_rows, G_cols, n)
54
53
 
55
54
  return energy
56
55
 
57
56
 
58
57
  @njit(parallel=True)
59
- def bootstrap(best_theta, G_data, G_rows, G_cols, indices_array, k, min_energy, dtype, is_spin_glass):
60
- n = len(indices_array) // k
58
+ def bootstrap(best_theta, G_data, G_rows, G_cols, indices_array, k, min_energy, dtype, is_spin_glass, n):
61
59
  energies = np.empty(n, dtype=dtype)
62
60
  for i in prange(n):
63
61
  j = i * k
64
- energies[i] = bootstrap_worker(best_theta, G_data, G_rows, G_cols, indices_array[j : j + k], is_spin_glass)
62
+ energies[i] = bootstrap_worker(best_theta, G_data, G_rows, G_cols, indices_array[j : j + k], is_spin_glass, n)
65
63
 
66
64
  energy = energies.min()
67
65
  if energy < min_energy:
@@ -154,13 +152,13 @@ def to_scipy_sparse_upper_triangular(G, nodes, n_nodes, dtype):
154
152
  return lil.tocsr()
155
153
 
156
154
 
157
- def log_intermediate(theta, G_data, G_rows, G_cols, nodes, min_energy, is_spin_glass):
155
+ def log_intermediate(theta, G_data, G_rows, G_cols, nodes, min_energy, is_spin_glass, n):
158
156
  bitstring, l, r = get_cut_from_bit_array(theta, nodes)
159
157
  if is_spin_glass:
160
- cut_value = evaluate_cut_edges(theta, G_data, G_rows, G_cols)
158
+ cut_value = evaluate_cut_edges(theta, G_data, G_rows, G_cols, n)
161
159
  else:
162
160
  cut_value = -min_energy
163
- min_energy = compute_energy(theta, G_data, G_rows, G_cols)
161
+ min_energy = compute_energy(theta, G_data, G_rows, G_cols, n)
164
162
  print(bitstring, float(cut_value), (l, r), float(min_energy))
165
163
 
166
164
 
@@ -228,10 +226,10 @@ def spin_glass_solver_sparse(
228
226
  if max_order is None:
229
227
  max_order = n_qubits
230
228
 
231
- min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices) if is_spin_glass else -evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices)
229
+ min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits) if is_spin_glass else -evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits)
232
230
 
233
231
  if is_log:
234
- log_intermediate(best_theta, G_m.data, G_m.indptr, G_m.indices, nodes, min_energy, is_spin_glass)
232
+ log_intermediate(best_theta, G_m.data, G_m.indptr, G_m.indices, nodes, min_energy, is_spin_glass, n_qubits)
235
233
 
236
234
  combos_list = []
237
235
  reheat_theta = best_theta.copy()
@@ -259,7 +257,7 @@ def spin_glass_solver_sparse(
259
257
  opencl_args = setup_opencl(n_qubits, combo_count, np.array([n_qubits, k, combo_count, is_spin_glass, segment_size], dtype=np.int32))
260
258
  energy = run_bootstrap_opencl(reheat_theta, G_data_buf, G_rows_buf, G_cols_buf, combos, k, reheat_min_energy, is_segmented, *opencl_args)
261
259
  else:
262
- energy = bootstrap(reheat_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, reheat_min_energy, dtype, is_spin_glass)
260
+ energy = bootstrap(reheat_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, reheat_min_energy, dtype, is_spin_glass, n_qubits)
263
261
 
264
262
  if energy < reheat_min_energy:
265
263
  reheat_min_energy = energy
@@ -268,7 +266,7 @@ def spin_glass_solver_sparse(
268
266
  correction_quality = k + 1
269
267
 
270
268
  if is_log:
271
- log_intermediate(reheat_theta, G_m.data, G_m.indptr, G_m.indices, nodes, min_energy, is_spin_glass)
269
+ log_intermediate(reheat_theta, G_m.data, G_m.indptr, G_m.indices, nodes, min_energy, is_spin_glass, n_qubits)
272
270
 
273
271
  break
274
272
 
@@ -285,7 +283,7 @@ def spin_glass_solver_sparse(
285
283
  bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
286
284
  for bit in bits_to_flip:
287
285
  reheat_theta[bit] = not reheat_theta[bit]
288
- reheat_min_energy = compute_energy(reheat_theta, G_m.data, G_m.indptr, G_m.indices) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_m.data, G_m.indptr, G_m.indices)
286
+ reheat_min_energy = compute_energy(reheat_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits)
289
287
 
290
288
  opencl_context.G_data_buf = None
291
289
  opencl_context.G_rows_buf = None
@@ -293,9 +291,9 @@ def spin_glass_solver_sparse(
293
291
 
294
292
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
295
293
  if is_spin_glass:
296
- cut_value = evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices)
294
+ cut_value = evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits)
297
295
  else:
298
296
  cut_value = -min_energy
299
- min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices)
297
+ min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits)
300
298
 
301
299
  return bitstring, float(cut_value), (l, r), float(min_energy)
@@ -13,8 +13,8 @@ epsilon = opencl_context.epsilon
13
13
 
14
14
 
15
15
  @njit
16
- def evaluate_cut_edges(theta_bits, G_func, nodes):
17
- l, r = get_cut_base(theta_bits)
16
+ def evaluate_cut_edges(theta_bits, G_func, nodes, n):
17
+ l, r = get_cut_base(theta_bits, n)
18
18
  cut = 0
19
19
  for u in l:
20
20
  for v in r:
@@ -24,12 +24,11 @@ def evaluate_cut_edges(theta_bits, G_func, nodes):
24
24
 
25
25
 
26
26
  @njit
27
- def compute_energy(theta_bits, G_func, nodes):
28
- n_qubits = len(nodes)
27
+ def compute_energy(theta_bits, G_func, nodes, n):
29
28
  energy = 0
30
- for u in range(n_qubits):
29
+ for u in range(n):
31
30
  u_bit = theta_bits[u]
32
- for v in range(u + 1, n_qubits):
31
+ for v in range(u + 1, n):
33
32
  val = G_func(nodes[u], nodes[v])
34
33
  energy += (val if u_bit == theta_bits[v] else -val)
35
34
 
@@ -37,22 +36,21 @@ def compute_energy(theta_bits, G_func, nodes):
37
36
 
38
37
 
39
38
  @njit
40
- def bootstrap_worker(theta, G_func, nodes, indices, is_spin_glass):
39
+ def bootstrap_worker(theta, G_func, nodes, indices, is_spin_glass, n):
41
40
  local_theta = theta.copy()
42
41
  for i in indices:
43
42
  local_theta[i] = not local_theta[i]
44
- energy = compute_energy(local_theta, G_func, nodes) if is_spin_glass else -evaluate_cut_edges(local_theta, G_func, nodes)
43
+ energy = compute_energy(local_theta, G_func, nodes, n) if is_spin_glass else -evaluate_cut_edges(local_theta, G_func, nodes, n)
45
44
 
46
45
  return energy
47
46
 
48
47
 
49
48
  @njit(parallel=True)
50
- def bootstrap(best_theta, G_func, nodes, indices_array, k, min_energy, dtype, is_spin_glass):
51
- n = len(indices_array) // k
49
+ def bootstrap(best_theta, G_func, nodes, indices_array, k, min_energy, dtype, is_spin_glass, n):
52
50
  energies = np.empty(n, dtype=dtype)
53
51
  for i in prange(n):
54
52
  j = i * k
55
- energies[i] = bootstrap_worker(best_theta, G_func, nodes, indices_array[j : j + k], is_spin_glass)
53
+ energies[i] = bootstrap_worker(best_theta, G_func, nodes, indices_array[j : j + k], is_spin_glass, n)
56
54
 
57
55
  energy = energies.min()
58
56
  if energy < min_energy:
@@ -67,13 +65,13 @@ def bootstrap(best_theta, G_func, nodes, indices_array, k, min_energy, dtype, is
67
65
  return min_energy
68
66
 
69
67
 
70
- def log_intermediate(theta, G_func, nodes, min_energy, is_spin_glass):
68
+ def log_intermediate(theta, G_func, nodes, min_energy, is_spin_glass, n):
71
69
  bitstring, l, r = get_cut_from_bit_array(theta, nodes)
72
70
  if is_spin_glass:
73
- cut_value = evaluate_cut_edges(theta, G_func, nodes)
71
+ cut_value = evaluate_cut_edges(theta, G_func, nodes, n)
74
72
  else:
75
73
  cut_value = -min_energy
76
- min_energy = compute_energy(theta, G_func, nodes)
74
+ min_energy = compute_energy(theta, G_func, nodes, n)
77
75
  print(bitstring, float(cut_value), (l, r), float(min_energy))
78
76
 
79
77
 
@@ -123,10 +121,10 @@ def spin_glass_solver_streaming(
123
121
  if max_order is None:
124
122
  max_order = n_qubits
125
123
 
126
- min_energy = compute_energy(best_theta, G_func, nodes) if is_spin_glass else -evaluate_cut_edges(best_theta, G_func, nodes)
124
+ min_energy = compute_energy(best_theta, G_func, nodes, n_qubits) if is_spin_glass else -evaluate_cut_edges(best_theta, G_func, nodes, n_qubits)
127
125
 
128
126
  if is_log:
129
- log_intermediate(best_theta, G_func, nodes, min_energy, is_spin_glass)
127
+ log_intermediate(best_theta, G_func, nodes, min_energy, is_spin_glass, n_qubits)
130
128
 
131
129
  combos_list = []
132
130
  reheat_theta = best_theta.copy()
@@ -149,7 +147,7 @@ def spin_glass_solver_streaming(
149
147
  else:
150
148
  combos = combos_list[k - 1]
151
149
 
152
- energy = bootstrap(best_theta, G_func, nodes, combos, k, min_energy, dtype, is_spin_glass)
150
+ energy = bootstrap(best_theta, G_func, nodes, combos, k, min_energy, dtype, is_spin_glass, n_qubits)
153
151
 
154
152
  if energy < reheat_min_energy:
155
153
  reheat_min_energy = energy
@@ -158,7 +156,7 @@ def spin_glass_solver_streaming(
158
156
  correction_quality = k + 1
159
157
 
160
158
  if is_log:
161
- log_intermediate(reheat_theta, G_func, nodes, min_energy, is_spin_glass)
159
+ log_intermediate(reheat_theta, G_func, nodes, min_energy, is_spin_glass, n_qubits)
162
160
 
163
161
  break
164
162
 
@@ -175,13 +173,13 @@ def spin_glass_solver_streaming(
175
173
  bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
176
174
  for bit in bits_to_flip:
177
175
  reheat_theta[bit] = not reheat_theta[bit]
178
- reheat_min_energy = compute_energy(reheat_theta, G_func, nodes) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_func, nodes)
176
+ reheat_min_energy = compute_energy(reheat_theta, G_func, nodes, n_qubits) if is_spin_glass else -evaluate_cut_edges(reheat_theta, G_func, nodes, n_qubits)
179
177
 
180
178
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
181
179
  if is_spin_glass:
182
- cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
180
+ cut_value = evaluate_cut_edges(best_theta, G_func, nodes, n_qubits)
183
181
  else:
184
182
  cut_value = -min_energy
185
- min_energy = compute_energy(best_theta, G_func, nodes)
183
+ min_energy = compute_energy(best_theta, G_func, nodes, n_qubits)
186
184
 
187
185
  return bitstring, float(cut_value), (l, r), float(min_energy)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.5
3
+ Version: 8.14.6
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
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name='pyqrackising',
10
- version='8.14.5',
10
+ version='8.14.6',
11
11
  author='Dan Strano',
12
12
  author_email='stranoj@gmail.com',
13
13
  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