PyQrackIsing 5.7.2__tar.gz → 5.7.4__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.7.2/pyqrackising.egg-info → pyqrackising-5.7.4}/PKG-INFO +1 -1
  2. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyproject.toml +1 -1
  3. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/kernels.cl +61 -50
  4. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim.py +10 -14
  5. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_sparse.py +11 -15
  6. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_streaming.py +9 -13
  7. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver.py +4 -2
  8. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_sparse.py +4 -2
  9. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_streaming.py +1 -1
  10. {pyqrackising-5.7.2 → pyqrackising-5.7.4/pyqrackising.egg-info}/PKG-INFO +1 -1
  11. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/setup.py +1 -1
  12. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/CMakeLists.txt +0 -0
  13. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/LICENSE.md +0 -0
  14. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/MANIFEST.in +0 -0
  15. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/README.md +0 -0
  16. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/__init__.py +0 -0
  17. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/_pyqrack_ising.cpp +0 -0
  18. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/generate_tfim_samples.py +0 -0
  19. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_util.py +0 -0
  20. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising/tsp.py +0 -0
  24. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-5.7.2 → pyqrackising-5.7.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.2
3
+ Version: 5.7.4
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
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "5.7.2"
15
+ version = "5.7.4"
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"}
@@ -1,94 +1,103 @@
1
1
  __kernel void init_theta(
2
- __constant float* fargs,
2
+ __constant double* fargs,
3
3
  const int n_qubits,
4
- __constant float* J_eff,
5
- __constant float* degrees,
6
- __global float* theta
4
+ __constant double* J_eff,
5
+ __constant unsigned* degrees,
6
+ __global double* theta
7
7
  ) {
8
8
  const int q = get_global_id(0);
9
9
  if (q >= n_qubits) {
10
10
  return;
11
11
  }
12
12
 
13
- const float h_mult = fabs(fargs[2]);
13
+ const double h_mult = fabs(fargs[2]);
14
14
 
15
- const float J = J_eff[q];
16
- const float z = degrees[q];
17
- const float abs_zJ = fabs(z * J);
15
+ const double J = J_eff[q];
16
+ const unsigned z = degrees[q];
17
+ const double abs_zJ = fabs(z * J);
18
18
 
19
19
  float val;
20
- if (abs_zJ < 2e-40f) {
21
- val = (J > 0.0f) ? M_PI_F : -M_PI_F;
20
+ if (abs_zJ < 2e-52) {
21
+ val = (J > 0.0) ? M_PI_F : -M_PI_F;
22
22
  } else {
23
- val = asin(fmax(-1.0f, fmin(1.0f, h_mult / (z * J))));
23
+ val = asin(fmax(-1.0, fmin(1.0, h_mult / (z * J))));
24
24
  }
25
25
 
26
26
  theta[q] = val;
27
27
  }
28
28
 
29
29
  // By Google Search AI
30
- inline void AtomicAdd_g_f(volatile __global float *source, const float operand) {
30
+ inline void AtomicAdd_g_f(volatile __global double *source, const double operand) {
31
31
  union {
32
- unsigned int intVal;
33
- float floatVal;
32
+ ulong intVal;
33
+ double floatVal;
34
34
  } oldVal, newVal;
35
35
 
36
36
  do {
37
37
  oldVal.floatVal = *source;
38
38
  newVal.floatVal = oldVal.floatVal + operand;
39
39
  // Use atomic_cmpxchg to atomically update the value
40
- } while (atomic_cmpxchg((volatile __global unsigned int*)source, oldVal.intVal, newVal.intVal) != oldVal.intVal);
40
+ } while (atomic_cmpxchg((volatile __global ulong*)source, oldVal.intVal, newVal.intVal) != oldVal.intVal);
41
41
  }
42
42
 
43
43
  // By Elara (custom OpenAI GPT)
44
- inline float probability_by_hamming_weight(
45
- int q, float J, float h, float z, float theta, float t, int n_qubits
44
+ inline double probability_by_hamming_weight(
45
+ int q, double J, double h, unsigned z, double theta, double t, int n_qubits
46
46
  ) {
47
- float ratio = fabs(h) / (z * J);
48
- if (ratio > 1.0f) ratio = 1.0f;
49
- float theta_c = asin(ratio);
47
+ double ratio = fabs(h) / (z * J);
48
+ if (ratio > 1.0) {
49
+ ratio = 1.0;
50
+ }
51
+ double theta_c = asin(ratio);
52
+
53
+ double p = pow(2.0, fabs(J / h) - 1.0)
54
+ * (1.0 + sin(theta - theta_c) * cos(1.5 * M_PI_F * J * t + theta) / (1.0 + sqrt(t)))
55
+ - 0.5;
50
56
 
51
- float p = pow(2.0f, fabs(J / h) - 1.0f)
52
- * (1.0f + sin(theta - theta_c) * cos(1.5f * M_PI_F * J * t + theta) / (1.0f + sqrt(t)))
53
- - 0.5f;
57
+ if ((p * (n_qubits + 2.0)) >= 1024.0) {
58
+ return 0.0;
59
+ }
54
60
 
55
- if ((p * (n_qubits + 2.0f)) >= 1024.0f) return 0.0f;
61
+ double numerator = pow(2.0, (n_qubits + 2.0) * p) - 1.0;
62
+ double denominator = pow(2.0, p) - 1.0;
63
+ double result = numerator * pow(2.0, -((n_qubits + 1.0) * p) - p * q) / denominator;
56
64
 
57
- float numerator = pow(2.0f, (n_qubits + 2.0f) * p) - 1.0f;
58
- float denominator = pow(2.0f, p) - 1.0f;
59
- float result = numerator * pow(2.0f, -((n_qubits + 1.0f) * p) - p * q) / denominator;
65
+ if (isnan(result) || isinf(result)) {
66
+ return 0.0;
67
+ }
60
68
 
61
- if (isnan(result) || isinf(result)) return 0.0f;
62
69
  return result;
63
70
  }
64
71
 
65
72
  __kernel void maxcut_hamming_cdf(
66
73
  int n_qubits,
67
- __constant int* degrees,
68
- __constant float* args,
69
- __constant float* J_func,
70
- __constant float* theta,
71
- __global float* hamming_prob
74
+ __constant unsigned* degrees,
75
+ __constant double* args,
76
+ __constant double* J_func,
77
+ __constant double* theta,
78
+ __global double* hamming_prob
72
79
  ) {
73
- const float delta_t = args[0U];
74
- const float tot_t = args[1U];
75
- const float h_mult = args[2U];
80
+ const double delta_t = args[0U];
81
+ const double tot_t = args[1U];
82
+ const double h_mult = args[2U];
76
83
  const int step = get_group_id(0) / n_qubits;
77
84
  const int qi = get_group_id(0) % n_qubits;
78
- const float J_eff = J_func[qi];
79
- const float z = degrees[qi];
80
- if (fabs(z * J_eff) <= (pow(2.0f, -52))) return;
85
+ const double J_eff = J_func[qi];
86
+ const unsigned z = degrees[qi];
87
+ if (fabs(z * J_eff) <= 2e-52) {
88
+ return;
89
+ }
81
90
 
82
- const float theta_eff = theta[qi];
83
- const float t = step * delta_t;
84
- const float tm1 = (step - 1) * delta_t;
85
- const float h_t = h_mult * (tot_t - t);
91
+ const double theta_eff = theta[qi];
92
+ const double t = step * delta_t;
93
+ const double tm1 = (step - 1) * delta_t;
94
+ const double h_t = h_mult * (tot_t - t);
86
95
 
87
96
  const int n_threads = get_local_size(0);
88
97
 
89
98
  for (int qo = get_local_id(0); qo < n_qubits; qo += n_threads) {
90
- int _qo = (J_eff > 0.0f) ? (n_qubits - (1 + qo)) : qo;
91
- float diff = probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, t, n_qubits);
99
+ int _qo = (J_eff > 0.0) ? (n_qubits - (1 + qo)) : qo;
100
+ double diff = probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, t, n_qubits);
92
101
  diff -= probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, tm1, n_qubits);
93
102
  AtomicAdd_g_f(&(hamming_prob[_qo]), diff);
94
103
  }
