PyQrackIsing 8.14.9__tar.gz → 8.15.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-8.14.9/pyqrackising.egg-info → pyqrackising-8.15.1}/PKG-INFO +1 -1
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/README.md +4 -4
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyproject.toml +1 -1
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/maxcut_tfim.py +3 -3
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/maxcut_tfim_sparse.py +3 -3
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/maxcut_tfim_streaming.py +2 -2
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/spin_glass_solver.py +13 -6
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/spin_glass_solver_sparse.py +13 -6
- {pyqrackising-8.14.9 → pyqrackising-8.15.1/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/setup.py +1 -1
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/LICENSE.md +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/MANIFEST.in +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/__init__.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/tsp.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-8.14.9 → pyqrackising-8.15.1}/setup.cfg +0 -0
|
@@ -50,10 +50,10 @@ from pyqrackising import maxcut_tfim
|
|
|
50
50
|
import networkx as nx
|
|
51
51
|
|
|
52
52
|
G = nx.petersen_graph()
|
|
53
|
-
best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=
|
|
53
|
+
best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=6, shots=None, is_spin_glass=False, anneal_t=8.0, anneal_h=8.0, repulsion_base=5.0)
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs), and `maxcut_tfim_streaming(G_func, nodes)` for `numba` JIT streaming weights function definitions. The (integer) `quality` setting is optional, with a default value of `
|
|
56
|
+
We also provide `maxcut_tfim_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs), and `maxcut_tfim_streaming(G_func, nodes)` for `numba` JIT streaming weights function definitions. The (integer) `quality` setting is optional, with a default value of `6`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) `anneal_t` and `anneal_h` control the physical maximum annealing time and `h` transverse field parameter, as in Trotterized Ising model. While `anneal_t` and `anneal_h` control how annealing finds the _Hamming weight_ of cuts (i.e., how many nodes end up in either partition), `repulsion_base` similarly controls the steepness of the search basin for optimizing bit-string locality ("like-like" repulsion and "like-unlike" attraction) within each partition. If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
|
|
57
57
|
|
|
58
58
|
Based on a combination of the TFIM-inspired MAXCUT solver and another technique for finding ground-state energy in quantum chemistry that we call the _"binary Clifford eigensolver,"_ we also provide an (approximate) spin glass ground-state solver:
|
|
59
59
|
```py
|
|
@@ -73,10 +73,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
G = generate_spin_glass_graph(n_nodes=64, seed=42)
|
|
76
|
-
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=
|
|
76
|
+
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=6, shots=None, anneal_t=8.0, anneal_h=8.0, is_spin_glass=True, best_guess=None, is_combo_maxcut_gpu=True, min_order=1, max_order=None, reheat_tries=0)
|
|
77
77
|
# solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=6)[0])
|
|
78
78
|
```
|
|
79
|
-
We also provide `spin_glass_solver_sparse(G)` and `spin_glass_solver_streaming(G_func, nodes)`. `is_combo_maxcut_gpu` controls whether gradient descent optimization is done on GPU (which is costly and the only GPU-based feature). `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. `min_order` determines the minimum order of local search and defaults to `1`, meaning it will perform a local search on at least single nodes (or `2` for pairs of nodes, or `3` for triplets of nodes, etc). `max_order` sets a ceiling on adaptive search for productive local search "order," and defaults to `None` for no ceiling. After the initial optimization round, `reheat_tries` will randomly flip `log2(n)` bits out of `n` count of total nodes and re-optimize, similar to "simulated annealing," for as many additional rounds as the `reheat_tries` value (which defaults to `0`). This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
|
|
79
|
+
We also provide `spin_glass_solver_sparse(G)` and `spin_glass_solver_streaming(G_func, nodes)`. `is_combo_maxcut_gpu` controls whether gradient descent optimization is done on GPU (which is costly and the only GPU-based feature). `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. `min_order` determines the minimum order of local search and defaults to `1`, meaning it will perform a local search on at least single nodes (or `2` for pairs of nodes, or `3` for triplets of nodes, etc). `max_order` sets a ceiling on adaptive search for productive local search "order," and defaults to `None` for no ceiling. After the initial optimization round, `reheat_tries` will randomly flip `log2(n)` bits out of `n` count of total nodes and re-optimize, similar to "simulated annealing," for as many additional rounds as the `reheat_tries` value (which defaults to `0`). `is_spin_glass` controls whether the solver optimizes for cut value or spin-glass energy. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
|
|
80
80
|
|
|
81
81
|
From the MAXCUT solvers, we provide a (recursive) Traveling Salesman Problem (TSP) solver:
|
|
82
82
|
```py
|
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "pyqrackising"
|
|
13
|
-
version = "8.
|
|
13
|
+
version = "8.15.1"
|
|
14
14
|
requires-python = ">=3.8"
|
|
15
15
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
16
16
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -252,7 +252,7 @@ def run_cut_opencl(best_energy, samples, G_m_buf, is_segmented, segment_size, is
|
|
|
252
252
|
best_x = np.argmax(max_energy_host)
|
|
253
253
|
energy = max_energy_host[best_x]
|
|
254
254
|
|
|
255
|
-
if energy
|
|
255
|
+
if energy <= best_energy:
|
|
256
256
|
# No improvement: we can exit early
|
|
257
257
|
return samples[0], max_energy_host[0]
|
|
258
258
|
|
|
@@ -301,7 +301,7 @@ def maxcut_tfim(
|
|
|
301
301
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
302
302
|
|
|
303
303
|
if quality is None:
|
|
304
|
-
quality =
|
|
304
|
+
quality = 6
|
|
305
305
|
|
|
306
306
|
if shots is None:
|
|
307
307
|
# Number of measurement shots
|
|
@@ -314,7 +314,7 @@ def maxcut_tfim(
|
|
|
314
314
|
anneal_h = 8.0
|
|
315
315
|
|
|
316
316
|
if repulsion_base is None:
|
|
317
|
-
repulsion_base =
|
|
317
|
+
repulsion_base = 5.0
|
|
318
318
|
|
|
319
319
|
is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
|
|
320
320
|
|
|
@@ -266,7 +266,7 @@ def run_cut_opencl(best_energy, samples, G_data_buf, G_rows_buf, G_cols_buf, is_
|
|
|
266
266
|
best_x = np.argmax(max_energy_host)
|
|
267
267
|
energy = max_energy_host[best_x]
|
|
268
268
|
|
|
269
|
-
if energy
|
|
269
|
+
if energy <= best_energy:
|
|
270
270
|
# No improvement: we can exit early
|
|
271
271
|
return samples[0], max_energy_host[0]
|
|
272
272
|
|
|
@@ -316,7 +316,7 @@ def maxcut_tfim_sparse(
|
|
|
316
316
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
317
317
|
|
|
318
318
|
if quality is None:
|
|
319
|
-
quality =
|
|
319
|
+
quality = 6
|
|
320
320
|
|
|
321
321
|
if shots is None:
|
|
322
322
|
# Number of measurement shots
|
|
@@ -329,7 +329,7 @@ def maxcut_tfim_sparse(
|
|
|
329
329
|
anneal_h = 8.0
|
|
330
330
|
|
|
331
331
|
if repulsion_base is None:
|
|
332
|
-
repulsion_base =
|
|
332
|
+
repulsion_base = 5.0
|
|
333
333
|
|
|
334
334
|
J_eff, degrees = init_J_and_z(G_m, repulsion_base)
|
|
335
335
|
|
|
@@ -197,7 +197,7 @@ def maxcut_tfim_streaming(
|
|
|
197
197
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
198
198
|
|
|
199
199
|
if quality is None:
|
|
200
|
-
quality =
|
|
200
|
+
quality = 6
|
|
201
201
|
|
|
202
202
|
if shots is None:
|
|
203
203
|
# Number of measurement shots
|
|
@@ -210,7 +210,7 @@ def maxcut_tfim_streaming(
|
|
|
210
210
|
anneal_h = 8.0
|
|
211
211
|
|
|
212
212
|
if repulsion_base is None:
|
|
213
|
-
repulsion_base =
|
|
213
|
+
repulsion_base = 5.0
|
|
214
214
|
|
|
215
215
|
G_min = find_G_min(G_func, nodes, n_qubits)
|
|
216
216
|
|
|
@@ -65,7 +65,7 @@ def bootstrap(best_theta, G_m, indices_array, k, min_energy, dtype, is_spin_glas
|
|
|
65
65
|
return min_energy
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k,
|
|
68
|
+
def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, best_energy, is_segmented, local_size, global_size, args_buf, local_energy_buf, local_index_buf, max_energy_host, max_index_host, max_energy_buf, max_index_buf):
|
|
69
69
|
ctx = opencl_context.ctx
|
|
70
70
|
queue = opencl_context.queue
|
|
71
71
|
bootstrap_kernel = opencl_context.bootstrap_segmented_kernel if is_segmented else opencl_context.bootstrap_kernel
|
|
@@ -110,15 +110,22 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy, i
|
|
|
110
110
|
|
|
111
111
|
# Read results
|
|
112
112
|
cl.enqueue_copy(queue, max_energy_host, max_energy_buf)
|
|
113
|
-
cl.enqueue_copy(queue, max_index_host, max_index_buf)
|
|
114
113
|
queue.finish()
|
|
115
114
|
|
|
115
|
+
# Queue read for results we might not need
|
|
116
|
+
cl.enqueue_copy(queue, max_index_host, max_index_buf)
|
|
117
|
+
|
|
116
118
|
# Find global minimum
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
best_x = np.argmax(max_energy_host)
|
|
120
|
+
energy = max_energy_host[best_x]
|
|
119
121
|
|
|
120
|
-
if
|
|
121
|
-
|
|
122
|
+
if energy <= best_energy:
|
|
123
|
+
# No improvement: we can exit early
|
|
124
|
+
return best_energy
|
|
125
|
+
|
|
126
|
+
# We need the best index
|
|
127
|
+
queue.finish()
|
|
128
|
+
best_i = max_index_host[best_x]
|
|
122
129
|
|
|
123
130
|
flip_index_start = best_i * k
|
|
124
131
|
indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
|
|
@@ -70,7 +70,7 @@ def bootstrap(best_theta, G_data, G_rows, G_cols, indices_array, k, min_energy,
|
|
|
70
70
|
return min_energy
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices_array_np, k,
|
|
73
|
+
def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices_array_np, k, best_energy, is_segmented, local_size, global_size, args_buf, local_energy_buf, local_index_buf, max_energy_host, max_index_host, max_energy_buf, max_index_buf):
|
|
74
74
|
ctx = opencl_context.ctx
|
|
75
75
|
queue = opencl_context.queue
|
|
76
76
|
bootstrap_kernel = opencl_context.bootstrap_sparse_segmented_kernel if is_segmented else opencl_context.bootstrap_sparse_kernel
|
|
@@ -119,15 +119,22 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
|
|
|
119
119
|
|
|
120
120
|
# Read results
|
|
121
121
|
cl.enqueue_copy(queue, max_energy_host, max_energy_buf)
|
|
122
|
-
cl.enqueue_copy(queue, max_index_host, max_index_buf)
|
|
123
122
|
queue.finish()
|
|
124
123
|
|
|
124
|
+
# Queue read for results we might not need
|
|
125
|
+
cl.enqueue_copy(queue, max_index_host, max_index_buf)
|
|
126
|
+
|
|
125
127
|
# Find global minimum
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
best_x = np.argmax(max_energy_host)
|
|
129
|
+
energy = max_energy_host[best_x]
|
|
128
130
|
|
|
129
|
-
if
|
|
130
|
-
|
|
131
|
+
if energy <= best_energy:
|
|
132
|
+
# No improvement: we can exit early
|
|
133
|
+
return best_energy
|
|
134
|
+
|
|
135
|
+
# We need the best index
|
|
136
|
+
queue.finish()
|
|
137
|
+
best_i = max_index_host[best_x]
|
|
131
138
|
|
|
132
139
|
flip_index_start = best_i * k
|
|
133
140
|
indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name='pyqrackising',
|
|
10
|
-
version='8.
|
|
10
|
+
version='8.15.1',
|
|
11
11
|
author='Dan Strano',
|
|
12
12
|
author_email='stranoj@gmail.com',
|
|
13
13
|
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
|