PyQrackIsing 1.12.0__tar.gz → 1.13.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.12.0/PyQrackIsing.egg-info → pyqrackising-1.13.0}/PKG-INFO +1 -1
  2. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/maxcut_tfim.py +129 -6
  3. {pyqrackising-1.12.0 → pyqrackising-1.13.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  4. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/pyproject.toml +2 -1
  5. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/setup.py +1 -1
  6. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/CMakeLists.txt +0 -0
  7. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/LICENSE.md +0 -0
  8. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/MANIFEST.in +0 -0
  9. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/__init__.py +0 -0
  10. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  11. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
  12. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/spin_glass_solver.py +0 -0
  13. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/tfim_magnetization.py +0 -0
  14. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  15. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing/tsp_symmetric.py +0 -0
  16. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/README.md +0 -0
  21. {pyqrackising-1.12.0 → pyqrackising-1.13.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.12.0
3
+ Version: 1.13.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
@@ -1,6 +1,83 @@
1
+ import math
1
2
  import networkx as nx
2
3
  import numpy as np
3
4
  from numba import njit, prange
5
+ IS_CUDA_AVAILABLE = True
6
+ try:
7
+ from numba import cuda, types
8
+ from numba.core.errors import NumbaPerformanceWarning
9
+ import warnings
10
+
11
+ warnings.simplefilter('ignore', category=NumbaPerformanceWarning)
12
+
13
+ @cuda.jit(device=True)
14
+ def cuda_probability_by_hamming_weight(J, h, z, theta, t, n_qubits, bias):
15
+ # critical angle
16
+ theta_c = np.arcsin(
17
+ max(
18
+ -1.0,
19
+ min(
20
+ 1.0,
21
+ (1.0 if J > 0.0 else -1.0) if abs(z * J) <= (2 ** (-54)) else (abs(h) / (z * J)),
22
+ ),
23
+ )
24
+ )
25
+
26
+ p = (
27
+ pow(2.0, abs(J / h) - 1.0)
28
+ * (1.0 + math.sin(theta - theta_c) * math.cos(1.5 * math.pi * J * t + theta) / (1.0 + math.sqrt(t)))
29
+ - 0.5
30
+ )
31
+
32
+ if (p * n_qubits) >= 1024:
33
+ for i in range(n_qubits - 1):
34
+ bias[i] = 0.0
35
+ return
36
+
37
+ tot_n = 1.0 + 1.0 / pow(2.0, p * n_qubits)
38
+ for q in range(1, n_qubits):
39
+ n = 1.0 / pow(2.0, p * q)
40
+ bias[q - 1] = n
41
+ tot_n += n
42
+ for q in range(n_qubits - 1):
43
+ bias[q] /= tot_n
44
+
45
+ if J > 0.0:
46
+ end = n_qubits - 2
47
+ for i in range((n_qubits - 1) // 2):
48
+ tmp = bias[i]
49
+ bias[i] = bias[end - i]
50
+ bias[end - i] = tmp
51
+
52
+ @cuda.jit
53
+ def cuda_maxcut_hamming_cdf(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
54
+ qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
55
+ step = qc // n_qubits
56
+ q = qc % n_qubits
57
+
58
+ if step > n_steps:
59
+ return
60
+
61
+ J_eff = J_func[q]
62
+ if abs(J_eff) <= (2 ** (-54)):
63
+ return
64
+
65
+ z = degrees[q]
66
+ theta_eff = theta[q]
67
+ t = step * delta_t
68
+ tm1 = (step - 1) * delta_t
69
+ h_t = h_mult * (tot_t - t)
70
+ n_bias = n_qubits - 1
71
+
72
+ bias = cuda.local.array(shape=(8192,), dtype=types.float64)
73
+ cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
74
+ last_bias = cuda.local.array(shape=(8192,), dtype=types.float64)
75
+ cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, last_bias)
76
+ for i in range(n_qubits - 1):
77
+ hamming_prob[i] += bias[i] - last_bias[i]
78
+
79
+ except:
80
+ IS_CUDA_AVAILABLE = False
4
81
 
5
82
 
6
83
  @njit
@@ -30,7 +107,7 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
30
107
  tot_n = 1.0 + 1.0 / pow(2.0, p * n_qubits)
31
108
  for q in range(1, n_qubits):
32
109
  n = 1.0 / pow(2.0, p * q)
33
- bias[q] = n
110
+ bias[q - 1] = n
34
111
  tot_n += n
35
112
  bias /= tot_n
36
113
 
@@ -41,7 +118,7 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
41
118
 
42
119
 
43
120
  @njit(parallel=True)
44
- def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality):
121
+ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
45
122
  if n_qubits < 2:
46
123
  return np.empty(0, dtype=np.float64)
47
124
 
@@ -50,7 +127,7 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality):
50
127
  tot_t = n_steps * delta_t
51
128
  h_mult = 32.0 / tot_t
52
129
  n_bias = n_qubits - 1
53
- hamming_prob = np.full(n_bias, 1 / n_bias)
130
+
54
131
  theta = np.zeros(n_qubits)
55
132
  for q in prange(n_qubits):
56
133
  J = J_func[q]
@@ -90,8 +167,6 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality):
90
167
  hamming_prob[i] = tot_prob
