PyQrackIsing 5.1.0__tar.gz → 5.1.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.
Files changed (27) hide show
  1. {pyqrackising-5.1.0/pyqrackising.egg-info → pyqrackising-5.1.2}/PKG-INFO +1 -1
  2. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyproject.toml +1 -1
  3. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/maxcut_tfim.py +14 -25
  4. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/maxcut_tfim_sparse.py +17 -27
  5. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/maxcut_tfim_streaming.py +15 -27
  6. pyqrackising-5.1.2/pyqrackising/maxcut_tfim_util.py +32 -0
  7. {pyqrackising-5.1.0 → pyqrackising-5.1.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  8. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising.egg-info/SOURCES.txt +1 -0
  9. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/setup.py +1 -1
  10. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/CMakeLists.txt +0 -0
  11. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/LICENSE.md +0 -0
  12. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/MANIFEST.in +0 -0
  13. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/README.md +0 -0
  14. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/__init__.py +0 -0
  15. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/_pyqrack_ising.cpp +0 -0
  16. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/generate_tfim_samples.py +0 -0
  17. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/kernels.cl +0 -0
  18. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/spin_glass_solver.py +0 -0
  19. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  20. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  21. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising/tsp.py +0 -0
  24. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  25. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  26. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/pyqrackising.egg-info/top_level.txt +0 -0
  27. {pyqrackising-5.1.0 → pyqrackising-5.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.1.0
3
+ Version: 5.1.2
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal 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 = "5.1.0"
15
+ version = "5.1.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"}
@@ -4,21 +4,11 @@ import numpy as np
4
4
  import os
5
5
  from numba import njit, prange
6
6
 
7
+ from .maxcut_tfim_util import opencl_context
7
8
 
8
9
  IS_OPENCL_AVAILABLE = True
9
- ctx = None
10
- queue = None
11
10
  try:
12
11
  import pyopencl as cl
13
-
14
- # Pick a device (GPU if available)
15
- ctx = cl.create_some_context()
16
- queue = cl.CommandQueue(ctx)
17
-
18
- # Load and build OpenCL kernels
19
- kernel_src = open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
20
- program = cl.Program(ctx, kernel_src).build()
21
- maxcut_hamming_cdf_kernel = program.maxcut_hamming_cdf
22
12
  except ImportError:
23
13
  IS_OPENCL_AVAILABLE = False
24
14
 
@@ -203,20 +193,19 @@ def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
203
193
  return best_solution, best_value
204
194
 
205
195
 
206
- @njit
196
+ @njit(parallel=True)
207
197
  def init_J_and_z(G_m):
208
198
  n_qubits = len(G_m)
209
199
  degrees = np.empty(n_qubits, dtype=np.uint32)
210
200
  J_eff = np.empty(n_qubits, dtype=np.float64)
211
201
  J_max = -float("inf")
212
- for n in range(n_qubits):
202
+ for n in prange(n_qubits):
213
203
  degree = sum(G_m[n] != 0.0)
214
204
  J = -G_m[n].sum() / degree if degree > 0 else 0
215
205
  degrees[n] = degree
216
206
  J_eff[n] = J
217
207
  J_abs = abs(J)
218
- if J_abs > J_max:
219
- J_max = J_abs
208
+ J_max = max(J_abs, J_max)
220
209
  J_eff /= J_max
221
210
 
222
211
  return J_eff, degrees
@@ -243,10 +232,10 @@ def init_thresholds(n_qubits):
243
232
  return thresholds
244
233
 
245
234
 
246
- @njit
235
+ @njit(parallel=True)
247
236
  def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
248
237
  theta = np.empty(n_qubits, dtype=np.float64)
249
- for q in range(n_qubits):
238
+ for q in prange(n_qubits):
250
239
  J = J_eff[q]
251
240
  z = degrees[q]
252
241
  theta[q] = np.arcsin(
@@ -324,20 +313,20 @@ def maxcut_tfim(
324
313
 
325
314
  # Move to GPU
326
315
  mf = cl.mem_flags
327
- args_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
328
- J_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
329
- deg_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
330
- theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
331
- ham_buf = cl.Buffer(ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
316
+ args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
317
+ J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
318
+ deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
319
+ theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
320
+ ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
332
321
 
333
322
  # Kernel execution
334
- maxcut_hamming_cdf_kernel(
335
- queue, (grid_dim,), (group_size,),
323
+ opencl_context.maxcut_hamming_cdf_kernel(
324
+ opencl_context.queue, (grid_dim,), (group_size,),
336
325
  np.int32(n_qubits), deg_buf, args_buf, J_buf, theta_buf, ham_buf
337
326
  )
338
327
 
339
328
  # Fetch results
340
- cl.enqueue_copy(queue, hamming_prob, ham_buf)
329
+ cl.enqueue_copy(opencl_context.queue, hamming_prob, ham_buf)
341
330
 
342
331
  hamming_prob /= hamming_prob.sum()
343
332
  tot_prob = 0.0
@@ -4,21 +4,11 @@ import numpy as np
4
4
  import os
5
5
  from numba import njit, prange
6
6
 
7
+ from .maxcut_tfim_util import opencl_context
7
8
 
8
9
  IS_OPENCL_AVAILABLE = True
9
- ctx = None
10
- queue = None
11
10
  try:
12
11
  import pyopencl as cl
13
-
14
- # Pick a device (GPU if available)
15
- ctx = cl.create_some_context()
16
- queue = cl.CommandQueue(ctx)
17
-
18
- # Load and build OpenCL kernels
19
- kernel_src = open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
20
- program = cl.Program(ctx, kernel_src).build()
21
- maxcut_hamming_cdf_kernel = program.maxcut_hamming_cdf
22
12
  except ImportError:
23
13
  IS_OPENCL_AVAILABLE = False
24
14
 
@@ -235,13 +225,12 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
235
225
  return best_solution, best_value
236
226
 
237
227
 
238
- @njit
228
+ @njit(parallel=True)
239
229
  def init_J_and_z(G_data, G_rows, G_cols):
240
230
  n_qubits = G_rows.shape[0] - 1
241
231
  degrees = np.empty(n_qubits, dtype=np.uint32)
242
232
  J_eff = np.empty(n_qubits, dtype=np.float64)
243
- J_max = -float("inf")
244
- for r in range(n_qubits):
233
+ for r in prange(n_qubits):
245
234
  # Row sum
246
235
  start = G_rows[r]
247
236
  end = G_rows[r + 1]
@@ -258,17 +247,18 @@ def init_J_and_z(G_data, G_rows, G_cols):
258
247
  degrees[c] += 1
259
248
  J_eff[c] += G_data[idx]
260
249
 
261
- for r in range(n_qubits):
250
+ J_max = -float("inf")
251
+ for r in prange(n_qubits):
262
252
  J = J_eff[r]
263
253
  degree = degrees[r]
264
254
  J_eff[r] = -J / degree if degree > 0 else 0
265
255
  J_abs = abs(J)
266
- if J_abs > J_max:
267
- J_max = J_abs
256
+ J_max = max(J_abs, J_max)
268
257
  J_eff /= J_max
269
258
 
270
259
  return J_eff, degrees
271
260
 
261
+
272
262
  @njit
273
263
  def init_thresholds(n_qubits):
274
264
  n_bias = n_qubits - 1
@@ -290,10 +280,10 @@ def init_thresholds(n_qubits):
290
280
  return thresholds
291
281
 
292
282
 
293
- @njit
283
+ @njit(parallel=True)
294
284
  def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
295
285
  theta = np.empty(n_qubits, dtype=np.float64)
296
- for q in range(n_qubits):
286
+ for q in prange(n_qubits):
297
287
  J = J_eff[q]
298
288
  z = degrees[q]
299
289
  theta[q] = np.arcsin(
@@ -383,20 +373,20 @@ def maxcut_tfim_sparse(
383
373
 
384
374
  # Move to GPU
385
375
  mf = cl.mem_flags
386
- args_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
387
- J_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
388
- deg_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
389
- theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
390
- ham_buf = cl.Buffer(ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
376
+ args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
377
+ J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
378
+ deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
379
+ theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
380
+ ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
391
381
 
392
382
  # Kernel execution
393
- maxcut_hamming_cdf_kernel(
394
- queue, (grid_dim,), (group_size,),
383
+ opencl_context.maxcut_hamming_cdf_kernel(
384
+ opencl_context.queue, (grid_dim,), (group_size,),
395
385
  np.int32(n_qubits), deg_buf, args_buf, J_buf, theta_buf, ham_buf
396
386
  )
397
387
 
398
388
  # Fetch results
399
- cl.enqueue_copy(queue, hamming_prob, ham_buf)
389
+ cl.enqueue_copy(opencl_context.queue, hamming_prob, ham_buf)
400
390
 
401
391
  hamming_prob /= hamming_prob.sum()
402
392
  tot_prob = 0.0
@@ -4,21 +4,11 @@ import numpy as np
4
4
  import os
5
5
  from numba import njit, prange
6
6
 
7
+ from .maxcut_tfim_util import opencl_context
7
8
 
8
9
  IS_OPENCL_AVAILABLE = True
9
- ctx = None
10
- queue = None
11
10
  try:
12
11
  import pyopencl as cl
13
-
14
- # Pick a device (GPU if available)
15
- ctx = cl.create_some_context()
16
- queue = cl.CommandQueue(ctx)
17
-
18
- # Load and build OpenCL kernels
19
- kernel_src = open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
20
- program = cl.Program(ctx, kernel_src).build()
21
- maxcut_hamming_cdf_kernel = program.maxcut_hamming_cdf
22
12
  except ImportError:
23
13
  IS_OPENCL_AVAILABLE = False
24
14
 
@@ -202,14 +192,14 @@ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thr
202
192
  return best_solution, best_value
203
193
 
204
194
 
205
- @njit
195
+ @njit(parallel=True)
206
196
  def init_J_and_z(G_func, G_func_args_tuple, nodes):
207
197
  n_qubits = len(nodes)
208
198
  degrees = np.empty(n_qubits, dtype=np.uint32)
209
199
  J_eff = np.empty(n_qubits, dtype=np.float64)
210
200
  J_max = -float("inf")
211
201
  G_max = -float("inf")
212
- for n in range(n_qubits):
202
+ for n in prange(n_qubits):
213
203
  degree = 0
214
204
  J = 0.0
215
205
  for m in range(n_qubits):
@@ -217,14 +207,12 @@ def init_J_and_z(G_func, G_func_args_tuple, nodes):
217
207
  if val != 0.0:
218
208
  degree += 1
219
209
  J += val
220
- if val > G_max:
221
- G_max = val
210
+ G_max = max(val, G_max)
222
211
  J = -J / degree if degree > 0 else 0
223
212
  degrees[n] = degree
224
213
  J_eff[n] = J
225
214
  J_abs = abs(J)
226
- if J_abs > J_max:
227
- J_max = J_abs
215
+ J_max = max(J_abs, J_max)
228
216
  J_eff /= J_max
229
217
 
230
218
  return J_eff, degrees, G_max
@@ -251,10 +239,10 @@ def init_thresholds(n_qubits):
251
239
  return thresholds
252
240
 
253
241
 
254
- @njit
242
+ @njit(parallel=True)
255
243
  def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
256
244
  theta = np.empty(n_qubits, dtype=np.float64)
257
- for q in range(n_qubits):
245
+ for q in prange(n_qubits):
258
246
  J = J_eff[q]
259
247
  z = degrees[q]
260
248
  theta[q] = np.arcsin(
@@ -324,20 +312,20 @@ def maxcut_tfim_streaming(
324
312
 
325
313
  # Move to GPU
326
314
  mf = cl.mem_flags
327
- args_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
328
- J_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
329
- deg_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
330
- theta_buf = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
331
- ham_buf = cl.Buffer(ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
315
+ args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
316
+ J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
317
+ deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
318
+ theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=theta)
319
+ ham_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=hamming_prob)
332
320
 
333
321
  # Kernel execution
334
- maxcut_hamming_cdf_kernel(
335
- queue, (grid_dim,), (group_size,),
322
+ opencl_context.maxcut_hamming_cdf_kernel(
323
+ opencl_context.queue, (grid_dim,), (group_size,),
336
324
  np.int32(n_qubits), deg_buf, args_buf, J_buf, theta_buf, ham_buf
337
325
  )
338
326
 
339
327
  # Fetch results
340
- cl.enqueue_copy(queue, hamming_prob, ham_buf)
328
+ cl.enqueue_copy(opencl_context.queue, hamming_prob, ham_buf)
341
329
 
342
330
  hamming_prob /= hamming_prob.sum()
343
331
  tot_prob = 0.0
@@ -0,0 +1,32 @@
1
+ import math
2
+ import networkx as nx
3
+ import numpy as np
4
+ import os
5
+ from numba import njit, prange
6
+
7
+
8
+ class OpenCLContext:
9
+ def __init__(self, a, c, q, k):
10
+ self.IS_OPENCL_AVAILABLE = a
11
+ self.ctx = c
12
+ self.queue = q
13
+ self.maxcut_hamming_cdf_kernel = k
14
+
15
+ IS_OPENCL_AVAILABLE = True
16
+ ctx = None
17
+ queue = None
18
+ try:
19
+ import pyopencl as cl
20
+
21
+ # Pick a device (GPU if available)
22
+ ctx = cl.create_some_context()
23
+ queue = cl.CommandQueue(ctx)
24
+
25
+ # Load and build OpenCL kernels
26
+ kernel_src = open(os.path.dirname(os.path.abspath(__file__)) + "/kernels.cl").read()
27
+ program = cl.Program(ctx, kernel_src).build()
28
+ maxcut_hamming_cdf_kernel = program.maxcut_hamming_cdf
29
+ except ImportError:
30
+ IS_OPENCL_AVAILABLE = False
31
+
32
+ opencl_context = OpenCLContext(IS_OPENCL_AVAILABLE, ctx, queue, maxcut_hamming_cdf_kernel)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 5.1.0
3
+ Version: 5.1.2
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -11,6 +11,7 @@ pyqrackising/kernels.cl
11
11
  pyqrackising/maxcut_tfim.py
12
12
  pyqrackising/maxcut_tfim_sparse.py
13
13
  pyqrackising/maxcut_tfim_streaming.py
14
+ pyqrackising/maxcut_tfim_util.py
14
15
  pyqrackising/spin_glass_solver.py
15
16
  pyqrackising/spin_glass_solver_sparse.py
16
17
  pyqrackising/spin_glass_solver_streaming.py
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='5.1.0',
54
+ version='5.1.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