PyQrackIsing 1.14.2__tar.gz → 1.14.3__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.14.2/PyQrackIsing.egg-info → pyqrackising-1.14.3}/PKG-INFO +1 -1
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/maxcut_tfim.py +30 -175
- {pyqrackising-1.14.2 → pyqrackising-1.14.3/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/pyproject.toml +1 -1
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/setup.py +1 -1
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/CMakeLists.txt +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/LICENSE.md +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/MANIFEST.in +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/spin_glass_solver.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/README.md +0 -0
- {pyqrackising-1.14.2 → pyqrackising-1.14.3}/setup.cfg +0 -0
|
@@ -11,17 +11,12 @@ try:
|
|
|
11
11
|
warnings.simplefilter('ignore', category=NumbaPerformanceWarning)
|
|
12
12
|
|
|
13
13
|
@cuda.jit(device=True)
|
|
14
|
-
def cuda_probability_by_hamming_weight(J, h, z, theta, t, n_qubits, bias):
|
|
14
|
+
def cuda_probability_by_hamming_weight(q, J, h, z, theta, t, n_qubits, bias):
|
|
15
|
+
if J > 0.0:
|
|
16
|
+
q = n_qubits - (2 + q)
|
|
17
|
+
|
|
15
18
|
# 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
|
-
)
|
|
19
|
+
theta_c = np.arcsin(max(-1.0, min(1.0, abs(h) / (z * J))))
|
|
25
20
|
|
|
26
21
|
p = (
|
|
27
22
|
pow(2.0, abs(J / h) - 1.0)
|
|
@@ -30,165 +25,32 @@ try:
|
|
|
30
25
|
)
|
|
31
26
|
|
|
32
27
|
if (p * n_qubits) >= 1024:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
53
|
-
@cuda.jit
|
|
54
|
-
def cuda_maxcut_hamming_cdf_256(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
55
|
-
qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
|
|
56
|
-
step = qc // n_qubits
|
|
57
|
-
q = qc % n_qubits
|
|
58
|
-
|
|
59
|
-
if step >= n_steps:
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
J_eff = J_func[q]
|
|
63
|
-
if abs(J_eff) <= (2 ** (-54)):
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
z = degrees[q]
|
|
67
|
-
theta_eff = theta[q]
|
|
68
|
-
t = step * delta_t
|
|
69
|
-
tm1 = (step - 1) * delta_t
|
|
70
|
-
h_t = h_mult * (tot_t - t)
|
|
71
|
-
n_bias = n_qubits - 1
|
|
72
|
-
|
|
73
|
-
bias = cuda.local.array(shape=(256,), dtype=types.float64)
|
|
74
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
75
|
-
last_bias = cuda.local.array(shape=(256,), dtype=types.float64)
|
|
76
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, last_bias)
|
|
77
|
-
for i in range(n_qubits - 1):
|
|
78
|
-
hamming_prob[i] += bias[i] - last_bias[i]
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@cuda.jit
|
|
82
|
-
def cuda_maxcut_hamming_cdf_512(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
83
|
-
qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
|
|
84
|
-
step = qc // n_qubits
|
|
85
|
-
q = qc % n_qubits
|
|
86
|
-
|
|
87
|
-
if step >= n_steps:
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
J_eff = J_func[q]
|
|
91
|
-
if abs(J_eff) <= (2 ** (-54)):
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
z = degrees[q]
|
|
95
|
-
theta_eff = theta[q]
|
|
96
|
-
t = step * delta_t
|
|
97
|
-
tm1 = (step - 1) * delta_t
|
|
98
|
-
h_t = h_mult * (tot_t - t)
|
|
99
|
-
n_bias = n_qubits - 1
|
|
100
|
-
|
|
101
|
-
bias = cuda.local.array(shape=(512,), dtype=types.float64)
|
|
102
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
103
|
-
last_bias = cuda.local.array(shape=(512,), dtype=types.float64)
|
|
104
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, last_bias)
|
|
105
|
-
for i in range(n_qubits - 1):
|
|
106
|
-
hamming_prob[i] += bias[i] - last_bias[i]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@cuda.jit
|
|
110
|
-
def cuda_maxcut_hamming_cdf_1024(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
111
|
-
qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
|
|
112
|
-
step = qc // n_qubits
|
|
113
|
-
q = qc % n_qubits
|
|
114
|
-
|
|
115
|
-
if step >= n_steps:
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
J_eff = J_func[q]
|
|
119
|
-
if abs(J_eff) <= (2 ** (-54)):
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
z = degrees[q]
|
|
123
|
-
theta_eff = theta[q]
|
|
124
|
-
t = step * delta_t
|
|
125
|
-
tm1 = (step - 1) * delta_t
|
|
126
|
-
h_t = h_mult * (tot_t - t)
|
|
127
|
-
n_bias = n_qubits - 1
|
|
128
|
-
|
|
129
|
-
bias = cuda.local.array(shape=(1024,), dtype=types.float64)
|
|
130
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
131
|
-
last_bias = cuda.local.array(shape=(1024,), dtype=types.float64)
|
|
132
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, last_bias)
|
|
133
|
-
for i in range(n_qubits - 1):
|
|
134
|
-
hamming_prob[i] += bias[i] - last_bias[i]
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
@cuda.jit
|
|
138
|
-
def cuda_maxcut_hamming_cdf_2048(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
139
|
-
qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
|
|
140
|
-
step = qc // n_qubits
|
|
141
|
-
q = qc % n_qubits
|
|
142
|
-
|
|
143
|
-
if step >= n_steps:
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
J_eff = J_func[q]
|
|
147
|
-
if abs(J_eff) <= (2 ** (-54)):
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
z = degrees[q]
|
|
151
|
-
theta_eff = theta[q]
|
|
152
|
-
t = step * delta_t
|
|
153
|
-
tm1 = (step - 1) * delta_t
|
|
154
|
-
h_t = h_mult * (tot_t - t)
|
|
155
|
-
n_bias = n_qubits - 1
|
|
156
|
-
|
|
157
|
-
bias = cuda.local.array(shape=(2048,), dtype=types.float64)
|
|
158
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
159
|
-
last_bias = cuda.local.array(shape=(2048,), dtype=types.float64)
|
|
160
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, last_bias)
|
|
161
|
-
for i in range(n_qubits - 1):
|
|
162
|
-
hamming_prob[i] += bias[i] - last_bias[i]
|
|
163
|
-
|
|
28
|
+
bias[q] = 0.0
|
|
29
|
+
else:
|
|
30
|
+
norm = pow(2.0, -(n_qubits + 1) * p) * (pow(2.0, (n_qubits + 2) * p) - 1.0) / (pow(2, p) - 1.0)
|
|
31
|
+
bias[q] = 1.0 / pow(2.0, p * q) / norm
|
|
164
32
|
|
|
165
33
|
@cuda.jit
|
|
166
|
-
def
|
|
167
|
-
|
|
168
|
-
step =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
34
|
+
def cuda_maxcut_hamming_cdf(delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
35
|
+
bias = cuda.shared.array(0, dtype=np.float64)
|
|
36
|
+
step = cuda.blockIdx.x
|
|
37
|
+
qi = cuda.blockIdx.y
|
|
38
|
+
J_eff = J_func[qi]
|
|
39
|
+
z = degrees[qi]
|
|
40
|
+
if abs(z * J_eff) <= (2 ** (-54)):
|
|
172
41
|
return
|
|
173
42
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
z = degrees[q]
|
|
179
|
-
theta_eff = theta[q]
|
|
43
|
+
n_qubits = cuda.gridDim.y
|
|
44
|
+
theta_eff = theta[qi]
|
|
180
45
|
t = step * delta_t
|
|
181
46
|
tm1 = (step - 1) * delta_t
|
|
182
47
|
h_t = h_mult * (tot_t - t)
|
|
183
|
-
n_bias = n_qubits - 1
|
|
184
48
|
|
|
185
|
-
|
|
186
|
-
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
for i in range(n_qubits - 1):
|
|
191
|
-
hamming_prob[i] -= bias[i]
|
|
49
|
+
qo = cuda.threadIdx.x
|
|
50
|
+
cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
51
|
+
hamming_prob[qo] += bias[qo]
|
|
52
|
+
cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff, tm1, n_qubits, bias)
|
|
53
|
+
hamming_prob[qo] -= bias[qo]
|
|
192
54
|
|
|
193
55
|
except:
|
|
194
56
|
IS_CUDA_AVAILABLE = False
|
|
@@ -371,17 +233,19 @@ def maxcut_tfim(
|
|
|
371
233
|
return "0", 0, ([nodes[0]], [])
|
|
372
234
|
|
|
373
235
|
# Warp size is 32:
|
|
374
|
-
group_size =
|
|
236
|
+
group_size = n_qubits - 1
|
|
237
|
+
shared_size = (n_qubits - 1) * 8
|
|
375
238
|
|
|
376
239
|
if quality is None:
|
|
377
|
-
quality =
|
|
240
|
+
quality = math.ceil(math.log2(128 * group_size))
|
|
378
241
|
|
|
379
242
|
if shots is None:
|
|
380
243
|
# Number of measurement shots
|
|
381
244
|
shots = n_qubits << quality
|
|
382
245
|
|
|
383
246
|
n_steps = 1 << quality
|
|
384
|
-
grid_size =
|
|
247
|
+
grid_size = n_steps * n_qubits
|
|
248
|
+
grid_dims = (n_steps, n_qubits)
|
|
385
249
|
|
|
386
250
|
J_eff = np.array(
|
|
387
251
|
[
|
|
@@ -413,7 +277,7 @@ def maxcut_tfim(
|
|
|
413
277
|
tot_prob += n
|
|
414
278
|
thresholds /= tot_prob
|
|
415
279
|
|
|
416
|
-
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128
|
|
280
|
+
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128:
|
|
417
281
|
delta_t = 1.0 / n_steps
|
|
418
282
|
tot_t = n_steps * delta_t
|
|
419
283
|
h_mult = 32.0 / tot_t
|
|
@@ -432,16 +296,7 @@ def maxcut_tfim(
|
|
|
432
296
|
)
|
|
433
297
|
)
|
|
434
298
|
|
|
435
|
-
|
|
436
|
-
cuda_maxcut_hamming_cdf_256[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
437
|
-
elif n_qubits <= 512:
|
|
438
|
-
cuda_maxcut_hamming_cdf_512[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
439
|
-
elif n_qubits <= 1024:
|
|
440
|
-
cuda_maxcut_hamming_cdf_1024[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
441
|
-
elif n_qubits <= 2048:
|
|
442
|
-
cuda_maxcut_hamming_cdf_2048[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
443
|
-
else:
|
|
444
|
-
cuda_maxcut_hamming_cdf_large[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
299
|
+
cuda_maxcut_hamming_cdf[grid_dims, group_size, 0, shared_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
445
300
|
|
|
446
301
|
tot_prob = sum(thresholds)
|
|
447
302
|
thresholds /= tot_prob
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.14.
|
|
15
|
+
version = "1.14.3"
|
|
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.14.
|
|
54
|
+
version='1.14.3',
|
|
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
|