PyQrackIsing 7.4.1__tar.gz → 7.4.2__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.
Files changed (30) hide show
  1. {pyqrackising-7.4.1/pyqrackising.egg-info → pyqrackising-7.4.2}/PKG-INFO +1 -1
  2. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyproject.toml +1 -1
  3. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/tsp.py +68 -68
  4. {pyqrackising-7.4.1 → pyqrackising-7.4.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/setup.py +1 -1
  6. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/CMakeLists.txt +0 -0
  7. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/LICENSE.md +0 -0
  8. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/MANIFEST.in +0 -0
  9. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/README.md +0 -0
  10. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/__init__.py +0 -0
  11. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/_pyqrack_ising.cpp +0 -0
  12. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  13. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/generate_tfim_samples.py +0 -0
  14. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/kernels.cl +0 -0
  15. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/maxcut_tfim.py +0 -0
  16. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  17. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/maxcut_tfim_util.py +0 -0
  19. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/spin_glass_solver.py +0 -0
  20. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  21. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  22. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/spin_glass_solver_util.py +0 -0
  23. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/tfim_magnetization.py +0 -0
  24. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  25. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising/tsp_maxcut.py +0 -0
  26. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-7.4.1 → pyqrackising-7.4.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.4.1
3
+ Version: 7.4.2
4
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
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "7.4.1"
15
+ version = "7.4.2"
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"}
@@ -109,7 +109,7 @@ def two_opt(path, G):
109
109
 
110
110
 
111
111
  @njit
112
- def targeted_three_opt(path, W, k_neighbors=20):
112
+ def targeted_three_opt(path, W, neighbor_lists, k_neighbors=20):
113
113
  """
114
114
  Lin-Kernighan style 3-opt heuristic for TSP improvement.
115
115
 
@@ -123,11 +123,6 @@ def targeted_three_opt(path, W, k_neighbors=20):
123
123
  best_dist = path_length(best_path, W)
124
124
  improved = True
125
125
 
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
126
  while improved:
132
127
  improved = False
133
128
  for i in range(n - 5):
@@ -461,7 +456,7 @@ def tsp_symmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic):
461
456
 
462
457
 
463
458
  @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):
459
+ 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
460
  path_a = [a[x] for x in sol_a[0]]
466
461
  path_b = [b[x] for x in sol_b[0]]
467
462
 
@@ -494,7 +489,7 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
494
489
  best_path, _ = one_way_two_opt(best_path, G_m)
495
490
 
496
491
  if k_neighbors > 0:
497
- best_path, _ = targeted_three_opt(best_path, G_m, k_neighbors)
492
+ best_path, _ = targeted_three_opt(best_path, G_m, neighbor_lists, k_neighbors)
498
493
 
499
494
  # We just corrected segments of 2 and 3,
500
495
  # and this is top level,
@@ -615,7 +610,24 @@ def tsp_symmetric(
615
610
  is_parallel=False
616
611
  )
617
612
 
618
- 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)
613
+ neighbor_lists = [[0]]
614
+ if k_neighbors > 0:
615
+ # Precompute nearest neighbors for each node
616
+ neighbor_lists = [
617
+ ([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
618
+ ]
619
+
620
+ for i in range(n_nodes):
621
+ for j in range(n_nodes):
622
+ val = G_m[i, j]
623
+ if val < neighbor_lists[i][-1][0]:
624
+ neighbor_lists[i][-1] = (val, j)
625
+ neighbor_lists[i].sort(key=lambda x: x[0])
626
+
627
+ for i in range(len(neighbor_lists)):
628
+ neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
629
+
630
+ 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
631
 
620
632
 
621
633
  @njit
@@ -684,14 +696,11 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
684
696
  path, weight = targeted_three_opt(best_path.copy(), G_m, k_neighbors)
685
697
  if weight < best_weight:
686
698
  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
699
  else:
693
700
  final_path = best_path
694
701
 
702
+ final_path = restitch(G_m, final_path, True)
703
+
695
704
  best_weight = path_length(final_path, G_m)
696
705
 
697
706
  if is_reversed:
@@ -1102,42 +1111,21 @@ def init_G_a_b_sparse(G_m, a, b, dtype):
1102
1111
 
1103
1112
  return G_a.tocsr(), G_b.tocsr()
1104
1113
 
1105
- def tsp_symmetric_sparse_driver(G_data, G_rows, G_cols, is_top_level, k_neighbors, nodes, sol_a, sol_b, a, b):
1114
+
1115
+ @njit
1116
+ 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
1117
  path_a = [a[x] for x in sol_a[0]]
1107
1118
  path_b = [b[x] for x in sol_b[0]]
1108
1119
 
1109
- restitch_sparse(G_data, G_rows, G_cols, path_a)
1110
- restitch_sparse(G_data, G_rows, G_cols, path_b)
1111
-
1112
1120
  best_path = stitch_sparse_symmetric(G_data, G_rows, G_cols, path_a, path_b)
1113
1121
 
1114
1122
  if is_top_level:
1115
1123
  best_path, _ = one_way_two_opt_sparse(best_path, G_data, G_rows, G_cols)
1116
1124
 
1117
1125
  if k_neighbors > 0:
1118
- # Precompute nearest neighbors for each node
1119
- n_rows = len(G_rows) - 1
1120
-
1121
- neighbor_lists = [
1122
- ([(float("inf"), 0)] * k_neighbors) for i in range(n_rows)
1123
- ]
1126
+ best_path, _ = targeted_three_opt_sparse(best_path, G_data, G_rows, G_cols, neighbor_lists, k_neighbors)
1124
1127
 
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)
1136
-
1137
- # We just corrected segments of 2 and 3,
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)
1128
+ best_path = restitch_sparse(G_data, G_rows, G_cols, best_path)
1141
1129
 
1142
1130
  best_weight = path_length_sparse(best_path, G_data, G_rows, G_cols)
1143
1131
 
@@ -1194,7 +1182,24 @@ def tsp_symmetric_sparse(
1194
1182
  is_parallel=False
1195
1183
  )
1196
1184
 
1197
- 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)
1185
+ neighbor_lists = [[0]]
1186
+ if k_neighbors > 0:
1187
+ # Precompute nearest neighbors for each node
1188
+ neighbor_lists = [
1189
+ ([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
1190
+ ]
1191
+
1192
+ for i in range(n_nodes):
1193
+ for j in range(n_nodes):
1194
+ val = G_m[i, j]
1195
+ if val < neighbor_lists[i][-1][0]:
1196
+ neighbor_lists[i][-1] = (val, j)
1197
+ neighbor_lists[i].sort(key=lambda x: x[0])
1198
+
1199
+ for i in range(len(neighbor_lists)):
1200
+ neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
1201
+
1202
+ 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
1203
 
1199
1204
 
1200
1205
  @njit
@@ -1427,39 +1432,17 @@ def tsp_streaming_bruteforce(G_func, perms, n):
1427
1432
  return best_path, best_weight
1428
1433
 
1429
1434
 
1430
- def tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, path_a, path_b):
1431
- restitch_streaming(G_func, path_a)
1432
- restitch_streaming(G_func, path_b)
1433
-
1435
+ @njit
1436
+ def tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, path_a, path_b, neighbor_lists):
1434
1437
  best_path = stitch_streaming_symmetric(G_func, path_a, path_b)
1435
1438
 
1436
1439
  if is_top_level:
1437
1440
  best_path, _ = one_way_two_opt_streaming(best_path, G_func)
1438
1441
 
1439
1442
  if k_neighbors > 0:
1440
- # Precompute nearest neighbors for each node
1441
- n_rows = len(nodes)
1442
-
1443
- neighbor_lists = [
1444
- ([(float("inf"), 0)] * k_neighbors) for i in range(n_rows)
1445
- ]
1446
-
1447
- for i in nodes:
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])
1443
+ best_path, _ = targeted_three_opt_streaming(best_path, G_func, neighbor_lists, k_neighbors)
1453
1444
 
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)
1445
+ best_path = restitch_streaming(G_func, best_path)
1463
1446
 
1464
1447
  best_weight = path_length_streaming(best_path, G_func)
1465
1448
 
@@ -1507,4 +1490,21 @@ def tsp_symmetric_streaming(
1507
1490
  is_parallel=False
1508
1491
  )
1509
1492
 
1510
- return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0])
1493
+ neighbor_lists = [[0]]
1494
+ if k_neighbors > 0:
1495
+ # Precompute nearest neighbors for each node
1496
+ neighbor_lists = [
1497
+ ([(float("inf"), 0)] * k_neighbors) for i in range(n_nodes)
1498
+ ]
1499
+
1500
+ for i in nodes:
1501
+ for j in nodes:
1502
+ val = G_func(i, j)
1503
+ if val < neighbor_lists[i][-1][0]:
1504
+ neighbor_lists[i][-1] = (val, j)
1505
+ neighbor_lists[i].sort(key=lambda x: x[0])
1506
+
1507
+ for i in range(len(neighbor_lists)):
1508
+ neighbor_lists[i] = [c[1] for c in neighbor_lists[i]]
1509
+
1510
+ return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0], np.array(neighbor_lists))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.4.1
3
+ Version: 7.4.2
4
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
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='7.4.1',
54
+ version='7.4.2',
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