PyQrackIsing 7.5.3__tar.gz → 8.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 (31) hide show
  1. {pyqrackising-7.5.3/pyqrackising.egg-info → pyqrackising-8.0.0}/PKG-INFO +1 -1
  2. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyproject.toml +1 -1
  3. pyqrackising-8.0.0/pyqrackising/kernels.cl +417 -0
  4. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/maxcut_tfim.py +11 -91
  5. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/maxcut_tfim_sparse.py +14 -94
  6. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/maxcut_tfim_streaming.py +12 -84
  7. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/maxcut_tfim_util.py +2 -14
  8. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/spin_glass_solver.py +3 -4
  9. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/spin_glass_solver_sparse.py +3 -4
  10. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/spin_glass_solver_streaming.py +6 -4
  11. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/tsp.py +6 -18
  12. {pyqrackising-7.5.3 → pyqrackising-8.0.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  13. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/setup.py +1 -1
  14. pyqrackising-7.5.3/pyqrackising/kernels.cl +0 -946
  15. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/CMakeLists.txt +0 -0
  16. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/LICENSE.md +0 -0
  17. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/MANIFEST.in +0 -0
  18. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/README.md +0 -0
  19. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/__init__.py +0 -0
  20. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  21. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  22. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/generate_tfim_samples.py +0 -0
  23. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  24. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/tfim_magnetization.py +0 -0
  25. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  26. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising/tsp_maxcut.py +0 -0
  27. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  28. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  29. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  30. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/pyqrackising.egg-info/top_level.txt +0 -0
  31. {pyqrackising-7.5.3 → pyqrackising-8.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.5.3
3
+ Version: 8.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
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "7.5.3"
15
+ version = "8.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"}
@@ -0,0 +1,417 @@
1
+ #if FP16
2
+ #define fwrapper(f, a) (half)f((float)(a))
3
+ #define fwrapper2(f, a, b) (half)f((float)(a), (float)(b))
4
+ #else
5
+ #define fwrapper(f, a) f(a)
6
+ #define fwrapper2(f, a, b) f(a, b)
7
+ #endif
8
+
9
+ inline uint xorshift32(uint *state) {
10
+ uint x = *state;
11
+ x ^= x << 13;
12
+ x ^= x >> 17;
13
+ x ^= x << 5;
14
+ *state = x;
15
+ return x;
16
+ }
17
+
18
+ real1 bootstrap_worker(__constant char* theta, __global const real1* G_m, __constant int* indices, const int k, const int n) {
19
+ real1 energy = ZERO_R1;
20
+ const size_t n_st = (size_t)n;
21
+ for (int u = 0; u < n; ++u) {
22
+ const size_t u_offset = u * n_st;
23
+ bool u_bit = theta[u];
24
+ for (int x = 0; x < k; ++x) {
25
+ if (indices[x] == u) {
26
+ u_bit = !u_bit;
27
+ break;
28
+ }
29
+ }
30
+ for (int v = u + 1; v < n; ++v) {
31
+ const real1 val = G_m[u_offset + v];
32
+ bool v_bit = theta[v];
33
+ for (int x = 0; x < k; ++x) {
34
+ if (indices[x] == v) {
35
+ v_bit = !v_bit;
36
+ break;
37
+ }
38
+ }
39
+ energy += (u_bit == v_bit) ? val : -val;
40
+ }
41
+ }
42
+
43
+ return energy;
44
+ }
45
+
46
+ __kernel void bootstrap(
47
+ uint prng_seed,
48
+ __global const real1* G_m,
49
+ __constant char* best_theta,
50
+ __constant int* indices_array,
51
+ __constant int* args, // args[0] = n, args[1] = k
52
+ __global real1* min_energy_ptr, // output: per-group min energy
53
+ __global int* min_index_ptr, // output: per-group best index (i)
54
+ __local real1* loc_energy, // local memory buffer
55
+ __local int* loc_index // local memory buffer
56
+ ) {
57
+ const int n = args[0];
58
+ const int k = args[1];
59
+ const int combo_count = args[2];
60
+ int i = get_global_id(0);
61
+
62
+ // The inputs are chaotic, and this doesn't need to be high-quality, just uniform.
63
+ prng_seed ^= (uint)i;
64
+
65
+ real1 best_energy = INFINITY;
66
+ int best_i = i;
67
+
68
+ for (; i < combo_count; i += MAX_PROC_ELEM) {
69
+ const int j = i * k;
70
+ const real1 energy = bootstrap_worker(best_theta, G_m, indices_array + j, k, n);
71
+ if (energy < best_energy) {
72
+ best_energy = energy;
73
+ best_i = i;
74
+ } else if (((energy - best_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
75
+ best_i = i;
76
+ }
77
+ }
78
+
79
+ const int lt_id = get_local_id(0);
80
+ const int lt_size = get_local_size(0);
81
+
82
+ loc_energy[lt_id] = best_energy;
83
+ loc_index[lt_id] = best_i;
84
+
85
+ // Reduce within workgroup
86
+ for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
87
+ barrier(CLK_LOCAL_MEM_FENCE);
88
+ if (lt_id < offset) {
89
+ real1 hid_energy = loc_energy[lt_id + offset];
90
+ real1 lid_energy = loc_energy[lt_id];
91
+ if (hid_energy < lid_energy) {
92
+ loc_energy[lt_id] = hid_energy;
93
+ loc_index[lt_id] = loc_index[lt_id + offset];
94
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
95
+ loc_index[lt_id] = loc_index[lt_id + offset];
96
+ }
97
+ }
98
+ }
99
+
100
+ // Write out per-group result
101
+ if (lt_id == 0) {
102
+ min_energy_ptr[get_group_id(0)] = loc_energy[0];
103
+ min_index_ptr[get_group_id(0)] = loc_index[0];
104
+ }
105
+ }
106
+
107
+ real1 bootstrap_worker_sparse(__constant char* theta, __global const real1* G_data, __global const uint* G_rows, __global const uint* G_cols, __constant int* indices, const int k, const int n) {
108
+ real1 energy = ZERO_R1;
109
+ for (int u = 0; u < n; ++u) {
110
+ bool u_bit = theta[u];
111
+ for (int x = 0; x < k; ++x) {
112
+ if (indices[x] == u) {
113
+ u_bit = !u_bit;
114
+ break;
115
+ }
116
+ }
117
+ const size_t mCol = G_rows[u + 1];
118
+ for (int col = G_rows[u]; col < mCol; ++col) {
119
+ const int v = G_cols[col];
120
+ const real1 val = G_data[col];
121
+ bool v_bit = theta[v];
122
+ for (int x = 0; x < k; ++x) {
123
+ if (indices[x] == v) {
124
+ v_bit = !v_bit;
125
+ break;
126
+ }
127
+ }
128
+ energy += (u_bit == v_bit) ? val : -val;
129
+ }
130
+ }
131
+
132
+ return energy;
133
+ }
134
+
135
+ __kernel void bootstrap_sparse(
136
+ uint prng_seed,
137
+ __global const real1* G_data,
138
+ __global const uint* G_rows,
139
+ __global const uint* G_cols,
140
+ __constant char* best_theta,
141
+ __constant int* indices_array,
142
+ __constant int* args, // args[0] = n, args[1] = k
143
+ __global real1* min_energy_ptr, // output: per-group min energy
144
+ __global int* min_index_ptr, // output: per-group best index (i)
145
+ __local real1* loc_energy, // local memory buffer
146
+ __local int* loc_index // local memory buffer
147
+ ) {
148
+ const int n = args[0];
149
+ const int k = args[1];
150
+ const int combo_count = args[2];
151
+ int i = get_global_id(0);
152
+
153
+ prng_seed ^= (uint)i;
154
+
155
+ real1 best_energy = INFINITY;
156
+ int best_i = i;
157
+
158
+ for (; i < combo_count; i += MAX_PROC_ELEM) {
159
+ const int j = i * k;
160
+ const real1 energy = bootstrap_worker_sparse(best_theta, G_data, G_rows, G_cols, indices_array + j, k, n);
161
+ if (energy < best_energy) {
162
+ best_energy = energy;
163
+ best_i = i;
164
+ } else if (((energy - best_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
165
+ best_i = i;
166
+ }
167
+ }
168
+
169
+ const int lt_id = get_local_id(0);
170
+ const int lt_size = get_local_size(0);
171
+
172
+ loc_energy[lt_id] = best_energy;
173
+ loc_index[lt_id] = best_i;
174
+
175
+ // Reduce within workgroup
176
+ for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
177
+ barrier(CLK_LOCAL_MEM_FENCE);
178
+ if (lt_id < offset) {
179
+ real1 hid_energy = loc_energy[lt_id + offset];
180
+ real1 lid_energy = loc_energy[lt_id];
181
+ if (hid_energy < lid_energy) {
182
+ loc_energy[lt_id] = hid_energy;
183
+ loc_index[lt_id] = loc_index[lt_id + offset];
184
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
185
+ loc_index[lt_id] = loc_index[lt_id + offset];
186
+ }
187
+ }
188
+ }
189
+
190
+ // Write out per-group result
191
+ if (lt_id == 0) {
192
+ min_energy_ptr[get_group_id(0)] = loc_energy[0];
193
+ min_index_ptr[get_group_id(0)] = loc_index[0];
194
+ }
195
+ }
196
+
197
+ // Helper to read from segmented G_m
198
+ inline real1 get_G_m(
199
+ __global const real1** G_m,
200
+ size_t flat_idx,
201
+ int segment_size
202
+ ) {
203
+ return G_m[flat_idx / segment_size][flat_idx % segment_size];
204
+ }
205
+
206
+ real1 bootstrap_worker_segmented(
207
+ __constant char* theta,
208
+ __global const real1** G_m,
209
+ __constant int* indices,
210
+ const int k,
211
+ const int n,
212
+ const int segment_size
213
+ ) {
214
+ real1 energy = ZERO_R1;
215
+ const size_t n_st = (size_t)n;
216
+
217
+ for (int u = 0; u < n; ++u) {
218
+ const size_t u_offset = u * n_st;
219
+ bool u_bit = theta[u];
220
+ for (int x = 0; x < k; ++x) {
221
+ if (indices[x] == u) {
222
+ u_bit = !u_bit;
223
+ break;
224
+ }
225
+ }
226
+ for (int v = u + 1; v < n; ++v) {
227
+ size_t flat_idx = u_offset + v;
228
+ real1 val = get_G_m(G_m, flat_idx, segment_size);
229
+
230
+ bool v_bit = theta[v];
231
+ for (int x = 0; x < k; ++x) {
232
+ if (indices[x] == v) {
233
+ v_bit = !v_bit;
234
+ break;
235
+ }
236
+ }
237
+ energy += (u_bit == v_bit) ? val : -val;
238
+ }
239
+ }
240
+
241
+ return energy;
242
+ }
243
+
244
+
245
+ __kernel void bootstrap_segmented(
246
+ uint prng_seed,
247
+ __global const real1* G_m0,
248
+ __global const real1* G_m1,
249
+ __global const real1* G_m2,
250
+ __global const real1* G_m3,
251
+ __constant char* best_theta,
252
+ __constant int* indices_array,
253
+ __constant int* args, // args[0]=n, args[1]=k, args[2]=combo_count, args[3]=segment_size
254
+ __global real1* min_energy_ptr,
255
+ __global int* min_index_ptr,
256
+ __local real1* loc_energy,
257
+ __local int* loc_index
258
+ ) {
259
+ __global const real1* G_m[4] = { G_m0, G_m1, G_m2, G_m3 };
260
+
261
+ const int n = args[0];
262
+ const int k = args[1];
263
+ const int combo_count = args[2];
264
+ const int segment_size = args[3];
265
+ int i = get_global_id(0);
266
+
267
+ prng_seed ^= (uint)i;
268
+
269
+ real1 best_energy = INFINITY;
270
+ int best_i = i;
271
+
272
+ for (; i < combo_count; i += MAX_PROC_ELEM) {
273
+ const int j = i * k;
274
+ const real1 energy = bootstrap_worker_segmented(best_theta, G_m, indices_array + j, k, n, segment_size);
275
+ if (energy < best_energy) {
276
+ best_energy = energy;
277
+ best_i = i;
278
+ } else if (((energy - best_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
279
+ best_i = i;
280
+ }
281
+ }
282
+
283
+ const int lt_id = get_local_id(0);
284
+ const int lt_size = get_local_size(0);
285
+
286
+ loc_energy[lt_id] = best_energy;
287
+ loc_index[lt_id] = best_i;
288
+
289
+ for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
290
+ barrier(CLK_LOCAL_MEM_FENCE);
291
+ if (lt_id < offset) {
292
+ real1 hid_energy = loc_energy[lt_id + offset];
293
+ real1 lid_energy = loc_energy[lt_id];
294
+ if (hid_energy < lid_energy) {
295
+ loc_energy[lt_id] = hid_energy;
296
+ loc_index[lt_id] = loc_index[lt_id + offset];
297
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
298
+ loc_index[lt_id] = loc_index[lt_id + offset];
299
+ }
300
+ }
301
+ }
302
+
303
+ if (lt_id == 0) {
304
+ min_energy_ptr[get_group_id(0)] = loc_energy[0];
305
+ min_index_ptr[get_group_id(0)] = loc_index[0];
306
+ }
307
+ }
308
+
309
+ real1 bootstrap_worker_sparse_segmented(
310
+ __constant char* theta,
311
+ __global const real1** G_data,
312
+ __global const uint* G_rows,
313
+ __global const uint* G_cols,
314
+ __constant int* indices,
315
+ const int k,
316
+ const int n,
317
+ const int segment_size
318
+ ) {
319
+ real1 energy = ZERO_R1;
320
+
321
+ for (int u = 0; u < n; ++u) {
322
+ bool u_bit = theta[u];
323
+ for (int x = 0; x < k; ++x) {
324
+ if (indices[x] == u) {
325
+ u_bit = !u_bit;
326
+ break;
327
+ }
328
+ }
329
+
330
+ const uint row_start = G_rows[u];
331
+ const uint row_end = G_rows[u + 1];
332
+
333
+ for (uint col = row_start; col < row_end; ++col) {
334
+ const int v = G_cols[col];
335
+ real1 val = get_G_m(G_data, col, segment_size);
336
+
337
+ bool v_bit = theta[v];
338
+ for (int x = 0; x < k; ++x) {
339
+ if (indices[x] == v) {
340
+ v_bit = !v_bit;
341
+ break;
342
+ }
343
+ }
344
+
345
+ energy += (u_bit == v_bit) ? val : -val;
346
+ }
347
+ }
348
+
349
+ return energy;
350
+ }
351
+
352
+ __kernel void bootstrap_sparse_segmented(
353
+ uint prng_seed,
354
+ __global const real1* G_data0,
355
+ __global const real1* G_data1,
356
+ __global const real1* G_data2,
357
+ __global const real1* G_data3,
358
+ __global const uint* G_rows,
359
+ __global const uint* G_cols,
360
+ __constant char* best_theta,
361
+ __constant int* indices_array,
362
+ __constant int* args, // args[0] = n, args[1] = k, args[2] = combo_count, args[3] = segment_size
363
+ __global real1* min_energy_ptr,
364
+ __global int* min_index_ptr,
365
+ __local real1* loc_energy,
366
+ __local int* loc_index
367
+ ) {
368
+ __global const real1* G_data[4] = { G_data0, G_data1, G_data2, G_data3 };
369
+
370
+ const int n = args[0];
371
+ const int k = args[1];
372
+ const int combo_count = args[2];
373
+ const int segment_size = args[3];
374
+ int i = get_global_id(0);
375
+
376
+ prng_seed ^= (uint)i;
377
+
378
+ real1 best_energy = INFINITY;
379
+ int best_i = i;
380
+
381
+ for (; i < combo_count; i += MAX_PROC_ELEM) {
382
+ const int j = i * k;
383
+ const real1 energy = bootstrap_worker_sparse_segmented(best_theta, G_data, G_rows, G_cols, indices_array + j, k, n, segment_size);
384
+ if (energy < best_energy) {
385
+ best_energy = energy;
386
+ best_i = i;
387
+ } else if (((energy - best_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
388
+ best_i = i;
389
+ }
390
+ }
391
+
392
+ const int lt_id = get_local_id(0);
393
+ const int lt_size = get_local_size(0);
394
+
395
+ loc_energy[lt_id] = best_energy;
396
+ loc_index[lt_id] = best_i;
397
+
398
+ for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
399
+ barrier(CLK_LOCAL_MEM_FENCE);
400
+ if (lt_id < offset) {
401
+ real1 hid_energy = loc_energy[lt_id + offset];
402
+ real1 lid_energy = loc_energy[lt_id];
403
+ if (hid_energy < lid_energy) {
404
+ loc_energy[lt_id] = hid_energy;
405
+ loc_index[lt_id] = loc_index[lt_id + offset];
406
+ } else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
407
+ loc_index[lt_id] = loc_index[lt_id + offset];
408
+ }
409
+ }
410
+ }
411
+
412
+ if (lt_id == 0) {
413
+ min_energy_ptr[get_group_id(0)] = loc_energy[0];
414
+ min_index_ptr[get_group_id(0)] = loc_index[0];
415
+ }
416
+ }
417
+
@@ -4,7 +4,7 @@ import numpy as np
4
4
  import os
5
5
  from numba import njit, prange
6
6
 
7
- from .maxcut_tfim_util import fix_cdf, get_cut, init_thresholds, maxcut_hamming_cdf, opencl_context
7
+ from .maxcut_tfim_util import fix_cdf, get_cut, init_theta, init_thresholds, maxcut_hamming_cdf, opencl_context
8
8
 
9
9
  IS_OPENCL_AVAILABLE = True
10
10
  try:
@@ -13,6 +13,9 @@ except ImportError:
13
13
  IS_OPENCL_AVAILABLE = False
14
14
 
15
15
 
16
+ epsilon = opencl_context.epsilon
17
+
18
+
16
19
  @njit
17
20
  def update_repulsion_choice(G_m, max_edge, weights, n, used, node):
18
21
  # Select node
@@ -22,7 +25,7 @@ def update_repulsion_choice(G_m, max_edge, weights, n, used, node):
22
25
  for nbr in range(n):
23
26
  if used[nbr]:
24
27
  continue
25
- weights[nbr] *= max(1.1920928955078125e-7, 1 - G_m[node, nbr] / max_edge)
28
+ weights[nbr] *= max(epsilon, 1 - G_m[node, nbr] / max_edge)
26
29
 
27
30
 
28
31
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -49,11 +52,12 @@ def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m):
49
52
  node = i
50
53
  break
51
54
 
52
- update_repulsion_choice(G_m, max_edge, weights, n, used, node)
53
-
54
55
  if m == 1:
56
+ used[node] = True
55
57
  return used
56
58
 
59
+ update_repulsion_choice(G_m, max_edge, weights, n, used, node)
60
+
57
61
  for _ in range(1, m - 1):
58
62
  # Count available
59
63
  total_w = 0.0
@@ -262,7 +266,7 @@ def run_sampling_opencl(G_m_np, thresholds_np, shots, n, is_g_buf_reused):
262
266
 
263
267
 
264
268
  @njit
265
- def cpu_footer(shots, quality, n_qubits, G_m, nodes, dtype, epsilon):
269
+ def cpu_footer(shots, quality, n_qubits, G_m, nodes, dtype):
266
270
  J_eff, degrees = init_J_and_z(G_m, dtype)
267
271
  hamming_prob = init_thresholds(n_qubits, dtype)
268
272
 
@@ -278,27 +282,12 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, dtype, epsilon):
278
282
  return bit_string, best_value, (l, r)
279
283
 
280
284
 
281
- @njit
282
- def gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes, dtype):
283
- fix_cdf(hamming_prob)
284
-
285
- best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights, dtype)
286
-
287
- bit_string, l, r = get_cut(best_solution, nodes)
288
-
289
- return bit_string, best_value, (l, r)
290
-
291
-
292
285
  def maxcut_tfim(
293
286
  G,
294
287
  quality=None,
295
- shots=None,
296
- is_alt_gpu_sampling=False,
297
- is_g_buf_reused=False,
298
- is_base_maxcut_gpu=True
288
+ shots=None
299
289
  ):
