PyQrackIsing 8.14.1__tar.gz → 8.14.2__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.1/pyqrackising.egg-info → pyqrackising-8.14.2}/PKG-INFO +1 -1
  2. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyproject.toml +1 -1
  3. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/kernels.cl +21 -11
  4. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/maxcut_tfim.py +10 -21
  5. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/maxcut_tfim_sparse.py +9 -5
  6. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/maxcut_tfim_util.py +33 -0
  7. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/spin_glass_solver.py +1 -0
  8. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/spin_glass_solver_sparse.py +1 -0
  9. {pyqrackising-8.14.1 → pyqrackising-8.14.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  10. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/setup.py +1 -1
  11. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/LICENSE.md +0 -0
  12. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/MANIFEST.in +0 -0
  13. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/README.md +0 -0
  14. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/__init__.py +0 -0
  15. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  16. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/generate_tfim_samples.py +0 -0
  17. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  19. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/spin_glass_solver_util.py +0 -0
  20. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.14.1 → pyqrackising-8.14.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.1
3
+ Version: 8.14.2
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.1"
13
+ version = "8.14.2"
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"}
@@ -438,11 +438,11 @@ __kernel void bootstrap_sparse_segmented(
438
438
  }
439
439
  }
440
440
 
441
- inline bool get_bit(__global uint* theta, const size_t u) {
441
+ inline bool get_bit(__global const uint* theta, const size_t u) {
442
442
  return (theta[u >> 5U] >> (u & 31U)) & 1U;
443
443
  }
444
444
 
445
- real1 cut_worker(__global uint* theta, __global const real1* G_m, const int n, const bool is_spin_glass) {
445
+ real1 cut_worker(__global const uint* theta, __global const real1* G_m, const int n, const bool is_spin_glass) {
446
446
  real1 energy = ZERO_R1;
447
447
  const size_t n_st = (size_t)n;
448
448
  for (int u = 0; u < n; ++u) {
@@ -464,7 +464,7 @@ real1 cut_worker(__global uint* theta, __global const real1* G_m, const int n, c
464
464
 
465
465
  __kernel void calculate_cut(
466
466
  __global const real1* G_m,
467
- __global uint* theta,
467
+ __global const uint* theta,
468
468
  __constant int* args, // args[0] = n, args[1] = k
469
469
  __global real1* max_energy_ptr, // output: per-group min energy
470
470
  __global int* max_index_ptr, // output: per-group best index (i)
@@ -515,7 +515,7 @@ __kernel void calculate_cut(
515
515
  }
516
516
  }
517
517
 
518
- real1 cut_worker_sparse(__global uint* theta, __global const real1* G_data, __global const uint* G_rows, __global const uint* G_cols, const int n, const bool is_spin_glass) {
518
+ real1 cut_worker_sparse(__global const uint* theta, __global const real1* G_data, __global const uint* G_rows, __global const uint* G_cols, const int n, const bool is_spin_glass) {
519
519
  real1 energy = ZERO_R1;
520
520
  for (int u = 0; u < n; ++u) {
521
521
  const bool u_bit = get_bit(theta, u);
@@ -539,7 +539,7 @@ __kernel void calculate_cut_sparse(
539
539
  __global const real1* G_data,
540
540
  __global const uint* G_rows,
541
541
  __global const uint* G_cols,
542
- __global uint* theta,
542
+ __global const uint* theta,
543
543
  __constant int* args, // args[0] = n, args[1] = k
544
544
  __global real1* max_energy_ptr, // output: per-group min energy
545
545
  __global int* max_index_ptr, // output: per-group best index (i)
@@ -590,7 +590,7 @@ __kernel void calculate_cut_sparse(
590
590
  }
591
591
 
592
592
  real1 cut_worker_segmented(
593
- __global uint* theta,
593
+ __global const uint* theta,
594
594
  __global const real1** G_m,
595
595
  const int n,
596
596
  const int segment_size,
@@ -623,7 +623,10 @@ __kernel void calculate_cut_segmented(
623
623
  __global const real1* G_m1,
624
624
  __global const real1* G_m2,
625
625
  __global const real1* G_m3,
626
- __global uint* theta,
626
+ __global const uint* theta0,
627
+ __global const uint* theta1,
628
+ __global const uint* theta2,
629
+ __global const uint* theta3,
627
630
  __constant int* args, // args[0]=n, args[1]=k, args[2]=combo_count, args[3]=segment_size
628
631
  __global real1* max_energy_ptr,
629
632
  __global int* max_index_ptr,
@@ -631,11 +634,13 @@ __kernel void calculate_cut_segmented(
631
634
  __local int* loc_index
632
635
  ) {
633
636
  __global const real1* G_m[4] = { G_m0, G_m1, G_m2, G_m3 };
637
+ __global const uint* theta[4] = { theta0, theta1, theta2, theta3 };
634
638
 
635
639
  const int n = args[0];
636
640
  const int shots = args[1];
637
641
  const bool is_spin_glass = args[2];
638
642
  const int segment_size = args[3];
643
+ const int theta_segment_size = args[4];
639
644
  int i = get_global_id(0);
640
645
 
641
646
  real1 best_energy = -INFINITY;
@@ -643,7 +648,7 @@ __kernel void calculate_cut_segmented(
643
648
 
644
649
  for (; i < shots; i += MAX_PROC_ELEM) {
645
650
  const int j = (i * n + 31U) >> 5U;
646
- const real1 energy = cut_worker_segmented(theta + j, G_m, n, segment_size, is_spin_glass);
651
+ const real1 energy = cut_worker_segmented(theta[j / theta_segment_size] + (j % theta_segment_size), G_m, n, segment_size, is_spin_glass);
647
652
  if (energy > best_energy) {
648
653
  best_energy = energy;
649
654
  best_i = i;
@@ -675,7 +680,7 @@ __kernel void calculate_cut_segmented(
675
680
  }
676
681
 
677
682
  real1 cut_worker_sparse_segmented(
678
- __global uint* theta,
683
+ __global const uint* theta,
679
684
  __global const real1** G_data,
680
685
  __global const uint* G_rows,
681
686
  __global const uint* G_cols,
@@ -712,7 +717,10 @@ __kernel void calculate_cut_sparse_segmented(
712
717
  __global const real1* G_data3,
713
718
  __global const uint* G_rows,
714
719
  __global const uint* G_cols,
715
- __global uint* theta,
720
+ __global const uint* theta0,
721
+ __global const uint* theta1,
722
+ __global const uint* theta2,
723
+ __global const uint* theta3,
716
724
  __constant int* args, // args[0] = n, args[1] = k, args[2] = combo_count, args[3] = segment_size
717
725
  __global real1* max_energy_ptr,
718
726
  __global int* max_index_ptr,
@@ -720,11 +728,13 @@ __kernel void calculate_cut_sparse_segmented(
720
728
  __local int* loc_index
721
729
  ) {
722
730
  __global const real1* G_data[4] = { G_data0, G_data1, G_data2, G_data3 };
731
+ __global const uint* theta[4] = { theta0, theta1, theta2, theta3 };
723
732
 
724
733
  const int n = args[0];
725
734
  const int shots = args[1];
726
735
  const bool is_spin_glass = args[2];
727
736
  const int segment_size = args[3];
737
+ const int theta_segment_size = args[4];
728
738
  int i = get_global_id(0);
729
739
 
730
740
  real1 best_energy = -INFINITY;
@@ -732,7 +742,7 @@ __kernel void calculate_cut_sparse_segmented(
732
742
 
733
743
  for (; i < shots; i += MAX_PROC_ELEM) {
734
744
  const int j = (i * n + 31U) >> 5U;
735
- const real1 energy = cut_worker_sparse_segmented(theta + j, G_data, G_rows, G_cols, n, segment_size, is_spin_glass);
745
+ const real1 energy = cut_worker_sparse_segmented(theta[j / theta_segment_size] + (j % theta_segment_size), G_data, G_rows, G_cols, n, segment_size, is_spin_glass);
736
746
  if (energy > best_energy) {
737
747
  best_energy = energy;
738
748
  best_i = i;
@@ -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 get_cut, get_cut_base, make_G_m_buf, maxcut_hamming_cdf, opencl_context, sample_mag, bit_pick, init_bit_pick
7
+ from .maxcut_tfim_util import convert_bool_to_uint, get_cut, get_cut_base, make_G_m_buf, make_theta_buf, maxcut_hamming_cdf, opencl_context, sample_mag, bit_pick, init_bit_pick
8
8
 
9
9
  IS_OPENCL_AVAILABLE = True
10
10
  try:
@@ -90,7 +90,7 @@ def compute_cut(sample, G_m, n_qubits):
90
90
 
91
91
  @njit(parallel=True)
92
92
  def sample_measurement(G_m, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass):
93
- shots = max(1, shots >> 1)
93
+ shots = ((max(1, shots >> 1) + 3) >> 2) << 2
94
94
  n = len(G_m)
95
95
  tot_init_weight = weights.sum()
96
96
 
@@ -207,21 +207,6 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, an
207
207
  return bit_string, best_value, (l, r)
208
208
 
209
209
 
210
- @njit(parallel=True)
211
- def convert_bool_to_uint(samples):
212
- shots = samples.shape[0]
213
- n32 = ((samples.shape[1] + 31) >> 5) << 5
214
- theta = np.zeros(shots * (n32 >> 5), dtype=np.uint32)
215
- for i in prange(shots):
216
- i_offset = i * n32
217
- for j in range(n32):
218
- if samples[i, j]:
219
- b_index = i_offset + j
220
- theta[b_index >> 5] |= 1 << (b_index & 31)
221
-
222
- return theta
223
-
224
-
225
210
  def run_cut_opencl(samples, G_m_buf, is_segmented, segment_size, is_spin_glass):
226
211
  ctx = opencl_context.ctx
227
212
  queue = opencl_context.queue
@@ -233,12 +218,13 @@ def run_cut_opencl(samples, G_m_buf, is_segmented, segment_size, is_spin_glass):
233
218
  shots = samples.shape[1]
234
219
 
235
220
  # Args: [n, shots, is_spin_glass, prng_seed, segment_size]
236
- args_np = np.array([shots, samples.shape[0], is_spin_glass, segment_size], dtype=np.int32)
221
+ n = samples.shape[0]
222
+ args_np = np.array([shots, n, is_spin_glass, segment_size], dtype=np.int32)
237
223
 
238
224
  # Buffers
239
225
  mf = cl.mem_flags
240
- theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=convert_bool_to_uint(samples))
241
226
  args_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args_np)
227
+ theta_buf = make_theta_buf(convert_bool_to_uint(samples), is_segmented, shots, n)
242
228
 
243
229
  # Local memory allocation (1 float per work item)
244
230
  local_size = min(wgs, shots)
@@ -261,7 +247,10 @@ def run_cut_opencl(samples, G_m_buf, is_segmented, segment_size, is_spin_glass):
261
247
  G_m_buf[1],
262
248
  G_m_buf[2],
263
249
  G_m_buf[3],
264
- theta_buf,
250
+ theta_buf[0],
251
+ theta_buf[1],
252
+ theta_buf[2],
253
+ theta_buf[3],
265
254
  args_buf,
266
255
  max_energy_buf,
267
256
  max_index_buf,
@@ -410,7 +399,7 @@ def maxcut_tfim(
410
399
  repulsion_base = 8.0
411
400
 
412
401
  segment_size = G_m.shape[0] ** 2
413
- is_segmented = (G_m.nbytes << 1) > opencl_context.max_alloc
402
+ is_segmented = ((G_m.nbytes << 1) > opencl_context.max_alloc) or ((((((((n_qubits + 31) >> 5) << 5) * ((shots + 1) >> 1)) + 7) >> 3) << 1) > opencl_context.max_alloc)
414
403
 
415
404
  G_m_buf = make_G_m_buf(G_m, is_segmented, segment_size)
416
405
  if is_nested:
@@ -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 binary_search, get_cut, get_cut_base, make_G_m_csr_buf, maxcut_hamming_cdf, opencl_context, sample_mag, bit_pick, init_bit_pick, to_scipy_sparse_upper_triangular
7
+ from .maxcut_tfim_util import binary_search, convert_bool_to_uint, get_cut, get_cut_base, make_G_m_csr_buf, make_theta_buf, maxcut_hamming_cdf, opencl_context, sample_mag, bit_pick, init_bit_pick, to_scipy_sparse_upper_triangular
8
8
 
9
9
  IS_OPENCL_AVAILABLE = True
10
10
  try:
@@ -243,12 +243,13 @@ def run_cut_opencl(samples, G_data_buf, G_rows_buf, G_cols_buf, is_segmented, se
243
243
  shots = samples.shape[1]
244
244
 
245
245
  # Args: [n, shots, is_spin_glass, prng_seed, segment_size]
246
- args_np = np.array([shots, samples.shape[0], is_spin_glass, segment_size], dtype=np.int32)
246
+ n = samples.shape[0]
247
+ args_np = np.array([shots, n, is_spin_glass, segment_size], dtype=np.int32)
247
248
 
248
249
  # Buffers
249
250
  mf = cl.mem_flags
250
- theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=convert_bool_to_uint(samples))
251
251
  args_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args_np)
252
+ theta_buf = make_theta_buf(convert_bool_to_uint(samples), is_segmented, shots, n)
252
253
 
253
254
  # Local memory allocation (1 float per work item)
254
255
  local_size = min(wgs, shots)
@@ -273,7 +274,10 @@ def run_cut_opencl(samples, G_data_buf, G_rows_buf, G_cols_buf, is_segmented, se
273
274
  G_data_buf[3],
274
275
  G_rows_buf,
275
276
  G_cols_buf,
276
- theta_buf,
277
+ theta_buf[0],
278
+ theta_buf[1],
279
+ theta_buf[2],
280
+ theta_buf[3],
277
281
  args_buf,
278
282
  max_energy_buf,
279
283
  max_index_buf,
@@ -376,7 +380,7 @@ def maxcut_tfim_sparse(
376
380
  return bit_string, best_value, partition
377
381
 
378
382
  segment_size = G_m.data.shape[0]
379
- is_segmented = (G_m.data.nbytes << 1) > opencl_context.max_alloc
383
+ is_segmented = (G_m.data.nbytes << 1) > opencl_context.max_alloc or ((((((((n_qubits + 31) >> 5) << 5) * ((shots + 1) >> 1)) + 7) >> 3) << 1) > opencl_context.max_alloc)
380
384
 
381
385
  G_data_buf, G_rows_buf, G_cols_buf = make_G_m_csr_buf(G_m, is_segmented, segment_size)
382
386
  if is_nested:
@@ -162,6 +162,39 @@ def make_G_m_csr_buf(G_m, is_segmented, segment_size):
162
162
 
163
163
  return G_data_buf, G_rows_buf, G_cols_buf
164
164
 
165
+
166
+ def make_theta_buf(theta, is_segmented, shots, n):
167
+ mf = cl.mem_flags
168
+ ctx = opencl_context.ctx
169
+ if is_segmented:
170
+ n_shape = (((shots + 3) >> 2) << 2) * ((n + 31) >> 5)
171
+ theta = np.reshape(theta, (n_shape,))
172
+ _theta_segments = np.split(theta, 4)
173
+ theta_buf = [
174
+ cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=seg)
175
+ for seg in _theta_segments
176
+ ]
177
+ else:
178
+ theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
179
+
180
+ return theta_buf
181
+
182
+
183
+ @njit(parallel=True)
184
+ def convert_bool_to_uint(samples):
185
+ shots = samples.shape[0]
186
+ n32 = ((samples.shape[1] + 31) >> 5) << 5
187
+ theta = np.zeros(shots * (n32 >> 5), dtype=np.uint32)
188
+ for i in prange(shots):
189
+ i_offset = i * n32
190
+ for j in range(n32):
191
+ if samples[i, j]:
192
+ b_index = i_offset + j
193
+ theta[b_index >> 5] |= 1 << (b_index & 31)
194
+
195
+ return theta
196
+
197
+
165
198
  @njit
166
199
  def get_cut(solution, nodes):
167
200
  bit_string = ""
@@ -225,6 +225,7 @@ def spin_glass_solver(
225
225
  if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
226
226
  if not (opencl_context.G_m_buf is None):
227
227
  G_m_buf = opencl_context.G_m_buf
228
+ is_segmented = isinstance(G_m_buf, list)
228
229
  else:
229
230
  G_m_buf = make_G_m_buf(G_m, is_segmented, segment_size)
230
231
 
@@ -247,6 +247,7 @@ def spin_glass_solver_sparse(
247
247
  G_data_buf = opencl_context.G_data_buf
248
248
  G_rows_buf = opencl_context.G_rows_buf
249
249
  G_cols_buf = opencl_context.G_cols_buf
250
+ is_segmented = isinstance(G_data_buf, list)
250
251
  else:
251
252
  mf = cl.mem_flags
252
253
  ctx = opencl_context.ctx
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.1
3
+ Version: 8.14.2
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.1',
10
+ version='8.14.2',
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