PyQrackIsing 1.12.0__tar.gz → 1.13.1__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.
- {pyqrackising-1.12.0/PyQrackIsing.egg-info → pyqrackising-1.13.1}/PKG-INFO +1 -1
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/maxcut_tfim.py +131 -6
- {pyqrackising-1.12.0 → pyqrackising-1.13.1/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/pyproject.toml +2 -1
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/setup.py +1 -1
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/CMakeLists.txt +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/LICENSE.md +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/MANIFEST.in +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/spin_glass_solver.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/README.md +0 -0
- {pyqrackising-1.12.0 → pyqrackising-1.13.1}/setup.cfg +0 -0
|
@@ -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
|
-
|
|
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,57 @@ 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
|
-
|
|
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
|
+
# Warp size is 32:
|
|
295
|
+
group_size = 32
|
|
296
|
+
grid_size = (n_steps * n_qubits + group_size - 1) // group_size
|
|
297
|
+
|
|
298
|
+
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128 and (n_qubits <= 8192):
|
|
299
|
+
delta_t = 1.0 / n_steps
|
|
300
|
+
tot_t = n_steps * delta_t
|
|
301
|
+
h_mult = 32.0 / tot_t
|
|
302
|
+
|
|
303
|
+
theta = np.zeros(n_qubits)
|
|
304
|
+
for q in range(n_qubits):
|
|
305
|
+
J = J_eff[q]
|
|
306
|
+
z = degrees[q]
|
|
307
|
+
theta[q] = np.arcsin(
|
|
308
|
+
max(
|
|
309
|
+
-1.0,
|
|
310
|
+
min(
|
|
311
|
+
1.0,
|
|
312
|
+
(1.0 if J > 0.0 else -1.0) if np.isclose(abs(z * J), 0.0) else (abs(h_mult) / (z * J)),
|
|
313
|
+
),
|
|
314
|
+
)
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
cuda_maxcut_hamming_cdf[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
318
|
+
|
|
319
|
+
tot_prob = sum(thresholds)
|
|
320
|
+
thresholds /= tot_prob
|
|
321
|
+
|
|
322
|
+
tot_prob = 0.0
|
|
323
|
+
for i in range(n_bias):
|
|
324
|
+
tot_prob += thresholds[i]
|
|
325
|
+
thresholds[i] = tot_prob
|
|
326
|
+
thresholds[-1] = 1.0
|
|
327
|
+
else:
|
|
328
|
+
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
|
|
204
329
|
G_dict = nx.to_dict_of_lists(G)
|
|
205
330
|
J_max = max(J_eff)
|
|
206
331
|
weights = 1.0 / (1.0 + (J_max - J_eff))
|
|
@@ -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.
|
|
15
|
+
version = "1.13.1"
|
|
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.
|
|
54
|
+
version='1.13.1',
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|