300
290
  dtype = opencl_context.dtype
301
- epsilon = opencl_context.epsilon
302
291
  wgs = opencl_context.work_group_size
303
292
  nodes = None
304
293
  n_qubits = 0
@@ -341,73 +330,4 @@ def maxcut_tfim(
341
330
  n_steps = n_qubits << quality
342
331
  grid_size = n_steps * n_qubits
343
332
 
344
- if (not is_base_maxcut_gpu) or (not IS_OPENCL_AVAILABLE):
345
- return cpu_footer(shots, quality, n_qubits, G_m, nodes, dtype, epsilon)
346
-
347
- J_eff, degrees = init_J_and_z(G_m, dtype)
348
-
349
- delta_t = 1.0 / n_steps
350
- tot_t = 2.0 * n_steps * delta_t
351
- h_mult = 2.0 / tot_t
352
-
353
- args = np.empty(3, dtype=dtype)
354
- args[0] = delta_t
355
- args[1] = tot_t
356
- args[2] = h_mult
357
-
358
- # Move to GPU
359
- mf = cl.mem_flags
360
- args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
361
- J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
362
- deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
363
- theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * dtype().nbytes))
364
-
365
- # Warp size is 32:
366
- group_size = min(wgs, n_qubits)
367
- global_size = ((n_qubits + group_size - 1) // group_size) * group_size
368
-
369
- opencl_context.init_theta_kernel(
370
- opencl_context.queue, (global_size,), (group_size,),
371
- args_buf, np.int32(n_qubits), J_buf, deg_buf, theta_buf
372
- )
373
-
374
- hamming_prob = init_thresholds(n_qubits, dtype)
375
-
376
- # Warp size is 32:
377
- group_size = min(wgs, n_qubits - 1)
378
- grid_dim = n_steps * n_qubits * group_size
379
-
380
- # Move to GPU
381
- ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
382
-
383
- # Kernel execution
384
- opencl_context.maxcut_hamming_cdf_kernel(
385
- opencl_context.queue, (grid_dim,), (group_size,),
386
- np.int32(n_qubits), deg_buf, args_buf, J_buf, theta_buf, ham_buf
387
- )
388
-
389
- # Fetch results
390
- cl.enqueue_copy(opencl_context.queue, hamming_prob, ham_buf)
391
- opencl_context.queue.finish()
392
-
393
- args_buf.release()
394
- J_buf.release()
395
- deg_buf.release()
396
- theta_buf.release()
397
-
398
- args_buf = None
399
- J_buf = None
400
- deg_buf = None
401
- theta_buf = None
402
-
403
- if not is_alt_gpu_sampling:
404
- degrees = None
405
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
406
-
407
- return gpu_footer(shots, n_qubits, G_m, J_eff, hamming_prob, nodes, dtype)
408
-
409
- fix_cdf(hamming_prob)
410
- best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
411
- bit_string, l, r = get_cut(best_solution, nodes)
412
-
413
- return bit_string, best_value, (l, r)
333
+ return cpu_footer(shots, quality, n_qubits, G_m, nodes, dtype)