PyQrackIsing 5.5.0__tar.gz → 5.5.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-5.5.0/pyqrackising.egg-info → pyqrackising-5.5.2}/PKG-INFO +1 -1
  2. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/README.md +2 -0
  3. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyproject.toml +1 -1
  4. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/kernels.cl +98 -11
  5. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/maxcut_tfim.py +1 -1
  6. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/maxcut_tfim_sparse.py +1 -1
  7. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/maxcut_tfim_util.py +1 -0
  8. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/spin_glass_solver.py +1 -1
  9. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/spin_glass_solver_sparse.py +1 -1
  10. {pyqrackising-5.5.0 → pyqrackising-5.5.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  11. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/setup.py +1 -1
  12. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/CMakeLists.txt +0 -0
  13. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/LICENSE.md +0 -0
  14. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/MANIFEST.in +0 -0
  15. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/__init__.py +0 -0
  16. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/_pyqrack_ising.cpp +0 -0
  17. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/generate_tfim_samples.py +0 -0
  18. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  19. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising/tsp.py +0 -0
  24. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-5.5.0 → pyqrackising-5.5.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.5.0
3
+ Version: 5.5.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
@@ -143,6 +143,8 @@ solution_bit_string, cut_value, node_groups, energy = spin_glass_solver_streamin
143
143
 
144
144
  We expose an environment variable, "`PYQRACKISING_MAX_GPU_PROC_ELEM`", for when `is_alt_gpu_sampling=True`. The default value (when the variable is not set) is queried from the OpenCL device properties. You might see performance benefit from tuning this manually to several times your device's number of "compute units" (or tune it down to reduce private memory usage).
145
145
 
146
+ Similarly, for `is_alt_gpu_sampling=True`, define the "top-`n`" count of highest-weight direct neighbors to retain during sampling with environment variable "`PYQRACKISING_GPU_TOP_N`". The default is `32`. Increasing this might increase solution quality, but it will also increase time-to-solution and private memory usage.
147
+
146
148
  ## About
147
149
  Transverse field Ising model (TFIM) is the basis of most claimed algorithmic "quantum advantage," circa 2025, with the notable exception of Shor's integer factoring algorithm.
148
150
 
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "5.5.0"
15
+ version = "5.5.2"
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"}
@@ -323,8 +323,12 @@ __kernel void sample_for_solution_best_bitset(
323
323
  temp_sol[(gid >> 5) & MAX_WORDS_MASK] |= 1U << (gid & 31);
324
324
 
325
325
  for (int count = 1; count < m; ++count) {
326
- double highest_weight = -INFINITY;
327
- int best_bit = -1;
326
+ double highest_weights[TOP_N];
327
+ int best_bits[TOP_N];
328
+ for (int x = 0; x < TOP_N; ++x) {
329
+ highest_weights[x] = -INFINITY;
330
+ best_bits[x] = -1;
331
+ }
328
332
 
329
333
  for (int i = 0; i < n; i += 32) {
330
334
  for (int j = 0; j < 32; ++j) {
@@ -349,10 +353,50 @@ __kernel void sample_for_solution_best_bitset(
349
353
  }
350
354
  }
351
355
  }
352
- if (weight > highest_weight) {
353
- highest_weight = weight;
354
- best_bit = u;
356
+
357
+ int lowest_option = 0;
358
+ double lowest_weight = highest_weights[0];
359
+ if (lowest_weight != -INFINITY) {
360
+ for (int x = 0; x < TOP_N; ++x) {
361
+ double val = highest_weights[x];
362
+ if (val < lowest_weight) {
363
+ lowest_option = x;
364
+ lowest_weight = highest_weights[x];
365
+ if (val == -INFINITY) {
366
+ break;
367
+ }
368
+ }
369
+ }
355
370
  }
371
+
372
+ if (weight > lowest_weight) {
373
+ highest_weights[lowest_option] = weight;
374
+ best_bits[lowest_option] = u;
375
+ }
376
+ }
377
+ }
378
+
379
+ double total_weight = 0.0;
380
+ for (int x = 0; x < TOP_N; ++x) {
381
+ const double val = highest_weights[x];
382
+ if (val == -INFINITY) {
383
+ continue;
384
+ }
385
+ total_weight += val;
386
+ }
387
+
388
+ const float bit_prob = rand_uniform(&state);
389
+ double tot_prob = 0.0;
390
+ int best_bit = 0;
391
+ for (int x = 0; x < TOP_N; ++x) {
392
+ const double val = highest_weights[x];
393
+ if (val == -INFINITY) {
394
+ continue;
395
+ }
396
+ tot_prob += val;
397
+ if ((total_weight * bit_prob) < tot_prob) {
398
+ best_bit = best_bits[x];
399
+ break;
356
400
  }
357
401
  }
358
402
 
@@ -475,7 +519,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
475
519
  for (int gid = gid_orig; gid < shots; gid += MAX_PROC_ELEM) {
476
520
 
477
521
  // --- 1. Choose Hamming weight
478
- float mag_prob = rand_uniform(&state);
522
+ const float mag_prob = rand_uniform(&state);
479
523
  int m = 0;
480
524
  while (m < n && thresholds[m] < mag_prob) m++;
481
525
  m++;
@@ -485,8 +529,12 @@ __kernel void sample_for_solution_best_bitset_sparse(
485
529
  temp_sol[(gid >> 5) & MAX_WORDS_MASK] |= 1U << (gid & 31);
486
530
 
487
531
  for (int count = 1; count < m; ++count) {
488
- double highest_weight = -INFINITY;
489
- int best_bit = -1;
532
+ double highest_weights[TOP_N];
533
+ int best_bits[TOP_N];
534
+ for (int x = 0; x < TOP_N; ++x) {
535
+ highest_weights[x] = -INFINITY;
536
+ best_bits[x] = -1;
537
+ }
490
538
 
491
539
  for (int i = 0; i < n; i += 32) {
492
540
  for (int j = 0; j < 32; ++j) {
@@ -521,10 +569,49 @@ __kernel void sample_for_solution_best_bitset_sparse(
521
569
  }
522
570
  }
523
571
 
524
- if (weight > highest_weight) {
525
- highest_weight = weight;
526
- best_bit = u;
572
+ int lowest_option = 0;
573
+ double lowest_weight = highest_weights[0];
574
+ if (lowest_weight != -INFINITY) {
575
+ for (int x = 0; x < TOP_N; ++x) {
576
+ double val = highest_weights[x];
577
+ if (val < lowest_weight) {
578
+ lowest_option = x;
579
+ lowest_weight = highest_weights[x];
580
+ if (val == -INFINITY) {
581
+ break;
582
+ }
583
+ }
584
+ }
527
585
  }
586
+
587
+ if (weight > lowest_weight) {
588
+ highest_weights[lowest_option] = weight;
589
+ best_bits[lowest_option] = u;
590
+ }
591
+ }
592
+ }
593
+
594
+ double total_weight = 0.0;
595
+ for (int x = 0; x < TOP_N; ++x) {
596
+ const double val = highest_weights[x];
597
+ if (val == -INFINITY) {
598
+ continue;
599
+ }
600
+ total_weight += val;
601
+ }
602
+
603
+ const float bit_prob = rand_uniform(&state);
604
+ double tot_prob = 0.0;
605
+ int best_bit = 0;
606
+ for (int x = 0; x < TOP_N; ++x) {
607
+ const double val = highest_weights[x];
608
+ if (val == -INFINITY) {
609
+ continue;
610
+ }
611
+ tot_prob += val;
612
+ if ((total_weight * bit_prob) < tot_prob) {
613
+ best_bit = best_bits[x];
614
+ break;
528
615
  }
529
616
  }
530
617
 
@@ -240,7 +240,7 @@ def maxcut_tfim(
240
240
  G,
241
241
  quality=None,
242
242
  shots=None,
243
- is_alt_gpu_sampling = False,
243
+ is_alt_gpu_sampling = True,
244
244
  is_g_buf_reused = False
245
245
  ):
246
246
  nodes = None
@@ -305,7 +305,7 @@ def maxcut_tfim_sparse(
305
305
  G,
306
306
  quality=None,
307
307
  shots=None,
308
- is_alt_gpu_sampling = False,
308
+ is_alt_gpu_sampling = True,
309
309
  is_g_buf_reused = False
310
310
  ):
311
311
  nodes = None
@@ -179,6 +179,7 @@ try:
179
179
 
180
180
  # Load and build OpenCL kernels
181
181
  kernel_src = f"#define MAX_PROC_ELEM {compute_units}\n"
182
+ kernel_src += f"#define TOP_N {os.getenv('PYQRACKISING_GPU_TOP_N', '32')}\n"
182
183
  kernel_src += open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
183
184
  program = cl.Program(ctx, kernel_src).build()
184
185
  init_theta_kernel = program.init_theta
@@ -140,7 +140,7 @@ def spin_glass_solver(
140
140
  quality=None,
141
141
  shots=None,
142
142
  best_guess=None,
143
- is_alt_gpu_sampling=False
143
+ is_alt_gpu_sampling=True
144
144
  ):
145
145
  nodes = None
146
146
  n_qubits = 0
@@ -157,7 +157,7 @@ def spin_glass_solver_sparse(
157
157
  quality=None,
158
158
  shots=None,
159
159
  best_guess=None,
160
- is_alt_gpu_sampling=False
160
+ is_alt_gpu_sampling=True
161
161
  ):
162
162
  nodes = None
163
163
  n_qubits = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.5.0
3
+ Version: 5.5.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
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='5.5.0',
54
+ version='5.5.2',
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