@@ -131,6 +140,8 @@ float bootstrap_worker(__constant char* theta, __global double* G_m, __constant
131
140
  return (float)energy;
132
141
  }
133
142
 
143
+ #define EPSILON 1.1920928955078125e-7
144
+
134
145
  __kernel void bootstrap(
135
146
  uint prng_seed,
136
147
  __global double* G_m,
@@ -174,7 +185,7 @@ __kernel void bootstrap(
174
185
  if (hid_energy < lid_energy) {
175
186
  loc_energy[lt_id] = hid_energy;
176
187
  loc_index[lt_id] = loc_index[lt_id + offset];
177
- } else if ((hid_energy == lid_energy) && ((xorshift32(&prng_seed) >> 31) & 1)) {
188
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
178
189
  loc_index[lt_id] = loc_index[lt_id + offset];
179
190
  }
180
191
  }
@@ -259,7 +270,7 @@ __kernel void bootstrap_sparse(
259
270
  if (hid_energy < lid_energy) {
260
271
  loc_energy[lt_id] = hid_energy;
261
272
  loc_index[lt_id] = loc_index[lt_id + offset];
262
- } else if ((hid_energy == lid_energy) && ((xorshift32(&prng_seed) >> 31) & 1)) {
273
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
263
274
  loc_index[lt_id] = loc_index[lt_id + offset];
264
275
  }
265
276
  }
@@ -368,7 +379,7 @@ __kernel void sample_for_solution_best_bitset(
368
379
  break;
369
380
  }
370
381
  if ((temp_sol[k >> 5] >> l) & 1) {
371
- weight *= max(2e-7, 1.0 - G_m[u_offset + v] / max_weight);
382
+ weight *= max(EPSILON, 1.0 - G_m[u_offset + v] / max_weight);
372
383
  }
373
384
  }
