PyQrackIsing 7.4.3__tar.gz → 7.4.4__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-7.4.3/pyqrackising.egg-info → pyqrackising-7.4.4}/PKG-INFO +1 -1
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyproject.toml +1 -1
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/tsp.py +203 -23
- {pyqrackising-7.4.3 → pyqrackising-7.4.4/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/setup.py +1 -1
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/CMakeLists.txt +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/LICENSE.md +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/MANIFEST.in +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/README.md +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/__init__.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-7.4.3 → pyqrackising-7.4.4}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "7.4.
|
|
15
|
+
version = "7.4.4"
|
|
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,7 +4,7 @@ from concurrent.futures import ProcessPoolExecutor
|
|
|
4
4
|
import time
|
|
5
5
|
import itertools
|
|
6
6
|
import networkx as nx
|
|
7
|
-
from numba import njit
|
|
7
|
+
from numba import njit, prange
|
|
8
8
|
import numpy as np
|
|
9
9
|
import os
|
|
10
10
|
from scipy.sparse import lil_matrix
|
|
@@ -136,9 +136,6 @@ def targeted_three_opt(path, W, neighbor_lists, k_neighbors=20):
|
|
|
136
136
|
if k <= j or k >= n-1:
|
|
137
137
|
continue
|
|
138
138
|
|
|
139
|
-
# Extract indices
|
|
140
|
-
A, B, C, D, E, F = path[i], path[i+1], path[j], path[j+1], path[k], path[k+1]
|
|
141
|
-
|
|
142
139
|
# 7 unique cases (same as brute force, but restricted)
|
|
143
140
|
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
144
141
|
dist = path_length(new_path, W)
|
|
@@ -193,6 +190,66 @@ def targeted_three_opt(path, W, neighbor_lists, k_neighbors=20):
|
|
|
193
190
|
return best_path, best_dist
|
|
194
191
|
|
|
195
192
|
|
|
193
|
+
@njit(parallel=True)
|
|
194
|
+
def targeted_three_opt_parallel(path, W, neighbor_lists, k_neighbors=20):
|
|
195
|
+
n = len(path)
|
|
196
|
+
best_path = path[:]
|
|
197
|
+
best_dist = path_length(best_path, W)
|
|
198
|
+
paths = [best_path] * 7
|
|
199
|
+
dists = [best_dist] * 7
|
|
200
|
+
improved = True
|
|
201
|
+
|
|
202
|
+
while improved:
|
|
203
|
+
improved = False
|
|
204
|
+
for i in range(n - 5):
|
|
205
|
+
for _j in range(k_neighbors):
|
|
206
|
+
j = neighbor_lists[path[i], _j]
|
|
207
|
+
if j <= i or j >= n-3:
|
|
208
|
+
continue
|
|
209
|
+
for _k in range(k_neighbors):
|
|
210
|
+
k = neighbor_lists[path[j], _k]
|
|
211
|
+
if k <= j or k >= n-1:
|
|
212
|
+
continue
|
|
213
|
+
|
|
214
|
+
# 7 unique cases (same as brute force, but restricted)
|
|
215
|
+
for l in prange(7):
|
|
216
|
+
match l:
|
|
217
|
+
case 0:
|
|
218
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
219
|
+
case 1:
|
|
220
|
+
new_path = best_path[:j+1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
221
|
+
case 2:
|
|
222
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
223
|
+
case 3:
|
|
224
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
225
|
+
case 4:
|
|
226
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
227
|
+
case 5:
|
|
228
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
229
|
+
case _:
|
|
230
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
231
|
+
|
|
232
|
+
dists[l] = path_length(best_path, W)
|
|
233
|
+
paths[l] = new_path
|
|
234
|
+
|
|
235
|
+
for i in range(7):
|
|
236
|
+
if dists[i] < best_dist:
|
|
237
|
+
best_path, best_dist, improved = paths[i], dists[i], True
|
|
238
|
+
|
|
239
|
+
if improved:
|
|
240
|
+
break
|
|
241
|
+
|
|
242
|
+
if improved:
|
|
243
|
+
break
|
|
244
|
+
|
|
245
|
+
if improved:
|
|
246
|
+
break
|
|
247
|
+
|
|
248
|
+
path = best_path[:]
|
|
249
|
+
|
|
250
|
+
return best_path, best_dist
|
|
251
|
+
|
|
252
|
+
|
|
196
253
|
@njit
|
|
197
254
|
def init_G_a_b(G_m, a, b):
|
|
198
255
|
n_a_nodes = len(a)
|
|
@@ -459,7 +516,7 @@ def tsp_symmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic):
|
|
|
459
516
|
|
|
460
517
|
|
|
461
518
|
@njit
|
|
462
|
-
def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c, neighbor_lists):
|
|
519
|
+
def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_neighbors, nodes, sol_a, sol_b, a, b, c, neighbor_lists, is_parallel):
|
|
463
520
|
path_a = [a[x] for x in sol_a[0]]
|
|
464
521
|
path_b = [b[x] for x in sol_b[0]]
|
|
465
522
|
|
|
@@ -492,7 +549,10 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
|
|
|
492
549
|
best_path, _ = one_way_two_opt(best_path, G_m)
|
|
493
550
|
|
|
494
551
|
if k_neighbors > 0:
|
|
495
|
-
|
|
552
|
+
if is_parallel:
|
|
553
|
+
best_path, _ = targeted_three_opt_parallel(best_path, G_m, neighbor_lists, k_neighbors)
|
|
554
|
+
else:
|
|
555
|
+
best_path, _ = targeted_three_opt(best_path, G_m, neighbor_lists, k_neighbors)
|
|
496
556
|
|
|
497
557
|
# We just corrected segments of 2 and 3,
|
|
498
558
|
# and this is top level,
|
|
@@ -631,7 +691,7 @@ def tsp_symmetric(
|
|
|
631
691
|
for i in range(len(neighbor_lists)):
|
|
632
692
|
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
633
693
|
|
|
634
|
-
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, np.array(neighbor_lists))
|
|
694
|
+
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, np.array(neighbor_lists), is_parallel)
|
|
635
695
|
|
|
636
696
|
|
|
637
697
|
@njit
|
|
@@ -651,7 +711,7 @@ def tsp_asymmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic):
|
|
|
651
711
|
|
|
652
712
|
|
|
653
713
|
@njit
|
|
654
|
-
def 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):
|
|
714
|
+
def 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, is_parallel):
|
|
655
715
|
path_a = [a[x] for x in sol_a[0]]
|
|
656
716
|
path_b = [b[x] for x in sol_b[0]]
|
|
657
717
|
|
|
@@ -695,9 +755,9 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
|
|
|
695
755
|
|
|
696
756
|
if k_neighbors > 0:
|
|
697
757
|
best_path = final_path
|
|
698
|
-
final_path, best_weight = targeted_three_opt(best_path.copy(), G_m, k_neighbors)
|
|
758
|
+
final_path, best_weight = targeted_three_opt_parallel(best_path.copy(), G_m, k_neighbors) if is_parallel else targeted_three_opt(best_path.copy(), G_m, k_neighbors)
|
|
699
759
|
best_path.reverse()
|
|
700
|
-
path, weight = targeted_three_opt(best_path.copy(), G_m, k_neighbors)
|
|
760
|
+
path, weight = targeted_three_opt_parallel(best_path.copy(), G_m, k_neighbors) if is_parallel else targeted_three_opt(best_path.copy(), G_m, k_neighbors)
|
|
701
761
|
if weight < best_weight:
|
|
702
762
|
final_path, best_weight = path, weight
|
|
703
763
|
else:
|
|
@@ -827,7 +887,7 @@ def tsp_asymmetric(
|
|
|
827
887
|
is_parallel=False
|
|
828
888
|
)
|
|
829
889
|
|
|
830
|
-
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)
|
|
890
|
+
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, is_parallel)
|
|
831
891
|
|
|
832
892
|
|
|
833
893
|
@njit
|
|
@@ -904,9 +964,6 @@ def targeted_three_opt_sparse(path, G_data, G_rows, G_cols, neighbor_lists, k_ne
|
|
|
904
964
|
if k <= j or k >= n-1:
|
|
905
965
|
continue
|
|
906
966
|
|
|
907
|
-
# Extract indices
|
|
908
|
-
A, B, C, D, E, F = path[i], path[i+1], path[j], path[j+1], path[k], path[k+1]
|
|
909
|
-
|
|
910
967
|
# 7 unique cases (same as brute force, but restricted)
|
|
911
968
|
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
912
969
|
dist = path_length_sparse(new_path, G_data, G_rows, G_cols)
|
|
@@ -961,6 +1018,66 @@ def targeted_three_opt_sparse(path, G_data, G_rows, G_cols, neighbor_lists, k_ne
|
|
|
961
1018
|
return best_path, best_dist
|
|
962
1019
|
|
|
963
1020
|
|
|
1021
|
+
@njit(parallel=True)
|
|
1022
|
+
def targeted_three_opt_sparse_parallel(path, G_data, G_rows, G_cols, neighbor_lists, k_neighbors=20):
|
|
1023
|
+
n = len(path)
|
|
1024
|
+
best_path = path[:]
|
|
1025
|
+
best_dist = path_length_sparse(best_path, G_data, G_rows, G_cols)
|
|
1026
|
+
paths = [best_path] * 7
|
|
1027
|
+
dists = [best_dist] * 7
|
|
1028
|
+
improved = True
|
|
1029
|
+
|
|
1030
|
+
while improved:
|
|
1031
|
+
improved = False
|
|
1032
|
+
for i in range(n - 5):
|
|
1033
|
+
for _j in range(k_neighbors):
|
|
1034
|
+
j = neighbor_lists[path[i], _j]
|
|
1035
|
+
if j <= i or j >= n-3:
|
|
1036
|
+
continue
|
|
1037
|
+
for _k in range(k_neighbors):
|
|
1038
|
+
k = neighbor_lists[path[j], _k]
|
|
1039
|
+
if k <= j or k >= n-1:
|
|
1040
|
+
continue
|
|
1041
|
+
|
|
1042
|
+
# 7 unique cases (same as brute force, but restricted)
|
|
1043
|
+
for l in prange(7):
|
|
1044
|
+
match l:
|
|
1045
|
+
case 0:
|
|
1046
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
1047
|
+
case 1:
|
|
1048
|
+
new_path = best_path[:j+1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
1049
|
+
case 2:
|
|
1050
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
1051
|
+
case 3:
|
|
1052
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
1053
|
+
case 4:
|
|
1054
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
1055
|
+
case 5:
|
|
1056
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
1057
|
+
case _:
|
|
1058
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
1059
|
+
|
|
1060
|
+
dists[l] = path_length_sparse(new_path, G_data, G_rows, G_cols)
|
|
1061
|
+
paths[l] = new_path
|
|
1062
|
+
|
|
1063
|
+
for i in range(7):
|
|
1064
|
+
if dists[i] < best_dist:
|
|
1065
|
+
best_path, best_dist, improved = paths[i], dists[i], True
|
|
1066
|
+
|
|
1067
|
+
if improved:
|
|
1068
|
+
break
|
|
1069
|
+
|
|
1070
|
+
if improved:
|
|
1071
|
+
break
|
|
1072
|
+
|
|
1073
|
+
if improved:
|
|
1074
|
+
break
|
|
1075
|
+
|
|
1076
|
+
path = best_path[:]
|
|
1077
|
+
|
|
1078
|
+
return best_path, best_dist
|
|
1079
|
+
|
|
1080
|
+
|
|
964
1081
|
@njit
|
|
965
1082
|
def stich_singlet_sparse(G_data, G_rows, G_cols, singlet, bulk):
|
|
966
1083
|
best_path = bulk.copy()
|
|
@@ -1118,7 +1235,7 @@ def init_G_a_b_sparse(G_m, a, b, dtype):
|
|
|
1118
1235
|
|
|
1119
1236
|
|
|
1120
1237
|
@njit
|
|
1121
|
-
def tsp_symmetric_sparse_driver(G_data, G_rows, G_cols, is_top_level, k_neighbors, nodes, sol_a, sol_b, a, b, neighbor_lists):
|
|
1238
|
+
def tsp_symmetric_sparse_driver(G_data, G_rows, G_cols, is_top_level, k_neighbors, nodes, sol_a, sol_b, a, b, neighbor_lists, is_parallel):
|
|
1122
1239
|
path_a = [a[x] for x in sol_a[0]]
|
|
1123
1240
|
path_b = [b[x] for x in sol_b[0]]
|
|
1124
1241
|
|
|
@@ -1128,7 +1245,10 @@ def tsp_symmetric_sparse_driver(G_data, G_rows, G_cols, is_top_level, k_neighbor
|
|
|
1128
1245
|
best_path, _ = one_way_two_opt_sparse(best_path, G_data, G_rows, G_cols)
|
|
1129
1246
|
|
|
1130
1247
|
if k_neighbors > 0:
|
|
1131
|
-
|
|
1248
|
+
if is_parallel:
|
|
1249
|
+
best_path, _ = targeted_three_opt_sparse_parallel(best_path, G_data, G_rows, G_cols, neighbor_lists, k_neighbors)
|
|
1250
|
+
else:
|
|
1251
|
+
best_path, _ = targeted_three_opt_sparse(best_path, G_data, G_rows, G_cols, neighbor_lists, k_neighbors)
|
|
1132
1252
|
|
|
1133
1253
|
best_path = restitch_sparse(G_data, G_rows, G_cols, best_path)
|
|
1134
1254
|
|
|
@@ -1205,7 +1325,7 @@ def tsp_symmetric_sparse(
|
|
|
1205
1325
|
for i in range(len(neighbor_lists)):
|
|
1206
1326
|
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1207
1327
|
|
|
1208
|
-
return tsp_symmetric_sparse_driver(G_m.data, G_m.indptr, G_m.indices, is_top_level, k_neighbors, nodes, sol_a, sol_b, a, b, np.array(neighbor_lists))
|
|
1328
|
+
return tsp_symmetric_sparse_driver(G_m.data, G_m.indptr, G_m.indices, is_top_level, k_neighbors, nodes, sol_a, sol_b, a, b, np.array(neighbor_lists), is_parallel)
|
|
1209
1329
|
|
|
1210
1330
|
|
|
1211
1331
|
@njit
|
|
@@ -1258,9 +1378,6 @@ def targeted_three_opt_streaming(path, G_func, neighbor_lists, k_neighbors=20):
|
|
|
1258
1378
|
if k <= j or k >= n-1:
|
|
1259
1379
|
continue
|
|
1260
1380
|
|
|
1261
|
-
# Extract indices
|
|
1262
|
-
A, B, C, D, E, F = path[i], path[i+1], path[j], path[j+1], path[k], path[k+1]
|
|
1263
|
-
|
|
1264
1381
|
# 7 unique cases (same as brute force, but restricted)
|
|
1265
1382
|
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
1266
1383
|
dist = path_length_streaming(new_path, G_func)
|
|
@@ -1315,6 +1432,66 @@ def targeted_three_opt_streaming(path, G_func, neighbor_lists, k_neighbors=20):
|
|
|
1315
1432
|
return best_path, best_dist
|
|
1316
1433
|
|
|
1317
1434
|
|
|
1435
|
+
@njit(parallel=True)
|
|
1436
|
+
def targeted_three_opt_streaming_parallel(path, G_func, neighbor_lists, k_neighbors=20):
|
|
1437
|
+
n = len(path)
|
|
1438
|
+
best_path = path[:]
|
|
1439
|
+
best_dist = path_length_streaming(best_path, G_func)
|
|
1440
|
+
paths = [best_path] * 7
|
|
1441
|
+
dists = [best_dist] * 7
|
|
1442
|
+
improved = True
|
|
1443
|
+
|
|
1444
|
+
while improved:
|
|
1445
|
+
improved = False
|
|
1446
|
+
for i in range(n - 5):
|
|
1447
|
+
for _j in range(k_neighbors):
|
|
1448
|
+
j = neighbor_lists[path[i], _j]
|
|
1449
|
+
if j <= i or j >= n-3:
|
|
1450
|
+
continue
|
|
1451
|
+
for _k in range(k_neighbors):
|
|
1452
|
+
k = neighbor_lists[path[j], _k]
|
|
1453
|
+
if k <= j or k >= n-1:
|
|
1454
|
+
continue
|
|
1455
|
+
|
|
1456
|
+
# 7 unique cases (same as brute force, but restricted)
|
|
1457
|
+
for l in prange(7):
|
|
1458
|
+
match l:
|
|
1459
|
+
case 0:
|
|
1460
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:]
|
|
1461
|
+
case 1:
|
|
1462
|
+
new_path = best_path[:j+1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
1463
|
+
case 2:
|
|
1464
|
+
new_path = best_path[:i+1] + best_path[i+1:j+1][::-1] + best_path[j+1:k+1][::-1] + best_path[k+1:]
|
|
1465
|
+
case 3:
|
|
1466
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
1467
|
+
case 4:
|
|
1468
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
1469
|
+
case 5:
|
|
1470
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1] + best_path[i+1:j+1][::-1] + best_path[k+1:]
|
|
1471
|
+
case _:
|
|
1472
|
+
new_path = best_path[:i+1] + best_path[j+1:k+1][::-1] + best_path[i+1:j+1] + best_path[k+1:]
|
|
1473
|
+
|
|
1474
|
+
dists[l] = path_length_streaming(new_path, G_func)
|
|
1475
|
+
paths[l] = new_path
|
|
1476
|
+
|
|
1477
|
+
for i in range(7):
|
|
1478
|
+
if dists[i] < best_dist:
|
|
1479
|
+
best_path, best_dist, improved = paths[i], dists[i], True
|
|
1480
|
+
|
|
1481
|
+
if improved:
|
|
1482
|
+
break
|
|
1483
|
+
|
|
1484
|
+
if improved:
|
|
1485
|
+
break
|
|
1486
|
+
|
|
1487
|
+
if improved:
|
|
1488
|
+
break
|
|
1489
|
+
|
|
1490
|
+
path = best_path[:]
|
|
1491
|
+
|
|
1492
|
+
return best_path, best_dist
|
|
1493
|
+
|
|
1494
|
+
|
|
1318
1495
|
@njit
|
|
1319
1496
|
def stich_singlet_streaming(G_func, singlet, bulk):
|
|
1320
1497
|
best_path = bulk.copy()
|
|
@@ -1439,14 +1616,17 @@ def tsp_streaming_bruteforce(G_func, perms, n):
|
|
|
1439
1616
|
|
|
1440
1617
|
|
|
1441
1618
|
@njit
|
|
1442
|
-
def tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, path_a, path_b, neighbor_lists):
|
|
1619
|
+
def tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, path_a, path_b, neighbor_lists, is_parallel):
|
|
1443
1620
|
best_path = stitch_streaming_symmetric(G_func, path_a, path_b)
|
|
1444
1621
|
|
|
1445
1622
|
if is_top_level:
|
|
1446
1623
|
best_path, _ = one_way_two_opt_streaming(best_path, G_func)
|
|
1447
1624
|
|
|
1448
1625
|
if k_neighbors > 0:
|
|
1449
|
-
|
|
1626
|
+
if is_parallel:
|
|
1627
|
+
best_path, _ = targeted_three_opt_streaming_parallel(best_path, G_func, neighbor_lists, k_neighbors)
|
|
1628
|
+
else:
|
|
1629
|
+
best_path, _ = targeted_three_opt_streaming(best_path, G_func, neighbor_lists, k_neighbors)
|
|
1450
1630
|
|
|
1451
1631
|
best_path = restitch_streaming(G_func, best_path)
|
|
1452
1632
|
|
|
@@ -1514,4 +1694,4 @@ def tsp_symmetric_streaming(
|
|
|
1514
1694
|
for i in range(len(neighbor_lists)):
|
|
1515
1695
|
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1516
1696
|
|
|
1517
|
-
return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0], np.array(neighbor_lists))
|
|
1697
|
+
return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0], np.array(neighbor_lists), is_parallel)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='7.4.
|
|
54
|
+
version='7.4.4',
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|