PyQrackIsing 5.7.0__tar.gz → 5.7.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.7.0/pyqrackising.egg-info → pyqrackising-5.7.2}/PKG-INFO +1 -1
  2. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/README.md +4 -4
  3. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyproject.toml +1 -1
  4. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/kernels.cl +34 -15
  5. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/spin_glass_solver.py +1 -0
  6. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/spin_glass_solver_sparse.py +1 -0
  7. {pyqrackising-5.7.0 → pyqrackising-5.7.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  8. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/setup.py +1 -1
  9. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/CMakeLists.txt +0 -0
  10. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/LICENSE.md +0 -0
  11. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/MANIFEST.in +0 -0
  12. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/_pyqrack_ising.cpp +0 -0
  14. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/generate_tfim_samples.py +0 -0
  15. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/maxcut_tfim.py +0 -0
  16. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  17. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/maxcut_tfim_util.py +0 -0
  19. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising/tsp.py +0 -0
  24. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-5.7.0 → pyqrackising-5.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.0
3
+ Version: 5.7.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
@@ -50,10 +50,10 @@ from pyqrackising import maxcut_tfim
50
50
  import networkx as nx
51
51
 
52
52
  G = nx.petersen_graph()
53
- best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=2, is_alt_gpu_sampling=True)
53
+ best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=2, is_base_maxcut_gpu=True, is_alt_gpu_sampling=True)
54
54
  ```
55
55
 
56
- We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is optional, with a default value of `2`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) `is_alt_gpu_sampling` is `False` by default and, if set to `True`, will dispatch almost the entire algorithm on GPU, instead of just the TFIM-heuristic component (although solution quality is often lower). If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
56
+ We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is optional, with a default value of `2`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) `is_base_maxcut_gpu` enables or disables GPU execution. `is_alt_gpu_sampling` is `False` by default and, if set to `True`, will dispatch almost the entire algorithm on GPU, instead of just the TFIM-heuristic component (although solution quality is often lower). If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
57
57
 
58
58
  Based on a combination of the TFIM-inspired MAXCUT solver and another technique for finding ground-state energy in quantum chemistry that we call the _"binary Clifford eigensolver,"_ we also provide an (approximate) spin glass ground-state solver:
59
59
  ```py
@@ -73,10 +73,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
73
73
 
74
74
 
75
75
  G = generate_spin_glass_graph(n_nodes=64, seed=42)