374
385
  }
@@ -572,7 +583,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
572
583
  const int v = G_cols[col];
573
584
 
574
585
  if ((temp_sol[v >> 5] >> (v & 31)) & 1) {
575
- weight *= max(2e-7, 1.0 - G_data[col] / max_weight);
586
+ weight *= max(EPSILON, 1.0 - G_data[col] / max_weight);
576
587
  }
577
588
  }
578
589
 
@@ -584,7 +595,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
584
595
  int end = G_rows[v + 1];
585
596
  int j = binary_search(&(G_cols[start]), u, end - start) + start;
586
597
  if (j < end) {
587
- weight *= max(2e-7, 1.0 - G_data[j] / max_weight);
598
+ weight *= max(EPSILON, 1.0 - G_data[j] / max_weight);
588
599
  }
589
600
  }
590
601
 
@@ -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-8, 1 - G_m[node, nbr] / max_weight)
25
+ weights[nbr] *= max(1.1920928955078125e-7, 1 - G_m[node, nbr] / max_weight)
26
26
 
27
27
 
28
28
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -120,7 +120,7 @@ def sample_for_solution(G_m, shots, thresholds, weights):
120
120
  def init_J_and_z(G_m):
121
121
  n_qubits = len(G_m)
122
122
  degrees = np.empty(n_qubits, dtype=np.uint32)
123
- J_eff = np.empty(n_qubits, dtype=np.float32)
123
+ J_eff = np.empty(n_qubits, dtype=np.float64)
124
124
  J_max = -float("inf")
125
125
  for n in prange(n_qubits):
126
126
  degree = sum(G_m[n] != 0.0)
@@ -218,11 +218,9 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
218
218
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
219
219
 
220
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
221
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
224
222
 
225
- best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights)
223
+ best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, J_eff)
226
224
 
227
225
  bit_string, l, r = get_cut(best_solution, nodes)
228
226
 
@@ -275,13 +273,13 @@ def maxcut_tfim(
275
273
  return "01", weight, ([nodes[0]], [nodes[1]])
276
274
 
277
275
  if quality is None:
278
- quality = 2
276
+ quality = 3
279
277
 
280
278
  if shots is None:
281
279
  # Number of measurement shots
282
280
  shots = n_qubits << quality
283
281
 
284
- n_steps = 2 << quality
282
+ n_steps = n_qubits << quality
285
283
  grid_size = n_steps * n_qubits
286
284
 
287
285
  if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
@@ -293,7 +291,7 @@ def maxcut_tfim(
293
291
  tot_t = 2.0 * n_steps * delta_t
294
292
  h_mult = 2.0 / tot_t
295
293
 
296
- args = np.empty(3, dtype=np.float32)
294
+ args = np.empty(3, dtype=np.float64)
297
295
  args[0] = delta_t
298
296
  args[1] = tot_t
299
297
  args[2] = h_mult
@@ -303,7 +301,7 @@ def maxcut_tfim(
303
301
  args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
304
302
  J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
305
303
  deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
306
- theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.float32().nbytes))
304
+ theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.float64().nbytes))
307
305
 
