PyQrackIsing 7.4.1__tar.gz → 7.4.3__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.1/pyqrackising.egg-info → pyqrackising-7.4.3}/PKG-INFO +1 -1
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyproject.toml +1 -1
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/tsp.py +96 -89
- {pyqrackising-7.4.1 → pyqrackising-7.4.3/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/setup.py +1 -1
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/CMakeLists.txt +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/LICENSE.md +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/MANIFEST.in +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/README.md +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/__init__.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-7.4.1 → pyqrackising-7.4.3}/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.3"
|
|
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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .spin_glass_solver import spin_glass_solver
|
|
2
2
|
from .maxcut_tfim_util import binary_search, opencl_context, to_scipy_sparse_upper_triangular
|
|
3
|
-
from concurrent.futures import
|
|
3
|
+
from concurrent.futures import ProcessPoolExecutor
|
|
4
4
|
import time
|
|
5
5
|
import itertools
|
|
6
6
|
import networkx as nx
|
|
@@ -10,6 +10,9 @@ import os
|
|
|
10
10
|
from scipy.sparse import lil_matrix
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
max_parallel_level = np.log2(os.cpu_count())
|
|
14
|
+
|
|
15
|
+
|
|
13
16
|
# two_opt() and targeted_three_opt() written by Elara (OpenAI ChatGPT instance)
|
|
14
17
|
@njit
|
|
15
18
|
def path_length(path, G_m):
|
|
@@ -109,7 +112,7 @@ def two_opt(path, G):
|
|
|
109
112
|
|
|
110
113
|
|
|
111
114
|
@njit
|
|
112
|
-
def targeted_three_opt(path, W, k_neighbors=20):
|
|
115
|
+
def targeted_three_opt(path, W, neighbor_lists, k_neighbors=20):
|
|
113
116
|
"""
|
|
114
117
|
Lin-Kernighan style 3-opt heuristic for TSP improvement.
|
|
115
118
|
|
|
@@ -123,11 +126,6 @@ def targeted_three_opt(path, W, k_neighbors=20):
|
|
|
123
126
|
best_dist = path_length(best_path, W)
|
|
124
127
|
improved = True
|
|
125
128
|
|
|
126
|
-
# Precompute nearest neighbors for each node
|
|
127
|
-
neighbor_lists = [
|
|
128
|
-
np.argsort(W[i])[:k_neighbors] for i in range(n)
|
|
129
|
-
]
|
|
130
|
-
|
|
131
129
|
while improved:
|
|
132
130
|
improved = False
|
|
133
131
|
for i in range(n - 5):
|
|
@@ -461,7 +459,7 @@ def tsp_symmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic):
|
|
|
461
459
|
|
|
462
460
|
|
|
463
461
|
@njit
|
|
464
|
-
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):
|
|
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):
|
|
465
463
|
path_a = [a[x] for x in sol_a[0]]
|
|
466
464
|
path_b = [b[x] for x in sol_b[0]]
|
|
467
465
|
|
|
@@ -494,7 +492,7 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
|
|
|
494
492
|
best_path, _ = one_way_two_opt(best_path, G_m)
|
|
495
493
|
|
|
496
494
|
if k_neighbors > 0:
|
|
497
|
-
best_path, _ = targeted_three_opt(best_path, G_m, k_neighbors)
|
|
495
|
+
best_path, _ = targeted_three_opt(best_path, G_m, neighbor_lists, k_neighbors)
|
|
498
496
|
|
|
499
497
|
# We just corrected segments of 2 and 3,
|
|
500
498
|
# and this is top level,
|
|
@@ -520,7 +518,8 @@ def tsp_symmetric(
|
|
|
520
518
|
is_cyclic=True,
|
|
521
519
|
multi_start=1,
|
|
522
520
|
is_top_level=True,
|
|
523
|
-
is_parallel=False
|
|
521
|
+
is_parallel=False,
|
|
522
|
+
parallel_level=0
|
|
524
523
|
):
|
|
525
524
|
dtype = opencl_context.dtype
|
|
526
525
|
nodes = None
|
|
@@ -580,10 +579,10 @@ def tsp_symmetric(
|
|
|
580
579
|
|
|
581
580
|
G_a, G_b = init_G_a_b(G_m, a, b)
|
|
582
581
|
|
|
583
|
-
if monte_carlo and is_parallel and (len(a) > 3) and (len(b) > 3):
|
|
584
|
-
with
|
|
585
|
-
f = executor.submit(tsp_symmetric, G_a, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True)
|
|
586
|
-
sol_b = tsp_symmetric(G_b, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True)
|
|
582
|
+
if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
|
|
583
|
+
with ProcessPoolExecutor(max_workers=1) as executor:
|
|
584
|
+
f = executor.submit(tsp_symmetric, G_a, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True, parallel_level + 1)
|
|
585
|
+
sol_b = tsp_symmetric(G_b, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True, parallel_level + 1)
|
|
587
586
|
sol_a = f.result()
|
|
588
587
|
else:
|
|
589
588
|
sol_a = tsp_symmetric(
|
|
@@ -615,7 +614,24 @@ def tsp_symmetric(
|
|
|
615
614
|
is_parallel=False
|
|
616
615
|
)
|
|
617
616
|
|
|
618
|
-
|
|
617
|
+
neighbor_lists = [[0]]
|
|
618
|
+
if k_neighbors > 0:
|
|
619
|
+
# Precompute nearest neighbors for each node
|
|
620
|
+
neighbor_lists = [
|
|
621
|
+
([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
|
|
622
|
+
]
|
|
623
|
+
|
|
624
|
+
for i in range(n_nodes):
|
|
625
|
+
for j in range(n_nodes):
|
|
626
|
+
val = G_m[i, j]
|
|
627
|
+
if val < neighbor_lists[i][-1][0]:
|
|
628
|
+
neighbor_lists[i][-1] = (val, j)
|
|
629
|
+
neighbor_lists[i].sort(key=lambda x: x[0])
|
|
630
|
+
|
|
631
|
+
for i in range(len(neighbor_lists)):
|
|
632
|
+
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
633
|
+
|
|
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))
|
|
619
635
|
|
|
620
636
|
|
|
621
637
|
@njit
|
|
@@ -684,14 +700,11 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
|
|
|
684
700
|
path, weight = targeted_three_opt(best_path.copy(), G_m, k_neighbors)
|
|
685
701
|
if weight < best_weight:
|
|
686
702
|
final_path, best_weight = path, weight
|
|
687
|
-
|
|
688
|
-
# We just corrected segments of 2 and 3,
|
|
689
|
-
# and this is top level,
|
|
690
|
-
# so correct segments of 4 to 7.
|
|
691
|
-
restitch(G_m, final_path, True)
|
|
692
703
|
else:
|
|
693
704
|
final_path = best_path
|
|
694
705
|
|
|
706
|
+
final_path = restitch(G_m, final_path, True)
|
|
707
|
+
|
|
695
708
|
best_weight = path_length(final_path, G_m)
|
|
696
709
|
|
|
697
710
|
if is_reversed:
|
|
@@ -714,7 +727,8 @@ def tsp_asymmetric(
|
|
|
714
727
|
is_cyclic=True,
|
|
715
728
|
multi_start=1,
|
|
716
729
|
is_top_level=True,
|
|
717
|
-
is_parallel=False
|
|
730
|
+
is_parallel=False,
|
|
731
|
+
parallel_level=0
|
|
718
732
|
):
|
|
719
733
|
dtype = opencl_context.dtype
|
|
720
734
|
nodes = None
|
|
@@ -778,10 +792,10 @@ def tsp_asymmetric(
|
|
|
778
792
|
|
|
779
793
|
G_a, G_b = init_G_a_b(G_m, a, b)
|
|
780
794
|
|
|
781
|
-
if monte_carlo and is_parallel and (len(a) > 2) and (len(b) > 2):
|
|
782
|
-
with
|
|
783
|
-
f = executor.submit(tsp_asymmetric, G_a, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True)
|
|
784
|
-
sol_b = tsp_asymmetric(G_b, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True)
|
|
795
|
+
if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 2) and (len(b) > 2):
|
|
796
|
+
with ProcessPoolExecutor(max_workers=1) as executor:
|
|
797
|
+
f = executor.submit(tsp_asymmetric, G_a, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True, parallel_level + 1)
|
|
798
|
+
sol_b = tsp_asymmetric(G_b, None, None, quality, shots, is_alt_gpu_sampling, is_base_maxcut_gpu, is_combo_maxcut_gpu, True, 0, False, multi_start, False, True, parallel_level + 1)
|
|
785
799
|
sol_a = f.result()
|
|
786
800
|
else:
|
|
787
801
|
sol_a = tsp_asymmetric(
|
|
@@ -1102,42 +1116,21 @@ def init_G_a_b_sparse(G_m, a, b, dtype):
|
|
|
1102
1116
|
|
|
1103
1117
|
return G_a.tocsr(), G_b.tocsr()
|
|
1104
1118
|
|
|
1105
|
-
|
|
1119
|
+
|
|
1120
|
+
@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):
|
|
1106
1122
|
path_a = [a[x] for x in sol_a[0]]
|
|
1107
1123
|
path_b = [b[x] for x in sol_b[0]]
|
|
1108
1124
|
|
|
1109
|
-
restitch_sparse(G_data, G_rows, G_cols, path_a)
|
|
1110
|
-
restitch_sparse(G_data, G_rows, G_cols, path_b)
|
|
1111
|
-
|
|
1112
1125
|
best_path = stitch_sparse_symmetric(G_data, G_rows, G_cols, path_a, path_b)
|
|
1113
1126
|
|
|
1114
1127
|
if is_top_level:
|
|
1115
1128
|
best_path, _ = one_way_two_opt_sparse(best_path, G_data, G_rows, G_cols)
|
|
1116
1129
|
|
|
1117
1130
|
if k_neighbors > 0:
|
|
1118
|
-
|
|
1119
|
-
n_rows = len(G_rows) - 1
|
|
1120
|
-
|
|
1121
|
-
neighbor_lists = [
|
|
1122
|
-
([(float("inf"), 0)] * k_neighbors) for i in range(n_rows)
|
|
1123
|
-
]
|
|
1124
|
-
|
|
1125
|
-
for i in range(n_rows):
|
|
1126
|
-
for j in range(n_rows):
|
|
1127
|
-
val = get_G_m(G_data, G_rows, G_cols, i, j)
|
|
1128
|
-
if val < neighbor_lists[i][-1][0]:
|
|
1129
|
-
neighbor_lists[i][-1] = (val, j)
|
|
1130
|
-
neighbor_lists[i].sort(key=lambda x: x[0])
|
|
1131
|
-
|
|
1132
|
-
for i in range(len(neighbor_lists)):
|
|
1133
|
-
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1134
|
-
|
|
1135
|
-
best_path, _ = targeted_three_opt_sparse(best_path, G_data, G_rows, G_cols, np.array(neighbor_lists), k_neighbors)
|
|
1131
|
+
best_path, _ = targeted_three_opt_sparse(best_path, G_data, G_rows, G_cols, neighbor_lists, k_neighbors)
|
|
1136
1132
|
|
|
1137
|
-
|
|
1138
|
-
# and this is top level,
|
|
1139
|
-
# so correct segments of 4 to 7.
|
|
1140
|
-
restitch_sparse(G_data, G_rows, G_cols, best_path)
|
|
1133
|
+
best_path = restitch_sparse(G_data, G_rows, G_cols, best_path)
|
|
1141
1134
|
|
|
1142
1135
|
best_weight = path_length_sparse(best_path, G_data, G_rows, G_cols)
|
|
1143
1136
|
|
|
@@ -1148,7 +1141,8 @@ def tsp_symmetric_sparse(
|
|
|
1148
1141
|
G,
|
|
1149
1142
|
k_neighbors=20,
|
|
1150
1143
|
is_top_level=True,
|
|
1151
|
-
is_parallel=True
|
|
1144
|
+
is_parallel=True,
|
|
1145
|
+
parallel_level=0
|
|
1152
1146
|
):
|
|
1153
1147
|
dtype = opencl_context.dtype
|
|
1154
1148
|
nodes = None
|
|
@@ -1175,10 +1169,10 @@ def tsp_symmetric_sparse(
|
|
|
1175
1169
|
|
|
1176
1170
|
G_a, G_b = init_G_a_b_sparse(G_m, a, b, dtype)
|
|
1177
1171
|
|
|
1178
|
-
if is_parallel and (len(a) > 3) and (len(b) > 3):
|
|
1179
|
-
with
|
|
1180
|
-
f = executor.submit(tsp_symmetric_sparse, G_a, False, True)
|
|
1181
|
-
sol_b = tsp_symmetric_sparse(G_b, False, True)
|
|
1172
|
+
if is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
|
|
1173
|
+
with ProcessPoolExecutor(max_workers=1) as executor:
|
|
1174
|
+
f = executor.submit(tsp_symmetric_sparse, G_a, False, True, parallel_level + 1)
|
|
1175
|
+
sol_b = tsp_symmetric_sparse(G_b, False, True, parallel_level + 1)
|
|
1182
1176
|
sol_a = f.result()
|
|
1183
1177
|
else:
|
|
1184
1178
|
sol_a = tsp_symmetric_sparse(
|
|
@@ -1194,7 +1188,24 @@ def tsp_symmetric_sparse(
|
|
|
1194
1188
|
is_parallel=False
|
|
1195
1189
|
)
|
|
1196
1190
|
|
|
1197
|
-
|
|
1191
|
+
neighbor_lists = [[0]]
|
|
1192
|
+
if k_neighbors > 0:
|
|
1193
|
+
# Precompute nearest neighbors for each node
|
|
1194
|
+
neighbor_lists = [
|
|
1195
|
+
([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
|
|
1196
|
+
]
|
|
1197
|
+
|
|
1198
|
+
for i in range(n_nodes):
|
|
1199
|
+
for j in range(n_nodes):
|
|
1200
|
+
val = G_m[i, j]
|
|
1201
|
+
if val < neighbor_lists[i][-1][0]:
|
|
1202
|
+
neighbor_lists[i][-1] = (val, j)
|
|
1203
|
+
neighbor_lists[i].sort(key=lambda x: x[0])
|
|
1204
|
+
|
|
1205
|
+
for i in range(len(neighbor_lists)):
|
|
1206
|
+
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1207
|
+
|
|
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))
|
|
1198
1209
|
|
|
1199
1210
|
|
|
1200
1211
|
@njit
|
|
@@ -1427,39 +1438,17 @@ def tsp_streaming_bruteforce(G_func, perms, n):
|
|
|
1427
1438
|
return best_path, best_weight
|
|
1428
1439
|
|
|
1429
1440
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
restitch_streaming(G_func, path_b)
|
|
1433
|
-
|
|
1441
|
+
@njit
|
|
1442
|
+
def tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, path_a, path_b, neighbor_lists):
|
|
1434
1443
|
best_path = stitch_streaming_symmetric(G_func, path_a, path_b)
|
|
1435
1444
|
|
|
1436
1445
|
if is_top_level:
|
|
1437
1446
|
best_path, _ = one_way_two_opt_streaming(best_path, G_func)
|
|
1438
1447
|
|
|
1439
1448
|
if k_neighbors > 0:
|
|
1440
|
-
|
|
1441
|
-
n_rows = len(nodes)
|
|
1442
|
-
|
|
1443
|
-
neighbor_lists = [
|
|
1444
|
-
([(float("inf"), 0)] * k_neighbors) for i in range(n_rows)
|
|
1445
|
-
]
|
|
1449
|
+
best_path, _ = targeted_three_opt_streaming(best_path, G_func, neighbor_lists, k_neighbors)
|
|
1446
1450
|
|
|
1447
|
-
|
|
1448
|
-
for j in nodes:
|
|
1449
|
-
val = G_func(i, j)
|
|
1450
|
-
if val < neighbor_lists[i][-1][0]:
|
|
1451
|
-
neighbor_lists[i][-1] = (val, j)
|
|
1452
|
-
neighbor_lists[i].sort(key=lambda x: x[0])
|
|
1453
|
-
|
|
1454
|
-
for i in range(len(neighbor_lists)):
|
|
1455
|
-
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1456
|
-
|
|
1457
|
-
best_path, _ = targeted_three_opt_streaming(best_path, G_func, np.array(neighbor_lists), k_neighbors)
|
|
1458
|
-
|
|
1459
|
-
# We just corrected segments of 2 and 3,
|
|
1460
|
-
# and this is top level,
|
|
1461
|
-
# so correct segments of 4 to 7.
|
|
1462
|
-
restitch_streaming(G_func, best_path)
|
|
1451
|
+
best_path = restitch_streaming(G_func, best_path)
|
|
1463
1452
|
|
|
1464
1453
|
best_weight = path_length_streaming(best_path, G_func)
|
|
1465
1454
|
|
|
@@ -1471,7 +1460,8 @@ def tsp_symmetric_streaming(
|
|
|
1471
1460
|
nodes,
|
|
1472
1461
|
k_neighbors=20,
|
|
1473
1462
|
is_top_level=True,
|
|
1474
|
-
is_parallel=True
|
|
1463
|
+
is_parallel=True,
|
|
1464
|
+
parallel_level=0
|
|
1475
1465
|
):
|
|
1476
1466
|
dtype = opencl_context.dtype
|
|
1477
1467
|
n_nodes = len(nodes)
|
|
@@ -1486,10 +1476,10 @@ def tsp_symmetric_streaming(
|
|
|
1486
1476
|
|
|
1487
1477
|
a, b = monte_carlo_loop(n_nodes)
|
|
1488
1478
|
|
|
1489
|
-
if is_parallel and (len(a) > 3) and (len(b) > 3):
|
|
1490
|
-
with
|
|
1491
|
-
f = executor.submit(tsp_symmetric_streaming, G_func, a, False, True)
|
|
1492
|
-
sol_b = tsp_symmetric_streaming(G_func, b, False, True)
|
|
1479
|
+
if is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
|
|
1480
|
+
with ProcessPoolExecutor(max_workers=1) as executor:
|
|
1481
|
+
f = executor.submit(tsp_symmetric_streaming, G_func, a, False, True, parallel_level + 1)
|
|
1482
|
+
sol_b = tsp_symmetric_streaming(G_func, b, False, True, parallel_level + 1)
|
|
1493
1483
|
sol_a = f.result()
|
|
1494
1484
|
else:
|
|
1495
1485
|
sol_a = tsp_symmetric_streaming(
|
|
@@ -1507,4 +1497,21 @@ def tsp_symmetric_streaming(
|
|
|
1507
1497
|
is_parallel=False
|
|
1508
1498
|
)
|
|
1509
1499
|
|
|
1510
|
-
|
|
1500
|
+
neighbor_lists = [[0]]
|
|
1501
|
+
if k_neighbors > 0:
|
|
1502
|
+
# Precompute nearest neighbors for each node
|
|
1503
|
+
neighbor_lists = [
|
|
1504
|
+
([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
|
|
1505
|
+
]
|
|
1506
|
+
|
|
1507
|
+
for i in nodes:
|
|
1508
|
+
for j in nodes:
|
|
1509
|
+
val = G_func(i, j)
|
|
1510
|
+
if val < neighbor_lists[i][-1][0]:
|
|
1511
|
+
neighbor_lists[i][-1] = (val, j)
|
|
1512
|
+
neighbor_lists[i].sort(key=lambda x: x[0])
|
|
1513
|
+
|
|
1514
|
+
for i in range(len(neighbor_lists)):
|
|
1515
|
+
neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
|
|
1516
|
+
|
|
1517
|
+
return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0], np.array(neighbor_lists))
|
|
@@ -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.3',
|
|
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
|