76
- solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=2, best_guess=None, is_alt_gpu_sampling=True)
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`. `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` **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.0"
15
+ version = "5.7.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"}
@@ -94,6 +94,15 @@ __kernel void maxcut_hamming_cdf(
94
94
  }
95
95
  }
96
96
 
97
+ inline uint xorshift32(uint *state) {
98
+ uint x = *state;
99
+ x ^= x << 13;
100
+ x ^= x >> 17;
101
+ x ^= x << 5;
102
+ *state = x;
103
+ return x;
104
+ }
105
+
97
106
  float bootstrap_worker(__constant char* theta, __global double* G_m, __constant int* indices, const int k, const int n) {
98
107
  double energy = 0.0;
99
108
  const size_t n_st = (size_t)n;
@@ -123,6 +132,7 @@ float bootstrap_worker(__constant char* theta, __global double* G_m, __constant
123
132
  }
124
133
 
125
134
  __kernel void bootstrap(
135
+ uint prng_seed,
126
136
  __global double* G_m,
127
137
  __constant char* best_theta,
128
138
  __constant int* indices_array,
@@ -137,6 +147,9 @@ __kernel void bootstrap(
137
147
  const int combo_count = args[2];
138
148
  const int i = get_global_id(0);
139
149
 
150
+ // The inputs are chaotic, and this doesn't need to be high-quality, just uniform.
151
+ prng_seed ^= (uint)i;
152
+
140
153
  float energy = INFINITY;
141
154
 
142
155
  if (i < combo_count) {
@@ -155,9 +168,15 @@ __kernel void bootstrap(
155
168
  // Reduce within workgroup
156
169
  for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
157
170
  barrier(CLK_LOCAL_MEM_FENCE);
158
- if ((lt_id < offset) && (loc_energy[lt_id + offset] < loc_energy[lt_id])) {
159
- loc_energy[lt_id] = loc_energy[lt_id + offset];
160
- loc_index[lt_id] = loc_index[lt_id + offset];
171
+ if (lt_id < offset) {
172
+ float hid_energy = loc_energy[lt_id + offset];
173
+ float lid_energy = loc_energy[lt_id];
174
+ if (hid_energy < lid_energy) {
175
+ loc_energy[lt_id] = hid_energy;
176
+ loc_index[lt_id] = loc_index[lt_id + offset];
177
+ } else if ((hid_energy == lid_energy) && ((xorshift32(&prng_seed) >> 31) & 1)) {
178
+ loc_index[lt_id] = loc_index[lt_id + offset];
179
+ }
161
180
  }
162
181
  }
163
182
 
@@ -197,6 +216,7 @@ float bootstrap_worker_sparse(__constant char* theta, __global double* G_data, _
197
216
  }
198
217
 
199
218
  __kernel void bootstrap_sparse(
219
+ uint prng_seed,
200
220
  __global double* G_data,
201
221
  __global unsigned* G_rows,
202
222
  __global unsigned* G_cols,
@@ -213,6 +233,8 @@ __kernel void bootstrap_sparse(
213
233
  const int combo_count = args[2];
214
234
  const int i = get_global_id(0);
215
235
 
236
+ prng_seed ^= (uint)i;
237
+
216
238
  float energy = INFINITY;
217
239
 
218
240
  if (i < combo_count) {
@@ -231,9 +253,15 @@ __kernel void bootstrap_sparse(
231
253
  // Reduce within workgroup
232
254
  for (int offset = lt_size >> 1; offset > 0; offset >>= 1) {
233
255
  barrier(CLK_LOCAL_MEM_FENCE);
234
- if ((lt_id < offset) && (loc_energy[lt_id + offset] < loc_energy[lt_id])) {
235
- loc_energy[lt_id] = loc_energy[lt_id + offset];
236
- loc_index[lt_id] = loc_index[lt_id + offset];
256
+ if (lt_id < offset) {
257
+ float hid_energy = loc_energy[lt_id + offset];
258
+ float lid_energy = loc_energy[lt_id];
259
+ if (hid_energy < lid_energy) {
260
+ loc_energy[lt_id] = hid_energy;
261
+ loc_index[lt_id] = loc_index[lt_id + offset];
262
+ } else if ((hid_energy == lid_energy) && ((xorshift32(&prng_seed) >> 31) & 1)) {
263
+ loc_index[lt_id] = loc_index[lt_id + offset];
264
+ }
237
265
  }
238
266
  }
239
267
 
@@ -246,15 +274,6 @@ __kernel void bootstrap_sparse(
246
274
 
247
275
  /// ------ Alternative random sampling rejection kernel by Elara (the OpenAI custom GPT) is below ------ ///
248
276
 
249
- inline uint xorshift32(uint *state) {
250
- uint x = *state;
251
- x ^= x << 13;
252
- x ^= x >> 17;
253
- x ^= x << 5;
254
- *state = x;
255
- return x;
256
- }
257
-
258
277
  inline float rand_uniform(uint *state) {
259
278
  return (float)xorshift32(state) / (float)0xFFFFFFFF;
260
279
  }
@@ -101,6 +101,7 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy):
101
101
 
102
102
  # Set kernel args
103
103
  bootstrap_kernel.set_args(
104
+ np.random.randint(1<<32, dtype='uint32'),
104
105
  G_m_buf,
105
106
  best_theta_buf,
106
107
  indices_buf,
@@ -104,6 +104,7 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
104
104
 
105
105
  # Set kernel args
106
106
  bootstrap_kernel.set_args(
107
+ np.random.randint(1<<32, dtype='uint32'),
107
108
  G_data_buf,
108
109
  G_rows_buf,
109
110
  G_cols_buf,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.7.0
3
+ Version: 5.7.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.7.0',
54
+ version='5.7.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