PyQrackIsing 8.14.6__tar.gz → 8.14.8__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.6/pyqrackising.egg-info → pyqrackising-8.14.8}/PKG-INFO +1 -1
  2. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyproject.toml +1 -1
  3. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim.py +19 -12
  4. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_sparse.py +18 -14
  5. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_streaming.py +16 -10
  6. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_util.py +2 -1
  7. {pyqrackising-8.14.6 → pyqrackising-8.14.8/pyqrackising.egg-info}/PKG-INFO +1 -1
  8. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/setup.py +1 -1
  9. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/LICENSE.md +0 -0
  10. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/MANIFEST.in +0 -0
  11. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/README.md +0 -0
  12. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  14. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/generate_tfim_samples.py +0 -0
  15. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/kernels.cl +0 -0
  16. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver.py +0 -0
  17. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  18. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  19. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_util.py +0 -0
  20. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.14.6 → pyqrackising-8.14.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.6
3
+ Version: 8.14.8
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.6"
13
+ version = "8.14.8"
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"}
@@ -174,45 +174,52 @@ def sample_for_opencl(G_m, G_m_buf, max_edge, shots, thresholds, weights, repuls
174
174
 
175
175
 
176
176
  @njit(parallel=True)
177
- def init_J_and_z(G_m):
177
+ def init_J_and_z(G_m, repulsion_base):
178
178
  G_min = G_m.min()
179
179
  n_qubits = len(G_m)
180
180
  degrees = np.empty(n_qubits, dtype=np.uint32)
181
181
  J_eff = np.empty(n_qubits, dtype=np.float64)
182
+ weights = np.empty(n_qubits, dtype=np.float64)
182
183
  G_max = -float("inf")
183
184
  for n in prange(n_qubits):
184
185
  degree = 0
185
186
  J = 0.0
187
+ weight = 0.0
186
188
  for m in range(n_qubits):
187
189
  val = G_m[n, m]
190
+ weight += val
188
191
  if val > G_max:
189
192
  G_max = val
190
193
  val -= G_min
191
194
  if val != 0.0:
192
195
  degree += 1
193
196
  J += val
194
- val = abs(val)
195
- J = -J / degree if degree > 0 else 0
197
+ if degree > 0:
198
+ J = -J / degree
199
+ weight = -weight / n_qubits
196
200
  degrees[n] = degree
197
201
  J_eff[n] = J
202
+ weights[n] = weight
203
+
204
+ weights = repulsion_base ** weights
198
205
 
199
206
  G_min = abs(G_min)
200
207
  G_max = abs(G_max)
201
208
  if G_min > G_max:
202
209
  G_max = G_min
203
210
 
204
- return J_eff, degrees, G_max
211
+ return J_eff, degrees, weights, G_max
205
212
 
206
213
 
207
214
  @njit
208
215
  def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
209
- J_eff, degrees, max_edge = init_J_and_z(G_m)
216
+ J_eff, degrees, weights, max_edge = init_J_and_z(G_m, repulsion_base)
210
217
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
211
218
 
212
219
  degrees = None
213
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
220
+ J_eff = None
214
221
 
215
- best_solution, best_value = sample_measurement(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
222
+ best_solution, best_value = sample_measurement(G_m, max_edge, shots, hamming_prob, weights, repulsion_base, is_spin_glass)
216
223
 
217
224
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
218
225
 
@@ -311,7 +318,7 @@ def maxcut_tfim(
311
318
  return "01", weight, ([nodes[0]], [nodes[1]])
312
319
 
313
320
  if quality is None:
314
- quality = 6
321
+ quality = 5
315
322
 
316
323
  if shots is None:
317
324
  # Number of measurement shots
@@ -326,7 +333,7 @@ def maxcut_tfim(
326
333
  if repulsion_base is None:
327
334
  repulsion_base = 8.0
328
335
 
329
- is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE and (n_qubits >= wgs) and (shots >= wgs)
336
+ is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
330
337
 
331
338
  if not is_opencl:
332
339
  bit_string, best_value, partition = cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
@@ -342,13 +349,13 @@ def maxcut_tfim(
342
349
  is_segmented = ((G_m.nbytes << 1) > opencl_context.max_alloc) or ((theta_segment_size << 3) > opencl_context.max_alloc)
343
350
  G_m_buf = make_G_m_buf(G_m, is_segmented, segment_size)
344
351
 
345
- J_eff, degrees, max_edge = init_J_and_z(G_m)
352
+ J_eff, degrees, weights, max_edge = init_J_and_z(G_m, repulsion_base)
346
353
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
347
354
 
348
355
  degrees = None
349
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
356
+ J_eff = None
350
357
 
351
- best_solution, best_value = sample_for_opencl(G_m, G_m_buf, max_edge, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass, is_segmented, segment_size, theta_segment_size)
358
+ best_solution, best_value = sample_for_opencl(G_m, G_m_buf, max_edge, shots, hamming_prob, weights, repulsion_base, is_spin_glass, is_segmented, segment_size, theta_segment_size)
352
359
 
353
360
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
354
361
 
@@ -188,44 +188,48 @@ def sample_for_opencl(G_data, G_rows, G_cols, G_data_buf, G_rows_buf, G_cols_buf
188
188
  return best_solution, float(best_energy)
189
189
 
190
190
 
191
- def init_J_and_z(G_m):
191
+ def init_J_and_z(G_m, repulsion_base):
192
192
  G_min = G_m.min()
193
193
  n_qubits = G_m.shape[0]
194
194
  degrees = np.empty(n_qubits, dtype=np.uint32)
195
195
  J_eff = np.empty(n_qubits, dtype=np.float64)
196
+ weights = np.empty(n_qubits, dtype=np.float64)
196
197
  G_max = -float("inf")
197
198
  for n in prange(n_qubits):
198
199
  degree = 0
199
200
  J = 0.0
201
+ weight = 0.0
200
202
  for m in range(n_qubits):
201
203
  val = G_m[n, m]
204
+ weight += val
202
205
  if val > G_max:
203
206
  G_max = val
204
207
  val -= G_min
205
208
  if val != 0.0:
206
209
  degree += 1
207
210
  J += val
208
- val = abs(val)
209
- J = -J / degree if degree > 0 else 0
211
+ if degree > 0:
212
+ J = -J / degree
213
+ weight = -weight / n_qubits
210
214
  degrees[n] = degree
211
215
  J_eff[n] = J
216
+ weights[n] = weight
217
+
218
+ weights = repulsion_base ** weights
212
219
 
213
220
  G_min = abs(G_min)
214
221
  G_max = abs(G_max)
215
222
  if G_min > G_max:
216
223
  G_max = G_min
217
224
 
218
- return J_eff, degrees, G_max
225
+ return J_eff, degrees, weights, G_max
219
226
 
220
227
 
221
228
  @njit
222
- def cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_max, G_data, G_rows, G_cols, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
229
+ def cpu_footer(J_eff, degrees, weights, shots, quality, n_qubits, G_max, G_data, G_rows, G_cols, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
223
230
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
224
231
 
225
- degrees = None
226
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
227
-
228
- best_solution, best_value = sample_measurement(G_data, G_rows, G_cols, G_max, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
232
+ best_solution, best_value = sample_measurement(G_data, G_rows, G_cols, G_max, shots, hamming_prob, weights, repulsion_base, is_spin_glass)
229
233
 
230
234
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
231
235
 
@@ -374,7 +378,7 @@ def maxcut_tfim_sparse(
374
378
  return "01", weight, ([nodes[0]], [nodes[1]])
375
379
 
376
380
  if quality is None:
377
- quality = 6
381
+ quality = 5
378
382
 
379
383
  if shots is None:
380
384
  # Number of measurement shots
@@ -389,14 +393,14 @@ def maxcut_tfim_sparse(
389
393
  if repulsion_base is None:
390
394
  repulsion_base = 8.0
391
395
 
392
- J_eff, degrees, G_max = init_J_and_z(G_m)
396
+ J_eff, degrees, weights, G_max = init_J_and_z(G_m, repulsion_base)
393
397
 
394
398
  n_qubits = G_m.shape[0]
395
399
 
396
- is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE and (n_qubits >= wgs) and (shots >= wgs)
400
+ is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
397
401
 
398
402
  if not is_opencl:
399
- bit_string, best_value, partition = cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_max, G_m.data, G_m.indptr, G_m.indices, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
403
+ bit_string, best_value, partition = cpu_footer(J_eff, degrees, weights, shots, quality, n_qubits, G_max, G_m.data, G_m.indptr, G_m.indices, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
400
404
 
401
405
  if best_value < 0.0:
402
406
  # Best cut is trivial partition, all/empty
@@ -413,7 +417,7 @@ def maxcut_tfim_sparse(
413
417
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
414
418
 
415
419
  degrees = None
416
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
420
+ J_eff = repulsion_base ** J_eff
417
421
 
418
422
  best_solution, best_value = sample_for_opencl(G_m.data, G_m.indptr, G_m.indices, G_data_buf, G_rows_buf, G_cols_buf, G_max, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass, is_segmented, segment_size, theta_segment_size)
419
423
 
@@ -84,7 +84,7 @@ def compute_cut(sample, G_func, nodes, n_qubits):
84
84
 
85
85
 
86
86
  @njit(parallel=True)
87
- def sample_measurement(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base, is_spin_glass):
87
+ def sample_measurement(G_func, nodes, max_edge, shots, thresholds, weights, n, repulsion_base, is_spin_glass):
88
88
  shots = max(1, shots >> 1)
89
89
  tot_init_weight = weights.sum()
90
90
 
@@ -130,28 +130,35 @@ def sample_measurement(G_func, nodes, max_edge, shots, thresholds, degrees_sum,
130
130
 
131
131
 
132
132
  @njit(parallel=True)
133
- def init_J_and_z(G_func, nodes, G_min):
133
+ def init_J_and_z(G_func, nodes, G_min, repulsion_base):
134
134
  n_qubits = len(nodes)
135
135
  degrees = np.empty(n_qubits, dtype=np.uint32)
136
136
  J_eff = np.empty(n_qubits, dtype=np.float64)
137
+ weights = np.empty(n_qubits, dtype=np.float64)
137
138
  G_max = -float("inf")
138
139
  for n in prange(n_qubits):
139
140
  degree = 0
140
141
  J = 0.0
142
+ weight = 0.0
141
143
  for m in range(n_qubits):
142
144
  val = G_func(nodes[n], nodes[m])
145
+ weight += val
143
146
  if val > G_max:
144
147
  G_max = val
145
148
  val -= G_min
146
149
  if val != 0.0:
147
150
  degree += 1
148
151
  J += val
149
- val = abs(val)
150
- J = -J / degree if degree > 0 else 0
152
+ if degree > 0:
153
+ J = -J / degree
154
+ weight = -weight / n_qubits
151
155
  degrees[n] = degree
152
156
  J_eff[n] = J
157
+ weights[n] = weight
153
158
 
154
- return J_eff, degrees, G_max
159
+ weights = repulsion_base ** weights
160
+
161
+ return J_eff, degrees, weights, G_max
155
162
 
156
163
  @njit
157
164
  def find_G_min(G_func, nodes, n_nodes):
@@ -169,14 +176,13 @@ def find_G_min(G_func, nodes, n_nodes):
169
176
 
170
177
  @njit
171
178
  def cpu_footer(shots, quality, n_qubits, G_min, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
172
- J_eff, degrees, max_edge = init_J_and_z(G_func, nodes, G_min)
179
+ J_eff, degrees, weights, max_edge = init_J_and_z(G_func, nodes, G_min, repulsion_base)
173
180
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
174
- degrees_sum = degrees.sum()
175
181
 
176
182
  degrees = None
177
- J_eff = 1.0 / (1.0 + epsilon - J_eff)
183
+ J_eff = None
178
184
 
179
- best_solution, best_value = sample_measurement(G_func, nodes, max_edge, shots, hamming_prob, degrees_sum, J_eff, n_qubits, repulsion_base, is_spin_glass)
185
+ best_solution, best_value = sample_measurement(G_func, nodes, max_edge, shots, hamming_prob, weights, n_qubits, repulsion_base, is_spin_glass)
180
186
 
181
187
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
182
188
 
@@ -211,7 +217,7 @@ def maxcut_tfim_streaming(
211
217
  return "01", weight, ([nodes[0]], [nodes[1]])
212
218
 
213
219
  if quality is None:
214
- quality = 6
220
+ quality = 5
215
221
 
216
222
  if shots is None:
217
223
  # Number of measurement shots
@@ -368,7 +368,8 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, tot_t, h_mult):
368
368
  cum_prob = np.empty(n_bias, dtype=np.float64)
369
369
  for i in range(n_bias):
370
370
  tot_prob += hamming_prob[i + 1]
371
- cum_prob[i] = 2.0 if (1.0 - tot_prob) <= epsilon else tot_prob
371
+ cum_prob[i] = tot_prob
372
+ cum_prob[-1] = 1.0
372
373
 
373
374
  return cum_prob
374
375
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.6
3
+ Version: 8.14.8
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.6',
10
+ version='8.14.8',
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