PyQrackIsing 5.7.4__tar.gz → 6.0.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.7.4/pyqrackising.egg-info → pyqrackising-6.0.0}/PKG-INFO +1 -1
  2. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/README.md +2 -2
  3. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyproject.toml +1 -1
  4. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/kernels.cl +91 -99
  5. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/maxcut_tfim.py +6 -6
  6. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/maxcut_tfim_sparse.py +5 -5
  7. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/spin_glass_solver.py +2 -3
  8. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/spin_glass_solver_sparse.py +2 -3
  9. {pyqrackising-5.7.4 → pyqrackising-6.0.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  10. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/setup.py +1 -1
  11. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/CMakeLists.txt +0 -0
  12. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/LICENSE.md +0 -0
  13. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/MANIFEST.in +0 -0
  14. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/__init__.py +0 -0
  15. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  16. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/generate_tfim_samples.py +0 -0
  17. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/maxcut_tfim_util.py +0 -0
  19. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising/tsp.py +0 -0
  24. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-5.7.4 → pyqrackising-6.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.4
3
+ Version: 6.0.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
@@ -44,7 +44,7 @@ samples = generate_tfim_samples(
44
44
 
45
45
  There are two other functions, `tfim_magnetization()` and `tfim_square_magnetization()`, that follow the same function signature except without the `shots` argument.
46
46
 
47
- The library also provides a TFIM-inspired (approximate) MAXCUT solver:
47
+ The library also provides a TFIM-inspired (approximate) MAXCUT solver (which accepts a `networkx` graph or a 32-bit adjacency matrix):
48
48
  ```py
49
49
  from pyqrackising import maxcut_tfim
50
50
  import networkx as nx
@@ -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_base_maxcut_gpu=True, is_alt_gpu_sampling=True, is_combo_maxcut_gpu=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 `2`. `is_combo_maxcut_gpu` controls whether gradient descent optimization is done on GPU (which is the most costly GPU-based feature), while `is_base_maxcut_gpu` is passed through the underlying `maxcut_tfim(G)` solver. `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` (32-bit) **upper-triangular** CSR sparse arrays (or `networkx` graphs). The (integer) default `quality` setting is `2`. `is_combo_maxcut_gpu` controls whether gradient descent optimization is done on GPU (which is the most costly GPU-based feature), while `is_base_maxcut_gpu` is passed through the underlying `maxcut_tfim(G)` solver. `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.7.4"
15
+ version = "6.0.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"}
@@ -1,69 +1,61 @@
1
1
  __kernel void init_theta(
2
- __constant double* fargs,
2
+ __constant float* fargs,
3
3
  const int n_qubits,
4
- __constant double* J_eff,
4
+ __constant float* J_eff,
5
5
  __constant unsigned* degrees,
6
- __global double* theta
6
+ __global float* 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 double h_mult = fabs(fargs[2]);
14
-
15
- const double J = J_eff[q];
13
+ const float h_mult = fabs(fargs[2]);
14
+ const float J = J_eff[q];
16
15
  const unsigned z = degrees[q];
17
- const double abs_zJ = fabs(z * J);
18
-
19
- float val;
20
- if (abs_zJ < 2e-52) {
21
- val = (J > 0.0) ? M_PI_F : -M_PI_F;
22
- } else {
23
- val = asin(fmax(-1.0, fmin(1.0, h_mult / (z * J))));
24
- }
16
+ const float abs_zJ = fabs(z * J);
25
17
 
26
- theta[q] = val;
18
+ theta[q] = (abs_zJ <= FLT_EPSILON) ? ((J > 0.0f) ? M_PI_F : -M_PI_F) : (asin(fmax(-1.0f, fmin(1.0f, h_mult / (z * J)))));
27
19
  }
28
20
 
29
21
  // By Google Search AI
30
- inline void AtomicAdd_g_f(volatile __global double *source, const double operand) {
31
- union {
32
- ulong intVal;
33
- double floatVal;
34
- } oldVal, newVal;
22
+ inline void atomic_add_float(__global float* address, float val) {
23
+ int old_val_ll;
24
+ int new_val_ll;
25
+ float old_val_d;
35
26
 
36
27
  do {
37
- oldVal.floatVal = *source;
38
- newVal.floatVal = oldVal.floatVal + operand;
39
- // Use atomic_cmpxchg to atomically update the value
40
- } while (atomic_cmpxchg((volatile __global ulong*)source, oldVal.intVal, newVal.intVal) != oldVal.intVal);
28
+ old_val_d = *address;
29
+ old_val_ll = as_int(old_val_d); // Reinterpret float as int
30
+ new_val_ll = as_int(old_val_d + val); // Perform addition, then reinterpret
31
+
32
+ } while (atom_cmpxchg((__global int*)address, old_val_ll, new_val_ll) != old_val_ll);
41
33
  }
42
34
 
43
35
  // By Elara (custom OpenAI GPT)
44
- inline double probability_by_hamming_weight(
45
- int q, double J, double h, unsigned z, double theta, double t, int n_qubits
36
+ inline float probability_by_hamming_weight(
37
+ int q, float J, float h, unsigned z, float theta, float t, int n_qubits
46
38
  ) {
47
- double ratio = fabs(h) / (z * J);
48
- if (ratio > 1.0) {
49
- ratio = 1.0;
39
+ float ratio = fabs(h) / (z * J);
40
+ if (ratio > 1.0f) {
41
+ ratio = 1.0f;
50
42
  }
51
- double theta_c = asin(ratio);
43
+ float theta_c = asin(ratio);
52
44
 
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;
45
+ float p = pow(2.0f, fabs(J / h) - 1.0f)
46
+ * (1.0f + sin(theta - theta_c) * cos(1.5f * M_PI_F * J * t + theta) / (1.0f + sqrt(t)))
47
+ - 0.5f;
56
48
 
57
- if ((p * (n_qubits + 2.0)) >= 1024.0) {
58
- return 0.0;
49
+ if ((p * (n_qubits + 2.0f)) >= 128.0f) {
50
+ return 0.0f;
59
51
  }
60
52
 
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;
53
+ float numerator = pow(2.0f, (n_qubits + 2.0f) * p) - 1.0f;
54
+ float denominator = pow(2.0f, p) - 1.0f;
55
+ float result = numerator * pow(2.0f, -((n_qubits + 1.0f) * p) - p * q) / denominator;
64
56
 
65
57
  if (isnan(result) || isinf(result)) {
66
- return 0.0;
58
+ return 0.0f;
67
59
  }
68
60
 
69
61
  return result;
@@ -72,34 +64,34 @@ inline double probability_by_hamming_weight(
72
64
  __kernel void maxcut_hamming_cdf(
73
65
  int n_qubits,
74
66
  __constant unsigned* degrees,
75
- __constant double* args,
76
- __constant double* J_func,
77
- __constant double* theta,
78
- __global double* hamming_prob
67
+ __constant float* args,
68
+ __constant float* J_func,
69
+ __constant float* theta,
70
+ __global float* hamming_prob
79
71
  ) {
80
- const double delta_t = args[0U];
81
- const double tot_t = args[1U];
82
- const double h_mult = args[2U];
72
+ const float delta_t = args[0U];
73
+ const float tot_t = args[1U];
74
+ const float h_mult = args[2U];
83
75
  const int step = get_group_id(0) / n_qubits;
84
76
  const int qi = get_group_id(0) % n_qubits;
85
- const double J_eff = J_func[qi];
77
+ const float J_eff = J_func[qi];
86
78
  const unsigned z = degrees[qi];
87
- if (fabs(z * J_eff) <= 2e-52) {
79
+ if (fabs(z * J_eff) <= FLT_EPSILON) {
88
80
  return;
89
81
  }
90
82
 
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);
83
+ const float theta_eff = theta[qi];
84
+ const float t = step * delta_t;
85
+ const float tm1 = (step - 1) * delta_t;
86
+ const float h_t = h_mult * (tot_t - t);
95
87
 
96
88
  const int n_threads = get_local_size(0);
97
89
 
98
90
  for (int qo = get_local_id(0); qo < n_qubits; qo += n_threads) {
99
91
  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
+ float diff = probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, t, n_qubits);
101
93
  diff -= probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, tm1, n_qubits);
102
- AtomicAdd_g_f(&(hamming_prob[_qo]), diff);
94
+ atomic_add_float(&(hamming_prob[_qo]), diff);
103
95
  }
104
96
  }
105
97
 
@@ -112,8 +104,8 @@ inline uint xorshift32(uint *state) {
112
104
  return x;
113
105
  }
114
106
 
115
- float bootstrap_worker(__constant char* theta, __global double* G_m, __constant int* indices, const int k, const int n) {
116
- double energy = 0.0;
107
+ float bootstrap_worker(__constant char* theta, __global float* G_m, __constant int* indices, const int k, const int n) {
108
+ float energy = 0.0;
117
109
  const size_t n_st = (size_t)n;
118
110
  for (int u = 0; u < n; ++u) {
119
111
  const size_t u_offset = u * n_st;
@@ -125,7 +117,7 @@ float bootstrap_worker(__constant char* theta, __global double* G_m, __constant
125
117
  }
126
118
  }
127
119
  for (int v = u + 1; v < n; ++v) {
128
- const double val = G_m[u_offset + v];
120
+ const float val = G_m[u_offset + v];
129
121
  bool v_bit = theta[v];
130
122
  for (int x = 0; x < k; ++x) {
131
123
  if (indices[x] == v) {
@@ -137,14 +129,12 @@ float bootstrap_worker(__constant char* theta, __global double* G_m, __constant
137
129
  }
138
130
  }
139
131
 
140
- return (float)energy;
132
+ return energy;
141
133
  }
142
134
 
143
- #define EPSILON 1.1920928955078125e-7
144
-
145
135
  __kernel void bootstrap(
146
136
  uint prng_seed,
147
- __global double* G_m,
137
+ __global float* G_m,
148
138
  __constant char* best_theta,
149
139
  __constant int* indices_array,
150
140
  __constant int* args, // args[0] = n, args[1] = k
@@ -185,7 +175,7 @@ __kernel void bootstrap(
185
175
  if (hid_energy < lid_energy) {
186
176
  loc_energy[lt_id] = hid_energy;
187
177
  loc_index[lt_id] = loc_index[lt_id + offset];
188
- } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
178
+ } else if (((hid_energy - lid_energy) <= FLT_EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
189
179
  loc_index[lt_id] = loc_index[lt_id + offset];
190
180
  }
191
181
  }
@@ -198,8 +188,8 @@ __kernel void bootstrap(
198
188
  }
199
189
  }
200
190
 
201
- float bootstrap_worker_sparse(__constant char* theta, __global double* G_data, __global unsigned* G_rows, __global unsigned* G_cols, __constant int* indices, const int k, const int n) {
202
- double energy = 0.0;
191
+ float bootstrap_worker_sparse(__constant char* theta, __global float* G_data, __global unsigned* G_rows, __global unsigned* G_cols, __constant int* indices, const int k, const int n) {
192
+ float energy = 0.0f;
203
193
  for (int u = 0; u < n; ++u) {
204
194
  bool u_bit = theta[u];
205
195
  for (int x = 0; x < k; ++x) {
@@ -211,7 +201,7 @@ float bootstrap_worker_sparse(__constant char* theta, __global double* G_data, _
211
201
  const size_t mCol = G_rows[u + 1];
212
202
  for (int col = G_rows[u]; col < mCol; ++col) {
213
203
  const int v = G_cols[col];
214
- const double val = G_data[col];
204
+ const float val = G_data[col];
215
205
  bool v_bit = theta[v];
216
206
  for (int x = 0; x < k; ++x) {
217
207
  if (indices[x] == v) {
@@ -223,12 +213,12 @@ float bootstrap_worker_sparse(__constant char* theta, __global double* G_data, _
223
213
  }
224
214
  }
225
215
 
226
- return (float)energy;
216
+ return energy;
227
217
  }
228
218
 
229
219
  __kernel void bootstrap_sparse(
230
220
  uint prng_seed,
231
- __global double* G_data,
221
+ __global float* G_data,
232
222
  __global unsigned* G_rows,
233
223
  __global unsigned* G_cols,
234
224
  __constant char* best_theta,
@@ -270,7 +260,7 @@ __kernel void bootstrap_sparse(
270
260
  if (hid_energy < lid_energy) {
271
261
  loc_energy[lt_id] = hid_energy;
272
262
  loc_index[lt_id] = loc_index[lt_id + offset];
273
- } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
263
+ } else if (((hid_energy - lid_energy) <= FLT_EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
274
264
  loc_index[lt_id] = loc_index[lt_id + offset];
275
265
  }
276
266
  }
@@ -290,8 +280,8 @@ inline float rand_uniform(uint *state) {
290
280
  }
291
281
 
292
282
  // Compute cut value from bitset solution
293
- double compute_cut_bitset(__global const double* G_m, const uint* sol_bits, int n) {
294
- double cut_val = 0.0;
283
+ float compute_cut_bitset(__global const float* G_m, const uint* sol_bits, int n) {
284
+ float cut_val = 0.0f;
295
285
  for (int u = 0; u < n; u++) {
296
286
  int u_word = u >> 5; // divide by 32
297
287
  int u_bit = u & 31;
@@ -307,6 +297,7 @@ double compute_cut_bitset(__global const double* G_m, const uint* sol_bits, int
307
297
  }
308
298
  }
309
299
  }
300
+
310
301
  return cut_val;
311
302
  }
312
303
 
@@ -314,11 +305,11 @@ double compute_cut_bitset(__global const double* G_m, const uint* sol_bits, int
314
305
  #define MAX_WORDS_MASK 4095
315
306
 
316
307
  __kernel void sample_for_solution_best_bitset(
317
- __global const double* G_m,
308
+ __global const float* G_m,
318
309
  __global const float* thresholds,
319
310
  const int n,
320
311
  const int shots,
321
- const double max_weight,
312
+ const float max_weight,
322
313
  __global float* rng_seeds,
323
314
  __global uint* best_solutions, // [num_groups × ceil(n/32)]
324
315
  __global float* best_energies, // [num_groups]
@@ -339,7 +330,7 @@ __kernel void sample_for_solution_best_bitset(
339
330
  for (int w = 0; w < words; w++) sol_bits[w] = 0;
340
331
  uint temp_sol[MAX_WORDS];
341
332
 
342
- double cut_val = -INFINITY;
333
+ float cut_val = -INFINITY;
343
334
  for (int gid = gid_orig; gid < shots; gid += MAX_PROC_ELEM) {
344
335
 
345
336
  // --- 1. Choose Hamming weight
@@ -353,7 +344,7 @@ __kernel void sample_for_solution_best_bitset(
353
344
  temp_sol[(gid >> 5) & MAX_WORDS_MASK] |= 1U << (gid & 31);
354
345
 
355
346
  for (int count = 1; count < m; ++count) {
356
- double highest_weights[TOP_N];
347
+ float highest_weights[TOP_N];
357
348
  int best_bits[TOP_N];
358
349
  for (int x = 0; x < TOP_N; ++x) {
359
350
  highest_weights[x] = -INFINITY;
@@ -371,7 +362,7 @@ __kernel void sample_for_solution_best_bitset(
371
362
  }
372
363
  const int u_offset = u * n;
373
364
 
374
- double weight = 1.0;
365
+ float weight = 1.0f;
375
366
  for (int k = 0; k < n; k += 32) {
376
367
  for (int l = 0; l < 32; ++l) {
377
368
  const int v = k + l;
@@ -379,16 +370,16 @@ __kernel void sample_for_solution_best_bitset(
379
370
  break;
380
371
  }
381
372
  if ((temp_sol[k >> 5] >> l) & 1) {
382
- weight *= max(EPSILON, 1.0 - G_m[u_offset + v] / max_weight);
373
+ weight *= max(FLT_EPSILON, 1.0f - G_m[u_offset + v] / max_weight);
383
374
  }
384
375
  }
385
376
  }
386
377
 
387
378
  int lowest_option = 0;
388
- double lowest_weight = highest_weights[0];
379
+ float lowest_weight = highest_weights[0];
389
380
  if (lowest_weight != -INFINITY) {
390
381
  for (int x = 0; x < TOP_N; ++x) {
391
- double val = highest_weights[x];
382
+ float val = highest_weights[x];
392
383
  if (val < lowest_weight) {
393
384
  lowest_option = x;
394
385
  lowest_weight = highest_weights[x];
@@ -406,9 +397,9 @@ __kernel void sample_for_solution_best_bitset(
406
397
  }
407
398
  }
408
399
 
409
- double total_weight = 0.0;
400
+ float total_weight = 0.0f;
410
401
  for (int x = 0; x < TOP_N; ++x) {
411
- const double val = highest_weights[x];
402
+ const float val = highest_weights[x];
412
403
  if (val == -INFINITY) {
413
404
  continue;
414
405
  }
@@ -416,10 +407,10 @@ __kernel void sample_for_solution_best_bitset(
416
407
  }
417
408
 
418
409
  const float bit_prob = rand_uniform(&state);
419
- double tot_prob = 0.0;
410
+ float tot_prob = 0.0f;
420
411
  int best_bit = 0;
421
412
  for (int x = 0; x < TOP_N; ++x) {
422
- const double val = highest_weights[x];
413
+ const float val = highest_weights[x];
423
414
  if (val == -INFINITY) {
424
415
  continue;
425
416
  }
@@ -436,7 +427,7 @@ __kernel void sample_for_solution_best_bitset(
436
427
  }
437
428
 
438
429
  // --- 3. Compute cut value
439
- double temp_cut = compute_cut_bitset(G_m, temp_sol, n);
430
+ float temp_cut = compute_cut_bitset(G_m, temp_sol, n);
440
431
  if (temp_cut > cut_val) {
441
432
  cut_val = temp_cut;
442
433
  for (int i = 0; i < words; ++i) {
@@ -474,8 +465,8 @@ __kernel void sample_for_solution_best_bitset(
474
465
  }
475
466
 
476
467
  // Compute cut value from bitset solution
477
- double compute_cut_bitset_sparse(__global const double* G_data, __global const unsigned* G_rows, __global const unsigned* G_cols, const uint* sol_bits, int n) {
478
- double cut_val = 0.0;
468
+ float compute_cut_bitset_sparse(__global const float* G_data, __global const unsigned* G_rows, __global const unsigned* G_cols, const uint* sol_bits, int n) {
469
+ float cut_val = 0.0f;
479
470
  for (unsigned u = 0; u < n; u++) {
480
471
  int u_word = u >> 5; // divide by 32
481
472
  int u_bit = u & 31;
@@ -493,6 +484,7 @@ double compute_cut_bitset_sparse(__global const double* G_data, __global const u
493
484
  }
494
485
  }
495
486
  }
487
+
496
488
  return cut_val;
497
489
  }
498
490
 
@@ -518,13 +510,13 @@ int binary_search(__global const unsigned* l, const unsigned t, const unsigned l
518
510
  }
519
511
 
520
512
  __kernel void sample_for_solution_best_bitset_sparse(
521
- __global const double* G_data,
513
+ __global const float* G_data,
522
514
  __global const unsigned* G_rows,
523
515
  __global const unsigned* G_cols,
524
516
  __global const float* thresholds,
525
517
  const int n,
526
518
  const int shots,
527
- const double max_weight,
519
+ const float max_weight,
528
520
  __global float* rng_seeds,
529
521
  __global uint* best_solutions, // [num_groups × ceil(n/32)]
530
522
  __global float* best_energies, // [num_groups]
@@ -545,7 +537,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
545
537
  for (int w = 0; w < words; w++) sol_bits[w] = 0;
546
538
  uint temp_sol[MAX_WORDS];
547
539
 
548
- double cut_val = -INFINITY;
540
+ float cut_val = -INFINITY;
549
541
  for (int gid = gid_orig; gid < shots; gid += MAX_PROC_ELEM) {
550
542
 
551
543
  // --- 1. Choose Hamming weight
@@ -559,7 +551,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
559
551
  temp_sol[(gid >> 5) & MAX_WORDS_MASK] |= 1U << (gid & 31);
560
552
 
561
553
  for (int count = 1; count < m; ++count) {
562
- double highest_weights[TOP_N];
554
+ float highest_weights[TOP_N];
563
555
  int best_bits[TOP_N];
564
556
  for (int x = 0; x < TOP_N; ++x) {
565
557
  highest_weights[x] = -INFINITY;
@@ -576,14 +568,14 @@ __kernel void sample_for_solution_best_bitset_sparse(
576
568
  continue;
577
569
  }
578
570
 
579
- double weight = 1.0;
571
+ float weight = 1.0f;
580
572
 
581
573
  unsigned max_col = G_rows[u + 1];
582
574
  for (int col = G_rows[u]; col < max_col; ++col) {
583
575
  const int v = G_cols[col];
584
576
 
585
577
  if ((temp_sol[v >> 5] >> (v & 31)) & 1) {
586
- weight *= max(EPSILON, 1.0 - G_data[col] / max_weight);
578
+ weight *= max(FLT_EPSILON, 1.0f - G_data[col] / max_weight);
587
579
  }
588
580
  }
589
581
 
@@ -595,15 +587,15 @@ __kernel void sample_for_solution_best_bitset_sparse(
595
587
  int end = G_rows[v + 1];
596
588
  int j = binary_search(&(G_cols[start]), u, end - start) + start;
597
589
  if (j < end) {
598
- weight *= max(EPSILON, 1.0 - G_data[j] / max_weight);
590
+ weight *= max(FLT_EPSILON, 1.0f - G_data[j] / max_weight);
599
591
  }
600
592
  }
601
593
 
602
594
  int lowest_option = 0;
603
- double lowest_weight = highest_weights[0];
595
+ float lowest_weight = highest_weights[0];
604
596
  if (lowest_weight != -INFINITY) {
605
597
  for (int x = 0; x < TOP_N; ++x) {
606
- double val = highest_weights[x];
598
+ float val = highest_weights[x];
607
599
  if (val < lowest_weight) {
608
600
  lowest_option = x;
609
601
  lowest_weight = highest_weights[x];
@@ -621,9 +613,9 @@ __kernel void sample_for_solution_best_bitset_sparse(
621
613
  }
622
614
  }
623
615
 
624
- double total_weight = 0.0;
616
+ float total_weight = 0.0f;
625
617
  for (int x = 0; x < TOP_N; ++x) {
626
- const double val = highest_weights[x];
618
+ const float val = highest_weights[x];
627
619
  if (val == -INFINITY) {
628
620
  continue;
629
621
  }
@@ -631,10 +623,10 @@ __kernel void sample_for_solution_best_bitset_sparse(
631
623
  }
632
624
 
633
625
  const float bit_prob = rand_uniform(&state);
634
- double tot_prob = 0.0;
626
+ float tot_prob = 0.0f;
635
627
  int best_bit = 0;
636
628
  for (int x = 0; x < TOP_N; ++x) {
637
- const double val = highest_weights[x];
629
+ const float val = highest_weights[x];
638
630
  if (val == -INFINITY) {
639
631
  continue;
640
632
  }
@@ -651,7 +643,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
651
643
  }
652
644
 
653
645
  // --- 3. Compute cut value
654
- double temp_cut = compute_cut_bitset_sparse(G_data, G_rows, G_cols, temp_sol, n);
646
+ float temp_cut = compute_cut_bitset_sparse(G_data, G_rows, G_cols, temp_sol, n);
655
647
  if (temp_cut > cut_val) {
656
648
  cut_val = temp_cut;
657
649
  for (int i = 0; i < words; ++i) {
@@ -33,7 +33,7 @@ def local_repulsion_choice(G_m, max_weight, weights, n, m, shot):
33
33
  - High-degree nodes are already less likely
34
34
  - After choosing a node, its neighbors' probabilities are further reduced
35
35
  adjacency_data, adjacency_rows: CSR-format sparse adjacency data
36
- weights: float64 array of shape (n,)
36
+ weights: float32 array of shape (n,)
37
37
  """
38
38
 
39
39
  weights = weights.copy()
@@ -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.float64)
123
+ J_eff = np.empty(n_qubits, dtype=np.float32)
124
124
  J_max = -float("inf")
125
125
  for n in prange(n_qubits):
126
126
  degree = sum(G_m[n] != 0.0)
@@ -175,7 +175,7 @@ def run_sampling_opencl(G_m_np, thresholds_np, shots, n, is_g_buf_reused):
175
175
  thresholds_buf,
176
176
  np.int32(n),
177
177
  np.int32(shots),
178
- np.float64(G_m_np.max()),
178
+ np.float32(G_m_np.max()),
179
179
  rng_buf,
180
180
  solutions_buf,
181
181
  best_energies_buf,
@@ -252,7 +252,7 @@ def maxcut_tfim(
252
252
  if isinstance(G, nx.Graph):
253
253
  nodes = list(G.nodes())
254
254
  n_qubits = len(nodes)
255
- G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0)
255
+ G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0, dtype=np.float32)
256
256
  else:
257
257
  n_qubits = len(G)
258
258
  nodes = list(range(n_qubits))
@@ -291,7 +291,7 @@ def maxcut_tfim(
291
291
  tot_t = 2.0 * n_steps * delta_t
292
292
  h_mult = 2.0 / tot_t
293
293
 
294
- args = np.empty(3, dtype=np.float64)
294
+ args = np.empty(3, dtype=np.float32)
295
295
  args[0] = delta_t
296
296
  args[1] = tot_t
297
297
  args[2] = h_mult
@@ -301,7 +301,7 @@ def maxcut_tfim(
301
301
  args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
302
302
  J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
303
303
  deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
304
- theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.float64().nbytes))
304
+ theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.float32().nbytes))
305
305
 
306
306
  # Warp size is 32:
307
307
  group_size = min(n_qubits, 64)
@@ -63,7 +63,7 @@ def local_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, m, sh
63
63
  - High-degree nodes are already less likely
64
64
  - After choosing a node, its neighbors' probabilities are further reduced
65
65
  adjacency_data, adjacency_rows: CSR-format sparse adjacency data
66
- weights: float64 array of shape (n,)
66
+ weights: float32 array of shape (n,)
67
67
  """
68
68
 
69
69
  weights = weights.copy()
@@ -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.float64)
155
+ J_eff = np.empty(n_qubits, dtype=np.float32)
156
156
  for r in prange(n_qubits):
157
157
  # Row sum
158
158
  start = G_rows[r]
@@ -226,7 +226,7 @@ def run_sampling_opencl(G_m_csr, thresholds_np, shots, n, is_g_buf_reused):
226
226
  thresholds_buf,
227
227
  np.int32(n),
228
228
  np.int32(shots),
229
- np.float64(G_m_csr.data.max()),
229
+ np.float32(G_m_csr.data.max()),
230
230
  rng_buf,
231
231
  solutions_buf,
232
232
  best_energies_buf,
@@ -292,7 +292,7 @@ def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, weights, hamming_prob, n
292
292
 
293
293
 
294
294
  def to_scipy_sparse_upper_triangular(G, nodes, n_nodes):
295
- lil = lil_matrix((n_nodes, n_nodes), dtype=np.float64)
295
+ lil = lil_matrix((n_nodes, n_nodes), dtype=np.float32)
296
296
  for u in range(n_nodes):
297
297
  u_node = nodes[u]
298
298
  for v in range(u + 1, n_nodes):
@@ -356,7 +356,7 @@ def maxcut_tfim_sparse(
356
356
  tot_t = 2.0 * n_steps * delta_t
357
357
  h_mult = 2.0 / tot_t
358
358
 
359
- args = np.empty(3, dtype=np.float64)
359
+ args = np.empty(3, dtype=np.float32)
360
360
  args[0] = delta_t
361
361
  args[1] = tot_t
362
362
  args[2] = h_mult
@@ -124,8 +124,7 @@ 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
- ENERGY_EPSILON = 2e-23
128
- choices = np.where(abs(min_energy_host - energy) <= ENERGY_EPSILON)[0]
127
+ choices = np.where(np.isclose(min_energy_host, energy, atol=2e-23, rtol=0))[0]
129
128
  best_i = np.random.choice(choices) if len(choices) else np.argmin(min_energy_host)
130
129
 
131
130
  flip_index_start = best_i * k
@@ -152,7 +151,7 @@ def spin_glass_solver(
152
151
  if isinstance(G, nx.Graph):
153
152
  nodes = list(G.nodes())
154
153
  n_qubits = len(nodes)
155
- G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0)
154
+ G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0, dtype=np.float32)
156
155
  else:
157
156
  n_qubits = len(G)
158
157
  nodes = list(range(n_qubits))
@@ -129,8 +129,7 @@ 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
- ENERGY_EPSILON = 2e-23
133
- choices = np.where(abs(min_energy_host - energy) <= ENERGY_EPSILON)[0]
132
+ choices = np.where(np.isclose(min_energy_host, energy, atol=2e-23, rtol=0))[0]
134
133
  best_i = np.random.choice(choices) if len(choices) else np.argmin(min_energy_host)
135
134
 
136
135
  flip_index_start = best_i * k
@@ -143,7 +142,7 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
143
142
 
144
143
 
145
144
  def to_scipy_sparse_upper_triangular(G, nodes, n_nodes):
146
- lil = lil_matrix((n_nodes, n_nodes), dtype=np.float64)
145
+ lil = lil_matrix((n_nodes, n_nodes), dtype=np.float32)
147
146
  for u in range(n_nodes):
148
147
  u_node = nodes[u]
149
148
  for v in range(u + 1, n_nodes):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.4
3
+ Version: 6.0.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.7.4',
54
+ version='6.0.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