PyQrackIsing 8.14.7__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.7/pyqrackising.egg-info → pyqrackising-8.14.8}/PKG-INFO +1 -1
  2. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyproject.toml +1 -1
  3. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim.py +17 -10
  4. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_sparse.py +15 -10
  5. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_streaming.py +14 -7
  6. {pyqrackising-8.14.7 → pyqrackising-8.14.8/pyqrackising.egg-info}/PKG-INFO +1 -1
  7. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/setup.py +1 -1
  8. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/LICENSE.md +0 -0
  9. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/MANIFEST.in +0 -0
  10. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/README.md +0 -0
  11. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/__init__.py +0 -0
  12. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  13. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/generate_tfim_samples.py +0 -0
  14. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/kernels.cl +0 -0
  15. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/maxcut_tfim_util.py +0 -0
  16. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver.py +0 -0
  17. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  18. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  19. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/spin_glass_solver_util.py +0 -0
  20. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.14.7 → pyqrackising-8.14.8}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.14.7 → 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.7
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.7"
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 = repulsion_base ** 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
 
@@ -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 = repulsion_base ** 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,43 +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
- J_eff = repulsion_base ** J_eff
226
-
227
- 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)
228
233
 
229
234
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
230
235
 
@@ -388,14 +393,14 @@ def maxcut_tfim_sparse(
388
393
  if repulsion_base is None:
389
394
  repulsion_base = 8.0
390
395
 
391
- 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)
392
397
 
393
398
  n_qubits = G_m.shape[0]
394
399
 
395
400
  is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
396
401
 
397
402
  if not is_opencl:
398
- 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)
399
404
 
400
405
  if best_value < 0.0:
401
406
  # Best cut is trivial partition, all/empty
@@ -130,28 +130,35 @@ def sample_measurement(G_func, nodes, max_edge, shots, thresholds, weights, n, r
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,13 +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
181
 
175
182
  degrees = None
176
- J_eff = repulsion_base ** J_eff
183
+ J_eff = None
177
184
 
178
- best_solution, best_value = sample_measurement(G_func, nodes, max_edge, shots, hamming_prob, 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)
179
186
 
180
187
  bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
181
188
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.14.7
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.7',
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