PyQrackIsing 1.26.2__tar.gz → 1.27.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 (21) hide show
  1. {pyqrackising-1.26.2/PyQrackIsing.egg-info → pyqrackising-1.27.0}/PKG-INFO +1 -1
  2. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/maxcut_tfim.py +47 -20
  3. {pyqrackising-1.26.2 → pyqrackising-1.27.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  4. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/pyproject.toml +1 -1
  5. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/setup.py +1 -1
  6. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/CMakeLists.txt +0 -0
  7. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/LICENSE.md +0 -0
  8. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/MANIFEST.in +0 -0
  9. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/__init__.py +0 -0
  10. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  11. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
  12. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/spin_glass_solver.py +0 -0
  13. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/tfim_magnetization.py +0 -0
  14. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  15. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing/tsp_symmetric.py +0 -0
  16. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/README.md +0 -0
  21. {pyqrackising-1.26.2 → pyqrackising-1.27.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.26.2
3
+ Version: 1.27.0
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -32,12 +32,12 @@ try:
32
32
  return result
33
33
 
34
34
  @cuda.jit
35
- def cuda_maxcut_hamming_cdf(delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
35
+ def cuda_maxcut_hamming_cdf_wide(delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
36
36
  step = cuda.blockIdx.x
37
37
  qi = cuda.blockIdx.y
38
38
  J_eff = J_func[qi]
39
39
  z = degrees[qi]
40
- if abs(z * J_eff) <= (2 ** (-54)):
40
+ if abs(z * J_eff) <= (2 ** (-52)):
41
41
  return
42
42
 
43
43
  n_qubits = cuda.gridDim.y
@@ -53,6 +53,29 @@ try:
53
53
  diff -= cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff, tm1, n_qubits)
54
54
  hamming_prob[qo] += diff
55
55
 
56
+ @cuda.jit
57
+ def cuda_maxcut_hamming_cdf(n_qubits, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
58
+ step = cuda.blockIdx.x // n_qubits
59
+ qi = cuda.blockIdx.x % n_qubits
60
+ J_eff = J_func[qi]
61
+ z = degrees[qi]
62
+ if abs(z * J_eff) <= (2 ** (-52)):
63
+ return
64
+
65
+ theta_eff = theta[qi]
66
+ t = step * delta_t
67
+ tm1 = (step - 1) * delta_t
68
+ h_t = h_mult * (tot_t - t)
69
+
70
+ n_threads = cuda.gridDim.y
71
+ qo = cuda.threadIdx.x
72
+ while qo < n_qubits:
73
+ _qo = (n_qubits - (1 + qo)) if J_eff > 0.0 else qo
74
+ diff = cuda_probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, t, n_qubits)
75
+ diff -= cuda_probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, tm1, n_qubits)
76
+ hamming_prob[_qo] += diff
77
+ qo += n_threads
78
+
56
79
  except:
57
80
  IS_CUDA_AVAILABLE = False
58
81
 
@@ -162,7 +185,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
162
185
 
163
186
  weights = weights.copy()
164
187
  chosen = np.zeros(m, dtype=np.int32) # store chosen indices
165
- available = np.ones(n, dtype=np.int32) # 1 = available, 0 = not
188
+ available = np.ones(n, dtype=np.bool_) # True = available, False = not
166
189
  mask = np.zeros(n, dtype=np.bool_)
167
190
  chosen_count = 0
168
191
 
@@ -170,7 +193,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
170
193
  # Count available
171
194
  total_w = 0.0
172
195
  for i in range(n):
173
- if available[i] == 1:
196
+ if available[i]:
174
197
  total_w += weights[i]
175
198
  if total_w <= 0:
176
199
  break
@@ -180,7 +203,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
180
203
  cum = 0.0
181
204
  node = -1
182
205
  for i in range(n):
183
- if available[i] == 1:
206
+ if available[i]:
184
207
  cum += weights[i] / total_w
185
208
  if r < cum:
186
209
  node = i
@@ -192,14 +215,15 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
192
215
  # Select node
193
216
  chosen[chosen_count] = node
194
217
  chosen_count += 1
195
- available[node] = 0
196
- mask[node] = 1
218
+ available[node] = False
219
+ mask[node] = True
197
220
 
198
221
  # Repulsion: penalize neighbors
199
- deg = degrees[node]
200
- for j in range(deg):
222
+ for j in range(degrees[node]):
201
223
  nbr = adjacency[node, j]
202
- if nbr >= 0 and available[nbr] == 1:
224
+ if nbr < 0:
225
+ break
226
+ if available[nbr]:
203
227
  weights[nbr] *= 0.5 # tunable penalty factor
204
228
 
205
229
  return mask
@@ -217,7 +241,10 @@ def compute_energy(sample, G_m, n_qubits):
217
241
 
218
242
 
219
243
  @njit(parallel=True)
220
- def sample_for_solution(G_m, shots, thresholds, adjacency, degrees, weights, n):
244
+ def sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n):
245
+ adjacency = compute_adjacency(G_m, degrees.max())
246
+ weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
247
+
221
248
  best_solution = np.zeros(n, dtype=np.bool_)
222
249
  best_energy = compute_energy(best_solution, G_m, n)
223
250
 
@@ -303,11 +330,11 @@ def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
303
330
 
304
331
  return theta
305
332
 
306
- @njit
307
- def compute_adjacency(G_m):
333
+ @njit(parallel=True)
334
+ def compute_adjacency(G_m, max_degree):
308
335
  n_qubits = len(G_m)
309
- adjacency = np.full((n_qubits, n_qubits), -1, dtype=np.int32)
310
- for i in range(n_qubits):
336
+ adjacency = np.full((n_qubits, max_degree), -1, dtype=np.int32)
337
+ for i in prange(n_qubits):
311
338
  k = 0
312
339
  for j in range(n_qubits):
313
340
  if i == j:
@@ -371,8 +398,10 @@ def maxcut_tfim(
371
398
  # Warp size is 32:
372
399
  group_size = n_qubits - 1
373
400
  grid_dims = (n_steps, n_qubits)
374
-
375
- cuda_maxcut_hamming_cdf[grid_dims, group_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
401
+ if group_size <= 256:
402
+ cuda_maxcut_hamming_cdf_wide[grid_dims, group_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
403
+ else:
404
+ cuda_maxcut_hamming_cdf[n_steps * n_qubits, 128](n_qubits, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
376
405
 
377
406
  thresholds /= thresholds.sum()
378
407
  tot_prob = 0.0
@@ -383,9 +412,7 @@ def maxcut_tfim(
383
412
  else:
384
413
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
385
414
 
386
- adjacency = compute_adjacency(G_m)
387
- weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
388
- best_solution, best_value = sample_for_solution(G_m, shots, thresholds, adjacency, degrees, weights, n_qubits)
415
+ best_solution, best_value = sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n_qubits)
389
416
 
390
417
  bit_string = "".join(["1" if b else "0" for b in best_solution])
391
418
  bit_list = list(bit_string)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.26.2
3
+ Version: 1.27.0
4
4
  Summary: Near-ideal closed-form solutions for 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 = "1.26.2"
15
+ version = "1.27.0"
16
16
  requires-python = ">=3.8"
17
17
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
18
18
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='PyQrackIsing',
54
- version='1.26.2',
54
+ version='1.27.0',
55
55
  author='Dan Strano',
56
56
  author_email='stranoj@gmail.com',
57
57
  description='Near-ideal closed-form solutions for transverse field Ising model (TFIM)',
File without changes
File without changes
File without changes
File without changes