PyQrackIsing 5.6.0__tar.gz → 5.7.0__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.6.0/pyqrackising.egg-info → pyqrackising-5.7.0}/PKG-INFO +1 -1
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyproject.toml +1 -1
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim.py +19 -9
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_sparse.py +19 -9
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_streaming.py +19 -8
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver.py +8 -7
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_sparse.py +8 -7
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_streaming.py +3 -2
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/tsp.py +84 -8
- {pyqrackising-5.6.0 → pyqrackising-5.7.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/setup.py +1 -1
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/CMakeLists.txt +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/LICENSE.md +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/MANIFEST.in +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/README.md +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-5.6.0 → pyqrackising-5.7.0}/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.
|
|
15
|
+
version = "5.7.0"
|
|
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"}
|
|
@@ -84,10 +84,9 @@ def compute_energy(sample, G_m, n_qubits):
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
@njit(parallel=True)
|
|
87
|
-
def sample_for_solution(G_m, shots, thresholds,
|
|
87
|
+
def sample_for_solution(G_m, shots, thresholds, weights):
|
|
88
88
|
n = len(G_m)
|
|
89
89
|
max_weight = G_m.max()
|
|
90
|
-
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
91
90
|
|
|
92
91
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
93
92
|
energies = np.empty(shots, dtype=np.float32)
|
|
@@ -218,7 +217,12 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
|
|
|
218
217
|
|
|
219
218
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
|
|
220
219
|
|
|
221
|
-
|
|
220
|
+
degrees = None
|
|
221
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
222
|
+
weights = J_eff.astype(np.float64)
|
|
223
|
+
J_eff = None
|
|
224
|
+
|
|
225
|
+
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights)
|
|
222
226
|
|
|
223
227
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
224
228
|
|
|
@@ -226,10 +230,10 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
|
|
|
226
230
|
|
|
227
231
|
|
|
228
232
|
@njit
|
|
229
|
-
def gpu_footer(shots, n_qubits, G_m,
|
|
233
|
+
def gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes):
|
|
230
234
|
fix_cdf(hamming_prob)
|
|
231
235
|
|
|
232
|
-
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob,
|
|
236
|
+
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, weights)
|
|
233
237
|
|
|
234
238
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
235
239
|
|
|
@@ -240,8 +244,9 @@ def maxcut_tfim(
|
|
|
240
244
|
G,
|
|
241
245
|
quality=None,
|
|
242
246
|
shots=None,
|
|
243
|
-
is_alt_gpu_sampling
|
|
244
|
-
is_g_buf_reused
|
|
247
|
+
is_alt_gpu_sampling=False,
|
|
248
|
+
is_g_buf_reused=False,
|
|
249
|
+
is_base_maxcut_gpu=True
|
|
245
250
|
):
|
|
246
251
|
nodes = None
|
|
247
252
|
n_qubits = 0
|
|
@@ -279,7 +284,7 @@ def maxcut_tfim(
|
|
|
279
284
|
n_steps = 2 << quality
|
|
280
285
|
grid_size = n_steps * n_qubits
|
|
281
286
|
|
|
282
|
-
if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
287
|
+
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
283
288
|
return cpu_footer(shots, quality, n_qubits, G_m, nodes)
|
|
284
289
|
|
|
285
290
|
J_eff, degrees = init_J_and_z(G_m)
|
|
@@ -341,7 +346,12 @@ def maxcut_tfim(
|
|
|
341
346
|
theta_buf = None
|
|
342
347
|
|
|
343
348
|
if not is_alt_gpu_sampling:
|
|
344
|
-
|
|
349
|
+
degrees = None
|
|
350
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
351
|
+
weights = J_eff.astype(np.float64)
|
|
352
|
+
J_eff = None
|
|
353
|
+
|
|
354
|
+
return gpu_footer(shots, n_qubits, G_m, weights, hamming_prob, nodes)
|
|
345
355
|
|
|
346
356
|
fix_cdf(hamming_prob)
|
|
347
357
|
best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
|
|
@@ -116,10 +116,9 @@ def compute_energy(sample, G_data, G_rows, G_cols):
|
|
|
116
116
|
|
|
117
117
|
|
|
118
118
|
@njit(parallel=True)
|
|
119
|
-
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds,
|
|
119
|
+
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
120
120
|
n = G_rows.shape[0] - 1
|
|
121
121
|
max_weight = G_data.max()
|
|
122
|
-
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
123
122
|
|
|
124
123
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
125
124
|
energies = np.empty(shots, dtype=np.float32)
|
|
@@ -271,7 +270,12 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
|
|
|
271
270
|
|
|
272
271
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
|
|
273
272
|
|
|
274
|
-
|
|
273
|
+
degrees = None
|
|
274
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
275
|
+
weights = J_eff.astype(np.float64)
|
|
276
|
+
J_eff = None
|
|
277
|
+
|
|
278
|
+
best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, weights)
|
|
275
279
|
|
|
276
280
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
277
281
|
|
|
@@ -279,10 +283,10 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
|
|
|
279
283
|
|
|
280
284
|
|
|
281
285
|
@njit
|
|
282
|
-
def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols,
|
|
286
|
+
def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, weights, hamming_prob, nodes):
|
|
283
287
|
fix_cdf(hamming_prob)
|
|
284
288
|
|
|
285
|
-
best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob,
|
|
289
|
+
best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, weights)
|
|
286
290
|
|
|
287
291
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
288
292
|
|
|
@@ -305,8 +309,9 @@ def maxcut_tfim_sparse(
|
|
|
305
309
|
G,
|
|
306
310
|
quality=None,
|
|
307
311
|
shots=None,
|
|
308
|
-
is_alt_gpu_sampling
|
|
309
|
-
is_g_buf_reused
|
|
312
|
+
is_alt_gpu_sampling=False,
|
|
313
|
+
is_g_buf_reused=False,
|
|
314
|
+
is_base_maxcut_gpu=True
|
|
310
315
|
):
|
|
311
316
|
nodes = None
|
|
312
317
|
n_qubits = 0
|
|
@@ -344,7 +349,7 @@ def maxcut_tfim_sparse(
|
|
|
344
349
|
n_steps = 2 << quality
|
|
345
350
|
grid_size = n_steps * n_qubits
|
|
346
351
|
|
|
347
|
-
if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
352
|
+
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
348
353
|
return cpu_footer(shots, quality, n_qubits, G_m.data, G_m.indptr, G_m.indices, nodes)
|
|
349
354
|
|
|
350
355
|
J_eff, degrees = init_J_and_z(G_m.data, G_m.indptr, G_m.indices)
|
|
@@ -406,7 +411,12 @@ def maxcut_tfim_sparse(
|
|
|
406
411
|
theta_buf = None
|
|
407
412
|
|
|
408
413
|
if not is_alt_gpu_sampling:
|
|
409
|
-
|
|
414
|
+
degrees = None
|
|
415
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
416
|
+
weights = J_eff.astype(np.float64)
|
|
417
|
+
J_eff = None
|
|
418
|
+
|
|
419
|
+
return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, weights, hamming_prob, nodes)
|
|
410
420
|
|
|
411
421
|
fix_cdf(hamming_prob)
|
|
412
422
|
best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
|
|
@@ -87,9 +87,7 @@ def compute_energy(sample, G_func, G_func_args_tuple, nodes, n_qubits):
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
@njit(parallel=True)
|
|
90
|
-
def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thresholds, degrees_sum,
|
|
91
|
-
weights = (1.0 / (1.0 + (2e-52) - J_eff)).astype(np.float64)
|
|
92
|
-
|
|
90
|
+
def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thresholds, degrees_sum, weights, n):
|
|
93
91
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
94
92
|
energies = np.empty(shots, dtype=np.float32)
|
|
95
93
|
|
|
@@ -151,7 +149,13 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
|
|
|
151
149
|
|
|
152
150
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
|
|
153
151
|
|
|
154
|
-
|
|
152
|
+
max_weight = degrees.sum()
|
|
153
|
+
degrees = None
|
|
154
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
155
|
+
weights = J_eff.astype(np.float64)
|
|
156
|
+
J_eff = None
|
|
157
|
+
|
|
158
|
+
best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, weights, n_qubits)
|
|
155
159
|
|
|
156
160
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
157
161
|
|
|
@@ -159,10 +163,10 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
|
|
|
159
163
|
|
|
160
164
|
|
|
161
165
|
@njit
|
|
162
|
-
def gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max,
|
|
166
|
+
def gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights, degrees, hamming_prob, max_weight):
|
|
163
167
|
fix_cdf(hamming_prob)
|
|
164
168
|
|
|
165
|
-
best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob,
|
|
169
|
+
best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, weights, n_qubits)
|
|
166
170
|
|
|
167
171
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
168
172
|
|
|
@@ -175,6 +179,7 @@ def maxcut_tfim_streaming(
|
|
|
175
179
|
G_func_args_tuple=None,
|
|
176
180
|
quality=None,
|
|
177
181
|
shots=None,
|
|
182
|
+
is_base_maxcut_gpu=True
|
|
178
183
|
):
|
|
179
184
|
n_qubits = len(nodes)
|
|
180
185
|
|
|
@@ -202,7 +207,7 @@ def maxcut_tfim_streaming(
|
|
|
202
207
|
n_steps = 2 << quality
|
|
203
208
|
grid_size = n_steps * n_qubits
|
|
204
209
|
|
|
205
|
-
if not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
210
|
+
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
206
211
|
return cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes)
|
|
207
212
|
|
|
208
213
|
J_eff, degrees, G_max = init_J_and_z(G_func, G_func_args_tuple, nodes)
|
|
@@ -263,4 +268,10 @@ def maxcut_tfim_streaming(
|
|
|
263
268
|
deg_buf = None
|
|
264
269
|
theta_buf = None
|
|
265
270
|
|
|
266
|
-
|
|
271
|
+
max_weight = degrees.sum()
|
|
272
|
+
degrees = None
|
|
273
|
+
J_eff = 1.0 / (1.0 + (2e-52) - J_eff)
|
|
274
|
+
weights = J_eff.astype(np.float64)
|
|
275
|
+
J_eff = None
|
|
276
|
+
|
|
277
|
+
return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights, degrees, hamming_prob, max_weight)
|
|
@@ -119,12 +119,11 @@ def run_bootstrap_opencl(best_theta, G_m_buf, indices_array_np, k, min_energy):
|
|
|
119
119
|
queue.finish()
|
|
120
120
|
|
|
121
121
|
# Find global minimum
|
|
122
|
-
|
|
123
|
-
energy = min_energy_host[min_idx]
|
|
122
|
+
energy = min_energy_host.min()
|
|
124
123
|
if min_energy < energy:
|
|
125
124
|
return min_energy
|
|
126
125
|
|
|
127
|
-
best_i =
|
|
126
|
+
best_i = np.random.choice(np.where(min_energy_host == energy)[0])
|
|
128
127
|
|
|
129
128
|
flip_index_start = best_i * k
|
|
130
129
|
indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
|
|
@@ -140,7 +139,9 @@ def spin_glass_solver(
|
|
|
140
139
|
quality=None,
|
|
141
140
|
shots=None,
|
|
142
141
|
best_guess=None,
|
|
143
|
-
is_alt_gpu_sampling=False
|
|
142
|
+
is_alt_gpu_sampling=False,
|
|
143
|
+
is_base_maxcut_gpu=True,
|
|
144
|
+
is_combo_maxcut_gpu=True
|
|
144
145
|
):
|
|
145
146
|
nodes = None
|
|
146
147
|
n_qubits = 0
|
|
@@ -179,10 +180,10 @@ def spin_glass_solver(
|
|
|
179
180
|
elif isinstance(best_guess, list):
|
|
180
181
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
181
182
|
else:
|
|
182
|
-
bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True)
|
|
183
|
+
bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True, is_base_maxcut_gpu=is_base_maxcut_gpu)
|
|
183
184
|
best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
|
|
184
185
|
|
|
185
|
-
if IS_OPENCL_AVAILABLE:
|
|
186
|
+
if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
|
|
186
187
|
if not (opencl_context.G_m_buf is None):
|
|
187
188
|
G_m_buf = opencl_context.G_m_buf
|
|
188
189
|
else:
|
|
@@ -210,7 +211,7 @@ def spin_glass_solver(
|
|
|
210
211
|
else:
|
|
211
212
|
combos = combos_list[k - 1]
|
|
212
213
|
|
|
213
|
-
if IS_OPENCL_AVAILABLE:
|
|
214
|
+
if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
|
|
214
215
|
energy = run_bootstrap_opencl(best_theta, G_m_buf, combos, k, min_energy)
|
|
215
216
|
else:
|
|
216
217
|
energy = bootstrap(best_theta, G_m, combos, k, min_energy)
|
|
@@ -124,12 +124,11 @@ def run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, indices
|
|
|
124
124
|
queue.finish()
|
|
125
125
|
|
|
126
126
|
# Find global minimum
|
|
127
|
-
|
|
128
|
-
energy = min_energy_host[min_idx]
|
|
127
|
+
energy = min_energy_host.min()
|
|
129
128
|
if min_energy < energy:
|
|
130
129
|
return min_energy
|
|
131
130
|
|
|
132
|
-
best_i =
|
|
131
|
+
best_i = np.random.choice(np.where(min_energy_host == energy)[0])
|
|
133
132
|
|
|
134
133
|
flip_index_start = best_i * k
|
|
135
134
|
indices_to_flip = indices_array_np[flip_index_start : flip_index_start + k]
|
|
@@ -157,7 +156,9 @@ def spin_glass_solver_sparse(
|
|
|
157
156
|
quality=None,
|
|
158
157
|
shots=None,
|
|
159
158
|
best_guess=None,
|
|
160
|
-
is_alt_gpu_sampling=False
|
|
159
|
+
is_alt_gpu_sampling=False,
|
|
160
|
+
is_base_maxcut_gpu=True,
|
|
161
|
+
is_combo_maxcut_gpu=True
|
|
161
162
|
):
|
|
162
163
|
nodes = None
|
|
163
164
|
n_qubits = 0
|
|
@@ -196,10 +197,10 @@ def spin_glass_solver_sparse(
|
|
|
196
197
|
elif isinstance(best_guess, list):
|
|
197
198
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
198
199
|
else:
|
|
199
|
-
bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True)
|
|
200
|
+
bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_g_buf_reused=True, is_base_maxcut_gpu=is_base_maxcut_gpu)
|
|
200
201
|
best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
|
|
201
202
|
|
|
202
|
-
if IS_OPENCL_AVAILABLE:
|
|
203
|
+
if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
|
|
203
204
|
if not (opencl_context.G_data_buf is None):
|
|
204
205
|
G_data_buf = opencl_context.G_data_buf
|
|
205
206
|
G_rows_buf = opencl_context.G_rows_buf
|
|
@@ -231,7 +232,7 @@ def spin_glass_solver_sparse(
|
|
|
231
232
|
else:
|
|
232
233
|
combos = combos_list[k - 1]
|
|
233
234
|
|
|
234
|
-
if IS_OPENCL_AVAILABLE:
|
|
235
|
+
if is_combo_maxcut_gpu and IS_OPENCL_AVAILABLE:
|
|
235
236
|
energy = run_bootstrap_opencl(best_theta, G_data_buf, G_rows_buf, G_cols_buf, combos, k, min_energy)
|
|
236
237
|
else:
|
|
237
238
|
energy = bootstrap(best_theta, G_m.data, G_m.indptr, G_m.indices, combos, k, min_energy)
|
|
@@ -66,7 +66,8 @@ def spin_glass_solver_streaming(
|
|
|
66
66
|
G_func_args_tuple=None,
|
|
67
67
|
quality=None,
|
|
68
68
|
shots=None,
|
|
69
|
-
best_guess=None
|
|
69
|
+
best_guess=None,
|
|
70
|
+
is_base_maxcut_gpu=True
|
|
70
71
|
):
|
|
71
72
|
n_qubits = len(nodes)
|
|
72
73
|
|
|
@@ -95,7 +96,7 @@ def spin_glass_solver_streaming(
|
|
|
95
96
|
elif isinstance(best_guess, list):
|
|
96
97
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
97
98
|
else:
|
|
98
|
-
bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, G_func_args_tuple=G_func_args_tuple, quality=quality, shots=shots)
|
|
99
|
+
bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, G_func_args_tuple=G_func_args_tuple, quality=quality, shots=shots, is_base_maxcut_gpu=is_base_maxcut_gpu)
|
|
99
100
|
best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
|
|
100
101
|
|
|
101
102
|
min_energy = compute_energy(best_theta, G_func, G_func_args_tuple, nodes)
|
|
@@ -497,7 +497,21 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
|
|
|
497
497
|
return [nodes[x] for x in best_path], best_weight
|
|
498
498
|
|
|
499
499
|
|
|
500
|
-
def tsp_symmetric(
|
|
500
|
+
def tsp_symmetric(
|
|
501
|
+
G,
|
|
502
|
+
start_node=None,
|
|
503
|
+
end_node=None,
|
|
504
|
+
quality=None,
|
|
505
|
+
shots=None,
|
|
506
|
+
is_alt_gpu_sampling=False,
|
|
507
|
+
is_base_maxcut_gpu=True,
|
|
508
|
+
is_combo_maxcut_gpu=True,
|
|
509
|
+
monte_carlo=True,
|
|
510
|
+
k_neighbors=20,
|
|
511
|
+
is_cyclic=True,
|
|
512
|
+
multi_start=1,
|
|
513
|
+
is_top_level=True
|
|
514
|
+
):
|
|
501
515
|
nodes = None
|
|
502
516
|
n_nodes = 0
|
|
503
517
|
G_m = None
|
|
@@ -540,7 +554,7 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=None, shots=None, i
|
|
|
540
554
|
for _ in range(multi_start):
|
|
541
555
|
bits = ([], [])
|
|
542
556
|
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
543
|
-
_, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling)
|
|
557
|
+
_, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_base_maxcut_gpu=is_base_maxcut_gpu, is_combo_maxcut_gpu=is_combo_maxcut_gpu)
|
|
544
558
|
if energy < best_energy:
|
|
545
559
|
best_energy = energy
|
|
546
560
|
a, b = bits
|
|
@@ -555,8 +569,32 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=None, shots=None, i
|
|
|
555
569
|
|
|
556
570
|
G_a, G_b = init_G_a_b(G_m, a, b)
|
|
557
571
|
|
|
558
|
-
sol_a = tsp_symmetric(
|
|
559
|
-
|
|
572
|
+
sol_a = tsp_symmetric(
|
|
573
|
+
G_a,
|
|
574
|
+
quality=quality,
|
|
575
|
+
shots=shots,
|
|
576
|
+
is_alt_gpu_sampling=is_alt_gpu_sampling,
|
|
577
|
+
is_base_maxcut_gpu=is_base_maxcut_gpu,
|
|
578
|
+
is_combo_maxcut_gpu=is_combo_maxcut_gpu,
|
|
579
|
+
monte_carlo=monte_carlo,
|
|
580
|
+
is_cyclic=False,
|
|
581
|
+
is_top_level=False,
|
|
582
|
+
k_neighbors=0,
|
|
583
|
+
multi_start=multi_start
|
|
584
|
+
)
|
|
585
|
+
sol_b = tsp_symmetric(
|
|
586
|
+
G_b,
|
|
587
|
+
quality=quality,
|
|
588
|
+
shots=shots,
|
|
589
|
+
is_alt_gpu_sampling=is_alt_gpu_sampling,
|
|
590
|
+
is_base_maxcut_gpu=is_base_maxcut_gpu,
|
|
591
|
+
is_combo_maxcut_gpu=is_combo_maxcut_gpu,
|
|
592
|
+
monte_carlo=monte_carlo,
|
|
593
|
+
is_cyclic=False,
|
|
594
|
+
is_top_level=False,
|
|
595
|
+
k_neighbors=0,
|
|
596
|
+
multi_start=multi_start
|
|
597
|
+
)
|
|
560
598
|
|
|
561
599
|
return tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c[0] if len(c) else None)
|
|
562
600
|
|
|
@@ -643,7 +681,21 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
|
|
|
643
681
|
return [nodes[x] for x in final_path], best_weight
|
|
644
682
|
|
|
645
683
|
|
|
646
|
-
def tsp_asymmetric(
|
|
684
|
+
def tsp_asymmetric(
|
|
685
|
+
G,
|
|
686
|
+
start_node=None,
|
|
687
|
+
end_node=None,
|
|
688
|
+
quality=None,
|
|
689
|
+
shots=None,
|
|
690
|
+
is_alt_gpu_sampling=False,
|
|
691
|
+
is_base_maxcut_gpu=True,
|
|
692
|
+
is_combo_maxcut_gpu=True,
|
|
693
|
+
monte_carlo=True,
|
|
694
|
+
k_neighbors=20,
|
|
695
|
+
is_cyclic=True,
|
|
696
|
+
multi_start=1,
|
|
697
|
+
is_top_level=True
|
|
698
|
+
):
|
|
647
699
|
nodes = None
|
|
648
700
|
n_nodes = 0
|
|
649
701
|
G_m = None
|
|
@@ -690,7 +742,7 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=None, shots=None,
|
|
|
690
742
|
for _ in range(multi_start):
|
|
691
743
|
bits = ([], [])
|
|
692
744
|
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
693
|
-
_, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling)
|
|
745
|
+
_, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots, is_alt_gpu_sampling=is_alt_gpu_sampling, is_base_maxcut_gpu=is_base_maxcut_gpu, is_combo_maxcut_gpu=is_combo_maxcut_gpu)
|
|
694
746
|
if energy < best_energy:
|
|
695
747
|
best_energy = energy
|
|
696
748
|
a, b = bits
|
|
@@ -705,7 +757,31 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=None, shots=None,
|
|
|
705
757
|
|
|
706
758
|
G_a, G_b = init_G_a_b(G_m, a, b)
|
|
707
759
|
|
|
708
|
-
sol_a = tsp_asymmetric(
|
|
709
|
-
|
|
760
|
+
sol_a = tsp_asymmetric(
|
|
761
|
+
G_a,
|
|
762
|
+
quality=quality,
|
|
763
|
+
shots=shots,
|
|
764
|
+
is_alt_gpu_sampling=is_alt_gpu_sampling,
|
|
765
|
+
is_base_maxcut_gpu=is_base_maxcut_gpu,
|
|
766
|
+
is_combo_maxcut_gpu=is_combo_maxcut_gpu,
|
|
767
|
+
monte_carlo=monte_carlo,
|
|
768
|
+
is_cyclic=False,
|
|
769
|
+
is_top_level=False,
|
|
770
|
+
k_neighbors=0,
|
|
771
|
+
multi_start=multi_start
|
|
772
|
+
)
|
|
773
|
+
sol_b = tsp_asymmetric(
|
|
774
|
+
G_b,
|
|
775
|
+
quality=quality,
|
|
776
|
+
shots=shots,
|
|
777
|
+
is_alt_gpu_sampling=is_alt_gpu_sampling,
|
|
778
|
+
is_base_maxcut_gpu=is_base_maxcut_gpu,
|
|
779
|
+
is_combo_maxcut_gpu=is_combo_maxcut_gpu,
|
|
780
|
+
monte_carlo=monte_carlo,
|
|
781
|
+
is_cyclic=False,
|
|
782
|
+
is_top_level=False,
|
|
783
|
+
k_neighbors=0,
|
|
784
|
+
multi_start=multi_start
|
|
785
|
+
)
|
|
710
786
|
|
|
711
787
|
return tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c[0] if len(c) else None)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='5.
|
|
54
|
+
version='5.7.0',
|
|
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
|