PyQrackIsing 3.4.3__tar.gz → 3.4.5__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-3.4.3/pyqrackising.egg-info → pyqrackising-3.4.5}/PKG-INFO +2 -2
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/README.md +2 -2
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyproject.toml +2 -2
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/tsp.py +182 -71
- {pyqrackising-3.4.3 → pyqrackising-3.4.5/pyqrackising.egg-info}/PKG-INFO +2 -2
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/setup.py +2 -2
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/CMakeLists.txt +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/LICENSE.md +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/MANIFEST.in +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/__init__.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-3.4.3 → pyqrackising-3.4.5}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyqrackising
|
|
3
|
-
Version: 3.4.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 3.4.5
|
|
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
|
|
7
7
|
Author-email: Dan Strano <stranoj@gmail.com>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# PyQrack Ising
|
|
2
|
-
|
|
2
|
+
Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
|
|
3
3
|
|
|
4
4
|
(It's "the **Ising** on top.")
|
|
5
5
|
|
|
@@ -101,7 +101,7 @@ circuit, path_length = tsp_symmetric(
|
|
|
101
101
|
G,
|
|
102
102
|
start_node=None,
|
|
103
103
|
end_node=None,
|
|
104
|
-
monte_carlo=
|
|
104
|
+
monte_carlo=True,
|
|
105
105
|
quality=2,
|
|
106
106
|
correction_quality=2,
|
|
107
107
|
is_cyclic=True,
|
|
@@ -11,9 +11,9 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "pyqrackising"
|
|
14
|
-
version = "3.4.
|
|
14
|
+
version = "3.4.5"
|
|
15
15
|
requires-python = ">=3.8"
|
|
16
|
-
description = "
|
|
16
|
+
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
17
17
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
18
18
|
license = {text = "LGPL-3.0-or-later"}
|
|
19
19
|
authors = [
|
|
@@ -9,8 +9,8 @@ import numpy as np
|
|
|
9
9
|
@njit
|
|
10
10
|
def path_length(path, G_m):
|
|
11
11
|
tot_len = 0.0
|
|
12
|
-
for i in range(len(path)-1):
|
|
13
|
-
tot_len += G_m[path[i], path[i+1]]
|
|
12
|
+
for i in range(len(path) - 1):
|
|
13
|
+
tot_len += G_m[path[i], path[i + 1]]
|
|
14
14
|
|
|
15
15
|
return tot_len
|
|
16
16
|
|
|
@@ -207,80 +207,109 @@ def init_G_a_b(G_m, a, b):
|
|
|
207
207
|
|
|
208
208
|
|
|
209
209
|
@njit
|
|
210
|
-
def
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
singlet
|
|
223
|
-
bulk
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
best_weight = G_m[singlet, bulk[0]]
|
|
227
|
-
weight = G_m[singlet, bulk[-1]]
|
|
210
|
+
def stich_singlet(G_m, singlet, bulk):
|
|
211
|
+
best_path = bulk.copy()
|
|
212
|
+
best_weight = G_m[singlet, bulk[0]]
|
|
213
|
+
weight = G_m[singlet, bulk[-1]]
|
|
214
|
+
if weight < best_weight:
|
|
215
|
+
best_weight = weight
|
|
216
|
+
best_path += [singlet]
|
|
217
|
+
else:
|
|
218
|
+
best_path = [singlet] + best_path
|
|
219
|
+
|
|
220
|
+
for i in range(1, len(bulk)):
|
|
221
|
+
weight = (
|
|
222
|
+
G_m[singlet, bulk[i - 1]] +
|
|
223
|
+
G_m[singlet, bulk[i]] -
|
|
224
|
+
G_m[bulk[i - 1], bulk[i]]
|
|
225
|
+
)
|
|
228
226
|
if weight < best_weight:
|
|
229
227
|
best_weight = weight
|
|
230
|
-
best_path
|
|
231
|
-
|
|
232
|
-
best_path = [singlet] + best_path
|
|
233
|
-
|
|
234
|
-
for i in range(1, len(bulk)):
|
|
235
|
-
weight = (
|
|
236
|
-
G_m[singlet, bulk[i - 1]] +
|
|
237
|
-
G_m[singlet, bulk[i]] -
|
|
238
|
-
G_m[bulk[i - 1], bulk[i]]
|
|
239
|
-
)
|
|
240
|
-
if weight < best_weight:
|
|
241
|
-
best_weight = weight
|
|
242
|
-
best_path = bulk.copy()
|
|
243
|
-
best_path.insert(i, singlet)
|
|
244
|
-
else:
|
|
245
|
-
terminals_a = [path_a[0], path_a[-1]]
|
|
246
|
-
terminals_b = [path_b[0], path_b[-1]]
|
|
247
|
-
|
|
248
|
-
best_connect = G_m[terminals_a[1], terminals_b[0]]
|
|
249
|
-
best_path = path_b.copy()
|
|
250
|
-
weight = G_m[terminals_a[0], terminals_b[1]]
|
|
251
|
-
if weight < best_connect:
|
|
252
|
-
best_connect = weight
|
|
253
|
-
best_path += path_a
|
|
254
|
-
else:
|
|
255
|
-
best_path = path_a + best_path
|
|
228
|
+
best_path = bulk.copy()
|
|
229
|
+
best_path.insert(i, singlet)
|
|
256
230
|
|
|
257
|
-
|
|
258
|
-
path_weight = path_length(path_a, G_m) + path_length(path_a, G_m)
|
|
259
|
-
best_weight = best_connect + path_weight
|
|
231
|
+
return best_path
|
|
260
232
|
|
|
233
|
+
@njit
|
|
234
|
+
def stitch_symmetric(G_m, path_a, path_b):
|
|
235
|
+
if len(path_a) == 1:
|
|
236
|
+
return stich_singlet(G_m, path_a[0], path_b)
|
|
237
|
+
|
|
238
|
+
if len(path_b) == 1:
|
|
239
|
+
return stich_singlet(G_m, path_b[0], path_a)
|
|
240
|
+
|
|
241
|
+
terminals_a = [path_a[0], path_a[-1]]
|
|
242
|
+
terminals_b = [path_b[0], path_b[-1]]
|
|
243
|
+
|
|
244
|
+
best_connect = G_m[terminals_a[1], terminals_b[0]]
|
|
245
|
+
best_path = path_b.copy()
|
|
246
|
+
weight = G_m[terminals_a[0], terminals_b[1]]
|
|
247
|
+
if weight < best_connect:
|
|
248
|
+
best_connect = weight
|
|
249
|
+
best_path += path_a
|
|
250
|
+
else:
|
|
251
|
+
best_path = path_a + best_path
|
|
252
|
+
|
|
253
|
+
for _ in range(2):
|
|
261
254
|
for _ in range(2):
|
|
262
|
-
for
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
path_a.reverse()
|
|
277
|
-
terminals_a.reverse()
|
|
278
|
-
path_a, path_b = path_b, path_a
|
|
279
|
-
terminals_a, terminals_b = terminals_b, terminals_a
|
|
255
|
+
for i in range(1, len(path_b)):
|
|
256
|
+
weight = (
|
|
257
|
+
G_m[terminals_a[0], path_b[i - 1]] +
|
|
258
|
+
G_m[terminals_a[1], path_b[i]] -
|
|
259
|
+
G_m[path_b[i - 1], path_b[i]]
|
|
260
|
+
)
|
|
261
|
+
if weight < best_connect:
|
|
262
|
+
best_connect = weight
|
|
263
|
+
best_path = path_b.copy()
|
|
264
|
+
best_path[i:i] = path_a
|
|
265
|
+
path_a.reverse()
|
|
266
|
+
terminals_a.reverse()
|
|
267
|
+
path_a, path_b = path_b, path_a
|
|
268
|
+
terminals_a, terminals_b = terminals_b, terminals_a
|
|
280
269
|
|
|
281
270
|
return best_path
|
|
282
271
|
|
|
283
272
|
|
|
273
|
+
def stitch_asymmetric(G_m, path_a, path_b):
|
|
274
|
+
if len(path_a) == 1:
|
|
275
|
+
return stich_singlet(G_m, path_a[0], path_b)
|
|
276
|
+
|
|
277
|
+
if len(path_b) == 1:
|
|
278
|
+
return stich_singlet(G_m, path_b[0], path_a)
|
|
279
|
+
|
|
280
|
+
terminals_a = [path_a[0], path_a[-1]]
|
|
281
|
+
terminals_b = [path_b[0], path_b[-1]]
|
|
282
|
+
|
|
283
|
+
best_connect = G_m[terminals_a[1], terminals_b[0]]
|
|
284
|
+
best_path = path_b.copy()
|
|
285
|
+
weight = G_m[terminals_a[0], terminals_b[1]]
|
|
286
|
+
if weight < best_connect:
|
|
287
|
+
best_connect = weight
|
|
288
|
+
best_path += path_a
|
|
289
|
+
else:
|
|
290
|
+
best_path = path_a + best_path
|
|
291
|
+
|
|
292
|
+
for _ in range(2):
|
|
293
|
+
for _ in range(2):
|
|
294
|
+
path_weight = path_length(path_a, G_m) + path_length(path_a, G_m)
|
|
295
|
+
best_weight = best_connect + path_weight
|
|
296
|
+
for i in range(1, len(path_b)):
|
|
297
|
+
weight = (
|
|
298
|
+
G_m[terminals_a[0], path_b[i - 1]] +
|
|
299
|
+
G_m[terminals_a[1], path_b[i]] -
|
|
300
|
+
G_m[path_b[i - 1], path_b[i]]
|
|
301
|
+
)
|
|
302
|
+
if (weight + path_weight) < best_weight:
|
|
303
|
+
best_weight = weight + path_weight
|
|
304
|
+
best_path = path_b.copy()
|
|
305
|
+
best_path[i:i] = path_a
|
|
306
|
+
path_a.reverse()
|
|
307
|
+
terminals_a.reverse()
|
|
308
|
+
path_a, path_b = path_b, path_a
|
|
309
|
+
terminals_a, terminals_b = terminals_b, terminals_a
|
|
310
|
+
|
|
311
|
+
return best_path
|
|
312
|
+
|
|
284
313
|
|
|
285
314
|
def monte_carlo_loop(n_nodes):
|
|
286
315
|
bits = ([], [])
|
|
@@ -295,6 +324,72 @@ def monte_carlo_loop(n_nodes):
|
|
|
295
324
|
return bits
|
|
296
325
|
|
|
297
326
|
|
|
327
|
+
# Elara suggested replacing base-case handling with her brute-force solver
|
|
328
|
+
@njit
|
|
329
|
+
def tsp_bruteforce_cyclic(G_m, perms):
|
|
330
|
+
"""
|
|
331
|
+
Brute-force TSP solver for small n.
|
|
332
|
+
G_m : numpy.ndarray (2D adjacency/weight matrix)
|
|
333
|
+
is_cyclic : bool (default=True) – whether to close the tour
|
|
334
|
+
|
|
335
|
+
Returns:
|
|
336
|
+
(best_path, best_weight)
|
|
337
|
+
"""
|
|
338
|
+
n = len(G_m)
|
|
339
|
+
best_weight = float('inf')
|
|
340
|
+
best_path = None
|
|
341
|
+
|
|
342
|
+
# Must fix node 0 at start to remove rotational symmetry in cyclic case!
|
|
343
|
+
|
|
344
|
+
max_i = len(perms[0]) - 1
|
|
345
|
+
|
|
346
|
+
for perm in perms:
|
|
347
|
+
path = [0] + list(perm)
|
|
348
|
+
weight = 0.0
|
|
349
|
+
for i in range(max_i):
|
|
350
|
+
weight += G_m[path[i], path[i+1]]
|
|
351
|
+
weight += G_m[path[-1], path[0]]
|
|
352
|
+
|
|
353
|
+
if weight < best_weight:
|
|
354
|
+
best_weight = weight
|
|
355
|
+
best_path = path
|
|
356
|
+
|
|
357
|
+
best_path = best_path + [best_path[0]]
|
|
358
|
+
|
|
359
|
+
return best_path, best_weight
|
|
360
|
+
|
|
361
|
+
@njit
|
|
362
|
+
def tsp_bruteforce_acyclic(G_m, perms):
|
|
363
|
+
"""
|
|
364
|
+
Brute-force TSP solver for small n.
|
|
365
|
+
G_m : numpy.ndarray (2D adjacency/weight matrix)
|
|
366
|
+
is_cyclic : bool (default=True) – whether to close the tour
|
|
367
|
+
|
|
368
|
+
Returns:
|
|
369
|
+
(best_path, best_weight)
|
|
370
|
+
"""
|
|
371
|
+
n = len(G_m)
|
|
372
|
+
best_weight = float('inf')
|
|
373
|
+
best_path = None
|
|
374
|
+
|
|
375
|
+
# Must fix node 0 at start to remove rotational symmetry in cyclic case!
|
|
376
|
+
|
|
377
|
+
max_i = len(perms[0]) - 1
|
|
378
|
+
|
|
379
|
+
for path in perms:
|
|
380
|
+
weight = 0.0
|
|
381
|
+
for i in range(max_i):
|
|
382
|
+
weight += G_m[path[i], path[i+1]]
|
|
383
|
+
|
|
384
|
+
if weight < best_weight:
|
|
385
|
+
best_weight = weight
|
|
386
|
+
best_path = path
|
|
387
|
+
|
|
388
|
+
best_path = list(best_path)
|
|
389
|
+
|
|
390
|
+
return best_path, best_weight
|
|
391
|
+
|
|
392
|
+
|
|
298
393
|
def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, correction_quality=2, monte_carlo=True, k_neighbors=16, is_cyclic=True, multi_start=1, is_top_level=True):
|
|
299
394
|
nodes = None
|
|
300
395
|
n_nodes = 0
|
|
@@ -312,7 +407,15 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, corr
|
|
|
312
407
|
start_node = None
|
|
313
408
|
end_node = None
|
|
314
409
|
|
|
315
|
-
if n_nodes <
|
|
410
|
+
if n_nodes < 6:
|
|
411
|
+
if n_nodes > 3:
|
|
412
|
+
if is_cyclic:
|
|
413
|
+
best_path, best_weight = tsp_bruteforce_cyclic(G_m, list(itertools.permutations(list(range(1, n_nodes)))))
|
|
414
|
+
else:
|
|
415
|
+
best_path, best_weight = tsp_bruteforce_acyclic(G_m, list(itertools.permutations(list(range(n_nodes)))))
|
|
416
|
+
|
|
417
|
+
return [nodes[x] for x in best_path], best_weight
|
|
418
|
+
|
|
316
419
|
if n_nodes == 3:
|
|
317
420
|
if is_cyclic:
|
|
318
421
|
weight_0 = G_m[0, 1] + G_m[1, 2] + G_m[2, 0]
|
|
@@ -383,7 +486,7 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, corr
|
|
|
383
486
|
path_b = [b[x] for x in sol_b[0]]
|
|
384
487
|
|
|
385
488
|
if start_node is None:
|
|
386
|
-
best_path =
|
|
489
|
+
best_path = stitch_symmetric(G_m, path_a, path_b)
|
|
387
490
|
else:
|
|
388
491
|
best_path = path_a + path_b
|
|
389
492
|
best_weight = G_m[path_a[0], path_b[0]]
|
|
@@ -437,7 +540,15 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=1, shots=None, cor
|
|
|
437
540
|
start_node = None
|
|
438
541
|
end_node = None
|
|
439
542
|
|
|
440
|
-
if n_nodes <
|
|
543
|
+
if n_nodes < 6:
|
|
544
|
+
if n_nodes > 2:
|
|
545
|
+
if is_cyclic:
|
|
546
|
+
best_path, best_weight = tsp_bruteforce_cyclic(G_m, list(itertools.permutations(list(range(1, n_nodes)))))
|
|
547
|
+
else:
|
|
548
|
+
best_path, best_weight = tsp_bruteforce_acyclic(G_m, list(itertools.permutations(list(range(n_nodes)))))
|
|
549
|
+
|
|
550
|
+
return [nodes[x] for x in best_path], best_weight
|
|
551
|
+
|
|
441
552
|
if n_nodes == 2:
|
|
442
553
|
weight = G_m[0, 1]
|
|
443
554
|
if G_m[1, 0] < weight:
|
|
@@ -492,7 +603,7 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=1, shots=None, cor
|
|
|
492
603
|
path_b = [b[x] for x in sol_b[0]]
|
|
493
604
|
|
|
494
605
|
if start_node is None:
|
|
495
|
-
best_path =
|
|
606
|
+
best_path = stitch_asymmetric(G_m, path_a, path_b)
|
|
496
607
|
else:
|
|
497
608
|
best_path = path_a + path_b
|
|
498
609
|
best_weight = G_m[path_a[0], path_b[0]]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyqrackising
|
|
3
|
-
Version: 3.4.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 3.4.5
|
|
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
|
|
7
7
|
Author-email: Dan Strano <stranoj@gmail.com>
|
|
@@ -51,10 +51,10 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='3.4.
|
|
54
|
+
version='3.4.5',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
|
-
description='
|
|
57
|
+
description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)',
|
|
58
58
|
long_description=README,
|
|
59
59
|
long_description_content_type='text/markdown',
|
|
60
60
|
url="https://github.com/vm6502q/PyQrackIsing",
|
|
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
|