308
306
  # Warp size is 32:
309
307
  group_size = min(n_qubits, 64)
@@ -347,11 +345,9 @@ def maxcut_tfim(
347
345
 
348
346
  if not is_alt_gpu_sampling:
349
347
  degrees = None
350
- J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
351
- weights = J_eff.astype(np.float64)
352
- J_eff = None
348
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
353
349
 
354
- return gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes)
350
+ return gpu_footer(shots, n_qubits, G_m, J_eff, hamming_prob, nodes)
355
351
 
356
352
  fix_cdf(hamming_prob)
357
353
  best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
@@ -43,7 +43,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
43
43
  nbr = G_cols[j]
44
44
  if used[nbr]:
45
45
  continue
46
- weights[nbr] *= max(2e-7, 1 - G_data[j] / max_weight)
46
+ weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_weight)
47
47
 
48
48
  for nbr in range(node):
49
49
  if used[nbr]:
@@ -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-8, 1 - G_data[j] / max_weight)
55
+ weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_weight)
56
56
 
57
57
 
58
58
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -152,7 +152,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights):
152
152
  def init_J_and_z(G_data, G_rows, G_cols):
153
153
  n_qubits = G_rows.shape[0] - 1
154
154
  degrees = np.empty(n_qubits, dtype=np.uint32)
155
- J_eff = np.empty(n_qubits, dtype=np.float32)
155
+ J_eff = np.empty(n_qubits, dtype=np.float64)
156
156
  for r in prange(n_qubits):
157
157
  # Row sum
158
158
  start = G_rows[r]
@@ -271,11 +271,9 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
271
271
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
272
272
 
273
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
274
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
277
275
 
278
- best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, weights)
276
+ best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, J_eff)
279
277
 
280
278
  bit_string, l, r = get_cut(best_solution, nodes)
281
279
 
@@ -294,7 +292,7 @@ def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, weights, hamming_prob, n
294
292
 
295
293
 
296
294
  def to_scipy_sparse_upper_triangular(G, nodes, n_nodes):
297
- lil = lil_matrix((n_nodes, n_nodes), dtype=np.float32)
295
+ lil = lil_matrix((n_nodes, n_nodes), dtype=np.float64)
298
296
  for u in range(n_nodes):
299
297
  u_node = nodes[u]
300
298
  for v in range(u + 1, n_nodes):
@@ -340,13 +338,13 @@ def maxcut_tfim_sparse(
340
338
  return "01", weight, ([nodes[0]], [nodes[1]])
341
339
 
342
340
  if quality is None:
343
- quality = 2
341
+ quality = 3
344
342
 
345
343
  if shots is None:
346
344
  # Number of measurement shots
347
345
  shots = n_qubits << quality
348
346
 
349
- n_steps = 2 << quality
347
+ n_steps = n_qubits << quality
350
348
  grid_size = n_steps * n_qubits
351
349
 
352
350
  if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
@@ -358,7 +356,7 @@ def maxcut_tfim_sparse(
358
356
  tot_t = 2.0 * n_steps * delta_t
359
357
  h_mult = 2.0 / tot_t
360
358
 
361
- args = np.empty(3, dtype=np.float32)
359
+ args = np.empty(3, dtype=np.float64)
362
360
  args[0] = delta_t
363
361
  args[1] = tot_t
364
362
  args[2] = h_mult
@@ -412,11 +410,9 @@ def maxcut_tfim_sparse(
412
410
 
413
411
  if not is_alt_gpu_sampling:
414
412
  degrees = None
415
- J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
416
- weights = J_eff.astype(np.float64)
417
- J_eff = None
413
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
418
414
 
419
- return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, weights, hamming_prob, nodes)
415
+ return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, J_eff, hamming_prob, nodes)
420
416
 
421
417
  fix_cdf(hamming_prob)
422
418
  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-8, 1 - G_func((nodes[node], nodes[nbr]), G_func_args_tuple) / max_weight)