91
168
  hamming_prob[-1] = 1.0
92
169
 
93
- return hamming_prob
94
-
95
170
 
96
171
  # Written by Elara (OpenAI custom GPT)
97
172
  def local_repulsion_choice(nodes, adjacency, degrees, weights, n, m):
@@ -200,7 +275,55 @@ def maxcut_tfim(
200
275
  dtype=np.float64,
201
276
  )
202
277
  # thresholds = tfim_sampler._maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality)
203
- thresholds = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality)
278
+ n_bias = n_qubits - 1
279
+ tot_prob = 2.0
280
+ thresholds = np.zeros(n_bias)
281
+ for q in range(1, n_qubits // 2):
282
+ n = math.comb(n_qubits, q)
283
+ thresholds[q - 1] = n
284
+ thresholds[n_bias - q] = n
285
+ tot_prob += n << 1
286
+ if n_qubits & 1:
287
+ q = n_qubits // 2
288
+ n = math.comb(n_qubits, q)
289
+ thresholds[q - 1] = n
290
+ tot_prob += n
291
+ thresholds /= tot_prob
292
+
293
+ n_steps = 1 << quality
294
+ grid_size = (n_steps * n_qubits + 31) // 32
295
+
296
+ if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 256 and (n_qubits <= 8192):
297
+ delta_t = 1.0 / n_steps
298
+ tot_t = n_steps * delta_t
299
+ h_mult = 32.0 / tot_t
300
+
301
+ theta = np.zeros(n_qubits)
302
+ for q in range(n_qubits):
303
+ J = J_eff[q]
304
+ z = degrees[q]
305
+ theta[q] = np.arcsin(
306
+ max(
307
+ -1.0,
308
+ min(
309
+ 1.0,
310
+ (1.0 if J > 0.0 else -1.0) if np.isclose(abs(z * J), 0.0) else (abs(h_mult) / (z * J)),
311
+ ),
312
+ )
313
+ )
314
+
315
+ cuda_maxcut_hamming_cdf[grid_size, 256](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
316
+
317
+ tot_prob = sum(thresholds)
318
+ thresholds /= tot_prob
319
+
320
+ tot_prob = 0.0
321
+ for i in range(n_bias):
322
+ tot_prob += thresholds[i]
323
+ thresholds[i] = tot_prob
324
+ thresholds[-1] = 1.0
325
+ else:
326
+ maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
204
327
  G_dict = nx.to_dict_of_lists(G)
205
328
  J_max = max(J_eff)
206
329
  weights = 1.0 / (1.0 + (J_max - J_eff))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.12.0
3
+ Version: 1.13.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
@@ -6,12 +6,13 @@ requires = [
6
6
  "networkx",
7
7
  "numpy",
8
8
  "numba",
9
+ "numba-cuda",
9
10
  ]
10
11
  build-backend = "setuptools.build_meta"
11
12
 
12
13
  [project]
13
14
  name = "PyQrackIsing"
14
- version = "1.12.0"
15
+ version = "1.13.0"
15
16
  requires-python = ">=3.8"
16
17
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
17
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.12.0',
54
+ version='1.13.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