PyQrackIsing 5.4.1__tar.gz → 5.4.2__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-5.4.1/pyqrackising.egg-info → pyqrackising-5.4.2}/PKG-INFO +1 -1
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/README.md +1 -1
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyproject.toml +1 -1
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/kernels.cl +28 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/maxcut_tfim.py +21 -9
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/maxcut_tfim_sparse.py +21 -9
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/maxcut_tfim_streaming.py +21 -9
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/maxcut_tfim_util.py +6 -3
- {pyqrackising-5.4.1 → pyqrackising-5.4.2/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/setup.py +1 -1
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/CMakeLists.txt +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/LICENSE.md +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/MANIFEST.in +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/__init__.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising/tsp.py +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-5.4.1 → pyqrackising-5.4.2}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "5.4.
|
|
15
|
+
version = "5.4.2"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
18
18
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
__kernel void init_theta(
|
|
2
|
+
__constant float* fargs,
|
|
3
|
+
const int n_qubits,
|
|
4
|
+
__constant float* J_eff,
|
|
5
|
+
__constant float* degrees,
|
|
6
|
+
__global float* theta
|
|
7
|
+
) {
|
|
8
|
+
const int q = get_global_id(0);
|
|
9
|
+
if (q >= n_qubits) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const float h_mult = fabs(fargs[2]);
|
|
14
|
+
|
|
15
|
+
const float J = J_eff[q];
|
|
16
|
+
const float z = degrees[q];
|
|
17
|
+
const float abs_zJ = fabs(z * J);
|
|
18
|
+
|
|
19
|
+
float val;
|
|
20
|
+
if (abs_zJ < 2e-40f) {
|
|
21
|
+
val = (J > 0.0f) ? M_PI_F : -M_PI_F;
|
|
22
|
+
} else {
|
|
23
|
+
val = asin(fmax(-1.0f, fmin(1.0f, h_mult / (z * J))));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
theta[q] = val;
|
|
27
|
+
}
|
|
28
|
+
|
|
1
29
|
// By Google Search AI
|
|
2
30
|
inline void AtomicAdd_g_f(volatile __global float *source, const float operand) {
|
|
3
31
|
union {
|
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
|
4
4
|
import os
|
|
5
5
|
from numba import njit, prange
|
|
6
6
|
|
|
7
|
-
from .maxcut_tfim_util import get_cut,
|
|
7
|
+
from .maxcut_tfim_util import get_cut, init_thresholds, maxcut_hamming_cdf, opencl_context, probability_by_hamming_weight
|
|
8
8
|
|
|
9
9
|
IS_OPENCL_AVAILABLE = True
|
|
10
10
|
try:
|
|
@@ -82,7 +82,7 @@ def compute_energy(sample, G_m, n_qubits):
|
|
|
82
82
|
def sample_for_solution(G_m, shots, thresholds, J_eff):
|
|
83
83
|
n = len(G_m)
|
|
84
84
|
max_weight = G_m.max()
|
|
85
|
-
weights = (1.0 / (1.0 + (
|
|
85
|
+
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
86
86
|
|
|
87
87
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
88
88
|
energies = np.empty(shots, dtype=np.float32)
|
|
@@ -205,17 +205,34 @@ def maxcut_tfim(
|
|
|
205
205
|
return cpu_footer(shots, quality, n_qubits, G_m, nodes)
|
|
206
206
|
|
|
207
207
|
J_eff, degrees = init_J_and_z(G_m)
|
|
208
|
-
hamming_prob = init_thresholds(n_qubits)
|
|
209
208
|
|
|
210
209
|
delta_t = 1.0 / n_steps
|
|
211
210
|
tot_t = 2.0 * n_steps * delta_t
|
|
212
211
|
h_mult = 2.0 / tot_t
|
|
213
|
-
|
|
212
|
+
|
|
214
213
|
args = np.empty(3, dtype=np.float32)
|
|
215
214
|
args[0] = delta_t
|
|
216
215
|
args[1] = tot_t
|
|
217
216
|
args[2] = h_mult
|
|
218
217
|
|
|
218
|
+
# Move to GPU
|
|
219
|
+
mf = cl.mem_flags
|
|
220
|
+
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
221
|
+
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
222
|
+
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
223
|
+
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * 4))
|
|
224
|
+
|
|
225
|
+
# Warp size is 32:
|
|
226
|
+
group_size = min(n_qubits, 64)
|
|
227
|
+
global_size = ((n_qubits + group_size - 1) // group_size) * group_size
|
|
228
|
+
|
|
229
|
+
opencl_context.init_theta_kernel(
|
|
230
|
+
opencl_context.queue, (global_size,), (group_size,),
|
|
231
|
+
args_buf, np.int32(n_qubits), J_buf, deg_buf, theta_buf
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
hamming_prob = init_thresholds(n_qubits)
|
|
235
|
+
|
|
219
236
|
# Warp size is 32:
|
|
220
237
|
group_size = n_qubits - 1
|
|
221
238
|
if group_size > 256:
|
|
@@ -223,11 +240,6 @@ def maxcut_tfim(
|
|
|
223
240
|
grid_dim = n_steps * n_qubits * group_size
|
|
224
241
|
|
|
225
242
|
# Move to GPU
|
|
226
|
-
mf = cl.mem_flags
|
|
227
|
-
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
228
|
-
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
229
|
-
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
230
|
-
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
|
|
231
243
|
ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
|
|
232
244
|
|
|
233
245
|
# Kernel execution
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
from numba import njit, prange
|
|
6
6
|
from scipy.sparse import lil_matrix, csr_matrix
|
|
7
7
|
|
|
8
|
-
from .maxcut_tfim_util import get_cut,
|
|
8
|
+
from .maxcut_tfim_util import get_cut, init_thresholds, maxcut_hamming_cdf, opencl_context, probability_by_hamming_weight
|
|
9
9
|
|
|
10
10
|
IS_OPENCL_AVAILABLE = True
|
|
11
11
|
try:
|
|
@@ -114,7 +114,7 @@ def compute_energy(sample, G_data, G_rows, G_cols):
|
|
|
114
114
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
115
115
|
n = G_rows.shape[0] - 1
|
|
116
116
|
max_weight = G_data.max()
|
|
117
|
-
weights = (1.0 / (1.0 + (
|
|
117
|
+
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
118
118
|
|
|
119
119
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
120
120
|
energies = np.empty(shots, dtype=np.float32)
|
|
@@ -264,17 +264,34 @@ def maxcut_tfim_sparse(
|
|
|
264
264
|
return cpu_footer(shots, quality, n_qubits, G_m.data, G_m.indptr, G_m.indices, nodes)
|
|
265
265
|
|
|
266
266
|
J_eff, degrees = init_J_and_z(G_m.data, G_m.indptr, G_m.indices)
|
|
267
|
-
hamming_prob = init_thresholds(n_qubits)
|
|
268
267
|
|
|
269
268
|
delta_t = 1.0 / n_steps
|
|
270
269
|
tot_t = 2.0 * n_steps * delta_t
|
|
271
270
|
h_mult = 2.0 / tot_t
|
|
272
|
-
|
|
271
|
+
|
|
273
272
|
args = np.empty(3, dtype=np.float32)
|
|
274
273
|
args[0] = delta_t
|
|
275
274
|
args[1] = tot_t
|
|
276
275
|
args[2] = h_mult
|
|
277
276
|
|
|
277
|
+
# Move to GPU
|
|
278
|
+
mf = cl.mem_flags
|
|
279
|
+
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
280
|
+
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
281
|
+
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
282
|
+
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * 4))
|
|
283
|
+
|
|
284
|
+
# Warp size is 32:
|
|
285
|
+
group_size = min(n_qubits, 64)
|
|
286
|
+
global_size = ((n_qubits + group_size - 1) // group_size) * group_size
|
|
287
|
+
|
|
288
|
+
opencl_context.init_theta_kernel(
|
|
289
|
+
opencl_context.queue, (global_size,), (group_size,),
|
|
290
|
+
args_buf, np.int32(n_qubits), J_buf, deg_buf, theta_buf
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
hamming_prob = init_thresholds(n_qubits)
|
|
294
|
+
|
|
278
295
|
# Warp size is 32:
|
|
279
296
|
group_size = n_qubits - 1
|
|
280
297
|
if group_size > 256:
|
|
@@ -282,11 +299,6 @@ def maxcut_tfim_sparse(
|
|
|
282
299
|
grid_dim = n_steps * n_qubits * group_size
|
|
283
300
|
|
|
284
301
|
# Move to GPU
|
|
285
|
-
mf = cl.mem_flags
|
|
286
|
-
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
287
|
-
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
288
|
-
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
289
|
-
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
|
|
290
302
|
ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
|
|
291
303
|
|
|
292
304
|
# Kernel execution
|
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
|
4
4
|
import os
|
|
5
5
|
from numba import njit, prange
|
|
6
6
|
|
|
7
|
-
from .maxcut_tfim_util import get_cut,
|
|
7
|
+
from .maxcut_tfim_util import get_cut, init_thresholds, maxcut_hamming_cdf, opencl_context, probability_by_hamming_weight
|
|
8
8
|
|
|
9
9
|
IS_OPENCL_AVAILABLE = True
|
|
10
10
|
try:
|
|
@@ -80,7 +80,7 @@ def compute_energy(sample, G_func, G_func_args_tuple, nodes, n_qubits):
|
|
|
80
80
|
|
|
81
81
|
@njit(parallel=True)
|
|
82
82
|
def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thresholds, degrees_sum, J_eff, n):
|
|
83
|
-
weights = (1.0 / (1.0 + (
|
|
83
|
+
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
84
84
|
|
|
85
85
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
86
86
|
energies = np.empty(shots, dtype=np.float32)
|
|
@@ -203,17 +203,34 @@ def maxcut_tfim_streaming(
|
|
|
203
203
|
return cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes)
|
|
204
204
|
|
|
205
205
|
J_eff, degrees, G_max = init_J_and_z(G_func, G_func_args_tuple, nodes)
|
|
206
|
-
hamming_prob = init_thresholds(n_qubits)
|
|
207
206
|
|
|
208
207
|
delta_t = 1.0 / n_steps
|
|
209
208
|
tot_t = 2.0 * n_steps * delta_t
|
|
210
209
|
h_mult = 2.0 / tot_t
|
|
211
|
-
|
|
210
|
+
|
|
212
211
|
args = np.empty(3, dtype=np.float32)
|
|
213
212
|
args[0] = delta_t
|
|
214
213
|
args[1] = tot_t
|
|
215
214
|
args[2] = h_mult
|
|
216
215
|
|
|
216
|
+
# Move to GPU
|
|
217
|
+
mf = cl.mem_flags
|
|
218
|
+
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
219
|
+
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
220
|
+
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
221
|
+
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * 4))
|
|
222
|
+
|
|
223
|
+
# Warp size is 32:
|
|
224
|
+
group_size = min(n_qubits, 64)
|
|
225
|
+
global_size = ((n_qubits + group_size - 1) // group_size) * group_size
|
|
226
|
+
|
|
227
|
+
opencl_context.init_theta_kernel(
|
|
228
|
+
opencl_context.queue, (global_size,), (group_size,),
|
|
229
|
+
args_buf, np.int32(n_qubits), J_buf, deg_buf, theta_buf
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
hamming_prob = init_thresholds(n_qubits)
|
|
233
|
+
|
|
217
234
|
# Warp size is 32:
|
|
218
235
|
group_size = n_qubits - 1
|
|
219
236
|
if group_size > 256:
|
|
@@ -221,11 +238,6 @@ def maxcut_tfim_streaming(
|
|
|
221
238
|
grid_dim = n_steps * n_qubits * group_size
|
|
222
239
|
|
|
223
240
|
# Move to GPU
|
|
224
|
-
mf = cl.mem_flags
|
|
225
|
-
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
226
|
-
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
227
|
-
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
228
|
-
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
|
|
229
241
|
ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
|
|
230
242
|
|
|
231
243
|
# Kernel execution
|
|
@@ -21,7 +21,7 @@ def get_cut(solution, nodes):
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
@njit(parallel=True)
|
|
24
|
-
def init_theta(
|
|
24
|
+
def init_theta(h_mult, n_qubits, J_eff, degrees):
|
|
25
25
|
theta = np.empty(n_qubits, dtype=np.float32)
|
|
26
26
|
h_mult = abs(h_mult)
|
|
27
27
|
for q in prange(n_qubits):
|
|
@@ -133,10 +133,11 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
class OpenCLContext:
|
|
136
|
-
def __init__(self, a, c, q, m, b, s):
|
|
136
|
+
def __init__(self, a, c, q, i, m, b, s):
|
|
137
137
|
self.IS_OPENCL_AVAILABLE = a
|
|
138
138
|
self.ctx = c
|
|
139
139
|
self.queue = q
|
|
140
|
+
self.init_theta_kernel = i
|
|
140
141
|
self.maxcut_hamming_cdf_kernel = m
|
|
141
142
|
self.bootstrap_kernel = b
|
|
142
143
|
self.bootstrap_sparse_kernel = s
|
|
@@ -144,6 +145,7 @@ class OpenCLContext:
|
|
|
144
145
|
IS_OPENCL_AVAILABLE = True
|
|
145
146
|
ctx = None
|
|
146
147
|
queue = None
|
|
148
|
+
init_theta_kernel = None
|
|
147
149
|
maxcut_hamming_cdf_kernel = None
|
|
148
150
|
bootstrap_kernel = None
|
|
149
151
|
bootstrap_sparse_kernel = None
|
|
@@ -157,6 +159,7 @@ try:
|
|
|
157
159
|
# Load and build OpenCL kernels
|
|
158
160
|
kernel_src = open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
|
|
159
161
|
program = cl.Program(ctx, kernel_src).build()
|
|
162
|
+
init_theta_kernel = program.init_theta
|
|
160
163
|
maxcut_hamming_cdf_kernel = program.maxcut_hamming_cdf
|
|
161
164
|
bootstrap_kernel = program.bootstrap
|
|
162
165
|
bootstrap_sparse_kernel = program.bootstrap_sparse
|
|
@@ -164,4 +167,4 @@ except ImportError:
|
|
|
164
167
|
IS_OPENCL_AVAILABLE = False
|
|
165
168
|
print("PyOpenCL not installed. (If you have any OpenCL accelerator devices with available ICDs, you might want to optionally install pyopencl.)")
|
|
166
169
|
|
|
167
|
-
opencl_context = OpenCLContext(IS_OPENCL_AVAILABLE, ctx, queue, maxcut_hamming_cdf_kernel, bootstrap_kernel, bootstrap_sparse_kernel)
|
|
170
|
+
opencl_context = OpenCLContext(IS_OPENCL_AVAILABLE, ctx, queue, init_theta_kernel, maxcut_hamming_cdf_kernel, bootstrap_kernel, bootstrap_sparse_kernel)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='5.4.
|
|
54
|
+
version='5.4.2',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
57
|
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
|
|
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
|