25
+ weights[nbr] *= max(1.1920928955078125e-7, 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
@@ -120,7 +120,7 @@ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thr
120
120
  def init_J_and_z(G_func, G_func_args_tuple, nodes):
121
121
  n_qubits = len(nodes)
122
122
  degrees = np.empty(n_qubits, dtype=np.uint32)
123
- J_eff = np.empty(n_qubits, dtype=np.float32)
123
+ J_eff = np.empty(n_qubits, dtype=np.float64)
124
124
  J_max = -float("inf")
125
125
  G_max = -float("inf")
126
126
  for n in prange(n_qubits):
@@ -151,11 +151,9 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
151
151
 
152
152
  max_weight = degrees.sum()
153
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
154
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
157
155
 
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)
156
+ best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, J_eff, n_qubits)
159
157
 
160
158
  bit_string, l, r = get_cut(best_solution, nodes)
161
159
 
@@ -198,13 +196,13 @@ def maxcut_tfim_streaming(
198
196
  return "01", weight, ([nodes[0]], [nodes[1]])
199
197
 
200
198
  if quality is None:
201
- quality = 2
199
+ quality = 3
202
200
 
203
201
  if shots is None:
204
202
  # Number of measurement shots
205
203
  shots = n_qubits << quality
206
204
 
207
- n_steps = 2 << quality
205
+ n_steps = n_qubits << quality
208
206
  grid_size = n_steps * n_qubits
209
207
 
210
208
  if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
@@ -216,7 +214,7 @@ def maxcut_tfim_streaming(
216
214
  tot_t = 2.0 * n_steps * delta_t
217
215
  h_mult = 2.0 / tot_t
218
216
 
219
- args = np.empty(3, dtype=np.float32)
217
+ args = np.empty(3, dtype=np.float64)
220
218
  args[0] = delta_t
221
219
  args[1] = tot_t
222
220
  args[2] = h_mult
@@ -270,8 +268,6 @@ def maxcut_tfim_streaming(
270
268
 
271
269
  max_weight = degrees.sum()
272
270
  degrees = None
273
- J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
274
- weights = J_eff.astype(np.float64)
275
- J_eff = None
271
+ J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
276
272
 
277
- return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights, degrees, hamming_prob, max_weight)
273
+ return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, J_eff, degrees, hamming_prob, max_weight)
@@ -124,7 +124,9 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy):
124
124
  if min_energy < energy:
125
125
  return min_energy
126
126
 
127
- best_i = np.random.choice(np.where(min_energy_host == energy)[0])
127
+ ENERGY_EPSILON = 2e-23
128
+ choices = np.where(abs(min_energy_host - energy) <= ENERGY_EPSILON)[0]
129
+ best_i = np.random.choice(choices) if len(choices) else np.argmin(min_energy_host)
128
130
 
129
131
  flip_index_start = best_i * k
130
132
  indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
@@ -171,7 +173,7 @@ def spin_glass_solver(
171
173
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
172
174
 
173
175
  if quality is None:
174
- quality = 2
176
+ quality = 3
175
177
 
176
178
  bitstring = ""
177
179
  if isinstance(best_guess, str):
@@ -129,7 +129,9 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
129
129
  if min_energy < energy:
130
130
  return min_energy
131
131
 
132
- best_i = np.random.choice(np.where(min_energy_host == energy)[0])
132
+ ENERGY_EPSILON = 2e-23
133
+ choices = np.where(abs(min_energy_host - energy) <= ENERGY_EPSILON)[0]
134
+ best_i = np.random.choice(choices) if len(choices) else np.argmin(min_energy_host)
133
135
 
134
136
  flip_index_start = best_i * k
135
137
  indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
@@ -188,7 +190,7 @@ def spin_glass_solver_sparse(
188
190
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
189
191
 
190
192
  if quality is None:
191
- quuality = 2
193
+ quuality = 3
192
194
 
193
195
  bitstring = ""
194
196
  if isinstance(best_guess, str):
@@ -86,7 +86,7 @@ def spin_glass_solver_streaming(
86
86
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
87
87
 
88
88
  if quality is None:
89
- quality = 2
89
+ quality = 3
90
90
 
91
91
  bitstring = ""
92
92
  if isinstance(best_guess, str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.2
3
+ Version: 5.7.4
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.7.2',
54
+ version='5.7.4',
55
55
  author='Dan Strano',
56
56
  author_email='stranoj@gmail.com',
57
57
  description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)',
File without changes
File without changes
File without changes
File without changes