PyQrackIsing 8.7.2__tar.gz → 8.9.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 (30) hide show
  1. {pyqrackising-8.7.2/pyqrackising.egg-info → pyqrackising-8.9.0}/PKG-INFO +1 -1
  2. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyproject.toml +1 -1
  3. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/maxcut_tfim.py +2 -2
  4. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/maxcut_tfim_sparse.py +2 -2
  5. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/maxcut_tfim_streaming.py +2 -2
  6. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/maxcut_tfim_util.py +1 -1
  7. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/spin_glass_solver.py +56 -38
  8. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/spin_glass_solver_sparse.py +56 -38
  9. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/spin_glass_solver_streaming.py +53 -35
  10. {pyqrackising-8.7.2 → pyqrackising-8.9.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  11. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/setup.py +1 -1
  12. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/CMakeLists.txt +0 -0
  13. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/LICENSE.md +0 -0
  14. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/MANIFEST.in +0 -0
  15. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/README.md +0 -0
  16. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/__init__.py +0 -0
  17. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  18. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  19. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/generate_tfim_samples.py +0 -0
  20. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/kernels.cl +0 -0
  21. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  22. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/tfim_magnetization.py +0 -0
  23. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  24. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/tsp.py +0 -0
  25. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising/tsp_maxcut.py +0 -0
  26. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-8.7.2 → pyqrackising-8.9.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.7.2
3
+ Version: 8.9.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 = "8.7.2"
15
+ version = "8.9.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"}
@@ -287,7 +287,7 @@ def maxcut_tfim(
287
287
  return "01", weight, ([nodes[0]], [nodes[1]])
288
288
 
289
289
  if quality is None:
290
- quality = 5
290
+ quality = 6
291
291
 
292
292
  if shots is None:
293
293
  # Number of measurement shots
@@ -300,7 +300,7 @@ def maxcut_tfim(
300
300
  anneal_h = 8.0
301
301
 
302
302
  if repulsion_base is None:
303
- repulsion_base = 4.0
303
+ repulsion_base = 8.0
304
304
 
305
305
  bit_string, best_value, partition = cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
306
306
 
@@ -303,7 +303,7 @@ def maxcut_tfim_sparse(
303
303
  return "01", weight, ([nodes[0]], [nodes[1]])
304
304
 
305
305
  if quality is None:
306
- quality = 5
306
+ quality = 6
307
307
 
308
308
  if shots is None:
309
309
  # Number of measurement shots
@@ -316,7 +316,7 @@ def maxcut_tfim_sparse(
316
316
  anneal_h = 8.0
317
317
 
318
318
  if repulsion_base is None:
319
- repulsion_base = 4.0
319
+ repulsion_base = 8.0
320
320
 
321
321
  max_edge = abs(G_m.max())
322
322
  min_edge = abs(G_m.min())
@@ -278,7 +278,7 @@ def maxcut_tfim_streaming(
278
278
  return "01", weight, ([nodes[0]], [nodes[1]])
279
279
 
280
280
  if quality is None:
281
- quality = 5
281
+ quality = 6
282
282
 
283
283
  if shots is None:
284
284
  # Number of measurement shots
@@ -291,7 +291,7 @@ def maxcut_tfim_streaming(
291
291
  anneal_h = 8.0
292
292
 
293
293
  if repulsion_base is None:
294
- repulsion_base = 4.0
294
+ repulsion_base = 8.0
295
295
 
296
296
  bit_string, best_value, partition = cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
297
297
 
@@ -204,7 +204,7 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_bias):
204
204
  result *= factor
205
205
  bias[q] = result
206
206
 
207
- if (result == 0.0) or np.isnan(result):
207
+ if (result == 0.0) or np.isnan(result) or np.isinf(result):
208
208
  print("[WARN]: probability_by_hamming_weight() went below maximum precision.")
209
209
 
210
210
  if J > 0.0:
@@ -6,6 +6,7 @@ import networkx as nx
6
6
  import numpy as np
7
7
  from numba import njit, prange
8
8
  import os
9
+ import random
9
10
 
10
11
 
11
12
  IS_OPENCL_AVAILABLE = True
@@ -170,7 +171,8 @@ def spin_glass_solver(
170
171
  repulsion_base=None,
171
172
  min_order=1,
172
173
  max_order=None,
173
- is_log=False
174
+ is_log=False,
175
+ reheat_tries=0
174
176
  ):
175
177
  dtype = opencl_context.dtype
176
178
  nodes = None
@@ -249,44 +251,60 @@ def spin_glass_solver(
249
251
  cut_value = evaluate_cut_edges(best_theta, G_m)
250
252
  print(bitstring, float(cut_value), (l, r), float(min_energy))
251
253
 
252
- improved = True
253
- correction_quality = min_order
254
254
  combos_list = []
255
- while improved:
256
- improved = False
257
- k = 1
258
- while (k <= correction_quality) and (k <= max_order):
259
- if n_qubits < k:
260
- break
261
-
262
- combos = []
263
- if len(combos_list) < k:
264
- combos = np.array(list(
265
- item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
266
- ))
267
- combos_list.append(combos)
268
- else:
269
- combos = combos_list[k - 1]
270
-
271
- if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
272
- energy = run_bootstrap_opencl(best_theta, G_m_buf, combos, k, min_energy, is_segmented, segment_size)
273
- else:
274
- energy = bootstrap(best_theta, G_m, combos, k, min_energy, dtype)
275
-
276
- if energy < min_energy:
277
- min_energy = energy
278
- improved = True
279
- if correction_quality < (k + 1):
280
- correction_quality = k + 1
281
-
282
- if is_log:
283
- bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
284
- cut_value = evaluate_cut_edges(best_theta, G_m)
285
- print(bitstring, float(cut_value), (l, r), float(min_energy))
286
-
287
- break
288
-
289
- k = k + 1
255
+ reheat_theta = best_theta.copy()
256
+ reheat_min_energy = min_energy
257
+ for reheat_round in range(reheat_tries + 1):
258
+ improved = True
259
+ correction_quality = min_order
260
+ while improved:
261
+ improved = False
262
+ k = 1
263
+ while (k <= correction_quality) and (k <= max_order):
264
+ if n_qubits < k:
265
+ break
266
+
267
+ combos = []
268
+ if len(combos_list) < k:
269
+ combos = np.array(list(
270
+ item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
271
+ ))
272
+ combos_list.append(combos)
273
+ else:
274
+ combos = combos_list[k - 1]
275
+
276
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
277
+ energy = run_bootstrap_opencl(reheat_theta, G_m_buf, combos, k, reheat_min_energy, is_segmented, segment_size)
278
+ else:
279
+ energy = bootstrap(reheat_theta, G_m, combos, k, reheat_min_energy, dtype)
280
+
281
+ if energy < reheat_min_energy:
282
+ reheat_min_energy = energy
283
+ improved = True
284
+ if correction_quality < (k + 1):
285
+ correction_quality = k + 1
286
+
287
+ if is_log:
288
+ bitstring, l, r = get_cut_from_bit_array(reheat_theta, nodes)
289
+ cut_value = evaluate_cut_edges(reheat_theta, G_m)
290
+ print(bitstring, float(cut_value), (l, r), float(reheat_min_energy))
291
+
292
+ break
293
+
294
+ k = k + 1
295
+
296
+ if min_energy < reheat_min_energy:
297
+ reheat_theta = best_theta.copy()
298
+ else:
299
+ best_theta = reheat_theta.copy()
300
+ min_energy = reheat_min_energy
301
+
302
+ if reheat_round < reheat_tries:
303
+ num_to_flip = int(np.round(np.log2(n_qubits)))
304
+ bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
305
+ for bit in bits_to_flip:
306
+ reheat_theta[bit] = not reheat_theta[bit]
307
+ reheat_min_energy = compute_energy(reheat_theta, G_m)
290
308
 
291
309
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
292
310
  cut_value = evaluate_cut_edges(best_theta, G_m)
@@ -6,6 +6,7 @@ import networkx as nx
6
6
  import numpy as np
7
7
  from numba import njit, prange
8
8
  import os
9
+ import random
9
10
  from scipy.sparse import lil_matrix, csr_matrix
10
11
 
11
12
 
@@ -189,7 +190,8 @@ def spin_glass_solver_sparse(
189
190
  repulsion_base=None,
190
191
  min_order=1,
191
192
  max_order=None,
192
- is_log=False
193
+ is_log=False,
194
+ reheat_tries=0
193
195
  ):
194
196
  dtype = opencl_context.dtype
195
197
  nodes = None
@@ -272,44 +274,60 @@ def spin_glass_solver_sparse(
272
274
  cut_value = evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices)
273
275
  print(bitstring, float(cut_value), (l, r), float(min_energy))
274
276
 
275
- improved = True
276
- correction_quality = min_order
277
277
  combos_list = []
278
- while improved:
279
- improved = False
280
- k = 1
281
- while (k <= correction_quality) and (k <= max_order):
282
- if n_qubits < k:
283
- break
284
-
285
- combos = []
286
- if len(combos_list) < k:
287
- combos = np.array(list(
288
- item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
289
- ))
290
- combos_list.append(combos)
291
- else:
292
- combos = combos_list[k - 1]
293
-
294
- if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
295
- energy = run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, combos, k, min_energy, is_segmented, segment_size)
296
- else:
297
- energy = bootstrap(best_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, min_energy, dtype)
298
-
299
- if energy < min_energy:
300
- min_energy = energy
301
- improved = True
302
- if correction_quality < (k + 1):
303
- correction_quality = k + 1
304
-
305
- if is_log:
306
- bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
307
- cut_value = evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices)
308
- print(bitstring, float(cut_value), (l, r), float(min_energy))
309
-
310
- break
311
-
312
- k = k + 1
278
+ reheat_theta = best_theta.copy()
279
+ reheat_min_energy = min_energy
280
+ for reheat_round in range(reheat_tries + 1):
281
+ improved = True
282
+ correction_quality = min_order
283
+ while improved:
284
+ improved = False
285
+ k = 1
286
+ while (k <= correction_quality) and (k <= max_order):
287
+ if n_qubits < k:
288
+ break
289
+
290
+ combos = []
291
+ if len(combos_list) < k:
292
+ combos = np.array(list(
293
+ item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
294
+ ))
295
+ combos_list.append(combos)
296
+ else:
297
+ combos = combos_list[k - 1]
298
+
299
+ if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
300
+ energy = run_bootstrap_opencl(reheat_theta, G_data_buf, G_rows_buf, G_cols_buf, combos, k, reheat_min_energy, is_segmented, segment_size)
301
+ else:
302
+ energy = bootstrap(reheat_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, reheat_min_energy, dtype)
303
+
304
+ if energy < reheat_min_energy:
305
+ reheat_min_energy = energy
306
+ improved = True
307
+ if correction_quality < (k + 1):
308
+ correction_quality = k + 1
309
+
310
+ if is_log:
311
+ bitstring, l, r = get_cut_from_bit_array(reheat_theta, nodes)
312
+ cut_value = evaluate_cut_edges(reheat_theta, G_m.data, G_m.indptr, G_m.indices)
313
+ print(bitstring, float(cut_value), (l, r), float(reheat_min_energy))
314
+
315
+ break
316
+
317
+ k = k + 1
318
+
319
+ if min_energy < reheat_min_energy:
320
+ reheat_theta = best_theta.copy()
321
+ else:
322
+ best_theta = reheat_theta.copy()
323
+ min_energy = reheat_min_energy
324
+
325
+ if reheat_round < reheat_tries:
326
+ num_to_flip = int(np.round(np.log2(n_qubits)))
327
+ bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
328
+ for bit in bits_to_flip:
329
+ reheat_theta[bit] = not reheat_theta[bit]
330
+ reheat_min_energy = compute_energy(reheat_theta, G_m.data, G_m.indptr, G_m.indices)
313
331
 
314
332
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
315
333
  cut_value = evaluate_cut_edges(best_theta, G_m.data, G_m.indptr, G_m.indices)
@@ -6,6 +6,7 @@ import networkx as nx
6
6
  import numpy as np
7
7
  from numba import njit, prange
8
8
  import os
9
+ import random
9
10
 
10
11
 
11
12
  epsilon = opencl_context.epsilon
@@ -78,7 +79,8 @@ def spin_glass_solver_streaming(
78
79
  repulsion_base=None,
79
80
  min_order=1,
80
81
  max_order=None,
81
- is_log=False
82
+ is_log=False,
83
+ reheat_tries=0
82
84
  ):
83
85
  dtype = opencl_context.dtype
84
86
  n_qubits = len(nodes)
@@ -118,41 +120,57 @@ def spin_glass_solver_streaming(
118
120
  cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
119
121
  print(bitstring, float(cut_value), (l, r), float(min_energy))
120
122
 
121
- improved = True
122
- correction_quality = min_order
123
123
  combos_list = []
124
- while improved:
125
- improved = False
126
- k = 1
127
- while (k <= correction_quality) and (k <= max_order):
128
- if n_qubits < k:
129
- break
130
-
131
- combos = []
132
- if len(combos_list) < k:
133
- combos = np.array(list(
134
- item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
135
- ))
136
- combos_list.append(combos)
137
- else:
138
- combos = combos_list[k - 1]
139
-
140
- energy = bootstrap(best_theta, G_func, nodes, combos, k, min_energy, dtype)
141
-
142
- if energy < min_energy:
143
- min_energy = energy
144
- improved = True
145
- if correction_quality < (k + 1):
146
- correction_quality = k + 1
147
-
148
- if is_log:
149
- bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
150
- cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
151
- print(bitstring, float(cut_value), (l, r), float(min_energy))
152
-
153
- break
154
-
155
- k = k + 1
124
+ reheat_theta = best_theta.copy()
125
+ reheat_min_energy = min_energy
126
+ for reheat_round in range(reheat_tries + 1):
127
+ improved = True
128
+ correction_quality = min_order
129
+ while improved:
130
+ improved = False
131
+ k = 1
132
+ while (k <= correction_quality) and (k <= max_order):
133
+ if n_qubits < k:
134
+ break
135
+
136
+ combos = []
137
+ if len(combos_list) < k:
138
+ combos = np.array(list(
139
+ item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
140
+ ))
141
+ combos_list.append(combos)
142
+ else:
143
+ combos = combos_list[k - 1]
144
+
145
+ energy = bootstrap(best_theta, G_func, nodes, combos, k, min_energy, dtype)
146
+
147
+ if energy < reheat_min_energy:
148
+ reheat_min_energy = energy
149
+ improved = True
150
+ if correction_quality < (k + 1):
151
+ correction_quality = k + 1
152
+
153
+ if is_log:
154
+ bitstring, l, r = get_cut_from_bit_array(reheat_theta, nodes)
155
+ cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
156
+ print(bitstring, float(cut_value), (l, r), float(reheat_min_energy))
157
+
158
+ break
159
+
160
+ k = k + 1
161
+
162
+ if min_energy < reheat_min_energy:
163
+ reheat_theta = best_theta.copy()
164
+ else:
165
+ best_theta = reheat_theta.copy()
166
+ min_energy = reheat_min_energy
167
+
168
+ if reheat_round < reheat_tries:
169
+ num_to_flip = int(np.round(np.log2(n_qubits)))
170
+ bits_to_flip = random.sample(list(range(n_qubits)), num_to_flip)
171
+ for bit in bits_to_flip:
172
+ reheat_theta[bit] = not reheat_theta[bit]
173
+ reheat_min_energy = compute_energy(reheat_theta, G_func, nodes)
156
174
 
157
175
  bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
158
176
  cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.7.2
3
+ Version: 8.9.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
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='8.7.2',
54
+ version='8.9.0',
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
File without changes