PyQrackIsing 7.3.0__tar.gz → 7.4.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.
Files changed (30) hide show
  1. {pyqrackising-7.3.0/pyqrackising.egg-info → pyqrackising-7.4.0}/PKG-INFO +1 -1
  2. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyproject.toml +1 -1
  3. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/tsp.py +137 -78
  4. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/tsp_maxcut.py +6 -6
  5. {pyqrackising-7.3.0 → pyqrackising-7.4.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/setup.py +1 -1
  7. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/CMakeLists.txt +0 -0
  8. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/LICENSE.md +0 -0
  9. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/MANIFEST.in +0 -0
  10. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/README.md +0 -0
  11. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/__init__.py +0 -0
  12. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  13. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  14. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/generate_tfim_samples.py +0 -0
  15. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/kernels.cl +0 -0
  16. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/maxcut_tfim.py +0 -0
  17. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  18. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  19. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/maxcut_tfim_util.py +0 -0
  20. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/spin_glass_solver.py +0 -0
  21. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  22. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  23. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/spin_glass_solver_util.py +0 -0
  24. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/tfim_magnetization.py +0 -0
  25. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  26. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-7.3.0 → pyqrackising-7.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.3.0
3
+ Version: 7.4.0
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.3.0"
15
+ version = "7.4.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"}
@@ -1,12 +1,35 @@
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
3
  import itertools
4
+ import multiprocessing
5
+ import multiprocessing.pool
4
6
  import networkx as nx
5
7
  from numba import njit
6
8
  import numpy as np
7
9
  from scipy.sparse import lil_matrix
8
10
 
9
11
 
12
+ # See https://stackoverflow.com/questions/6974695/python-process-pool-non-daemonic#answer-53180921
13
+ class NoDaemonProcess(multiprocessing.Process):
14
+ @property
15
+ def daemon(self):
16
+ return False
17
+
18
+ @daemon.setter
19
+ def daemon(self, value):
20
+ pass
21
+
22
+
23
+ class NoDaemonContext(type(multiprocessing.get_context())):
24
+ Process = NoDaemonProcess
25
+
26
+
27
+ class NestablePool(multiprocessing.pool.Pool):
28
+ def __init__(self, *args, **kwargs):
29
+ kwargs['context'] = NoDaemonContext()
30
+ super(NestablePool, self).__init__(*args, **kwargs)
31
+
32
+
10
33
  # two_opt() and targeted_three_opt() written by Elara (OpenAI ChatGPT instance)
11
34
  @njit
12
35
  def path_length(path, G_m):
@@ -516,7 +539,8 @@ def tsp_symmetric(
516
539
  k_neighbors=20,
517
540
  is_cyclic=True,
518
541
  multi_start=1,
519
- is_top_level=True
542
+ is_top_level=True,
543
+ is_parallel=False
520
544
  ):
521
545
  dtype = opencl_context.dtype
522
546
  nodes = None
@@ -576,32 +600,40 @@ def tsp_symmetric(
576
600
 
577
601
  G_a, G_b = init_G_a_b(G_m, a, b)
578
602
 
579
- sol_a = tsp_symmetric(
580
- G_a,
581
- quality=quality,
582
- shots=shots,
583
- is_alt_gpu_sampling=is_alt_gpu_sampling,
584
- is_base_maxcut_gpu=is_base_maxcut_gpu,
585
- is_combo_maxcut_gpu=is_combo_maxcut_gpu,
586
- monte_carlo=monte_carlo,
587
- is_cyclic=False,
588
- is_top_level=False,
589
- k_neighbors=0,
590
- multi_start=multi_start
591
- )
592
- sol_b = tsp_symmetric(
593
- G_b,
594
- quality=quality,
595
- shots=shots,
596
- is_alt_gpu_sampling=is_alt_gpu_sampling,
597
- is_base_maxcut_gpu=is_base_maxcut_gpu,
598
- is_combo_maxcut_gpu=is_combo_maxcut_gpu,
599
- monte_carlo=monte_carlo,
600
- is_cyclic=False,
601
- is_top_level=False,
602
- k_neighbors=0,
603
- multi_start=multi_start
604
- )
603
+ if monte_carlo and is_parallel and len(a) > 3 and len(b) > 3:
604
+ args = (
605
+ (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),
606
+ (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)
607
+ )
608
+ with NestablePool(2) as pool:
609
+ sol_a, sol_b = pool.starmap(tsp_symmetric, args)
610
+ else:
611
+ sol_a = tsp_symmetric(
612
+ G_a,
613
+ quality=quality,
614
+ shots=shots,
615
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
616
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
617
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
618
+ monte_carlo=monte_carlo,
619
+ is_cyclic=False,
620
+ is_top_level=False,
621
+ k_neighbors=0,
622
+ multi_start=multi_start
623
+ )
624
+ sol_b = tsp_symmetric(
625
+ G_b,
626
+ quality=quality,
627
+ shots=shots,
628
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
629
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
630
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
631
+ monte_carlo=monte_carlo,
632
+ is_cyclic=False,
633
+ is_top_level=False,
634
+ k_neighbors=0,
635
+ multi_start=multi_start
636
+ )
605
637
 
606
638
  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)
607
639
 
@@ -701,7 +733,8 @@ def tsp_asymmetric(
701
733
  k_neighbors=20,
702
734
  is_cyclic=True,
703
735
  multi_start=1,
704
- is_top_level=True
736
+ is_top_level=True,
737
+ is_parallel=False
705
738
  ):
706
739
  dtype = opencl_context.dtype
707
740
  nodes = None
@@ -765,32 +798,40 @@ def tsp_asymmetric(
765
798
 
766
799
  G_a, G_b = init_G_a_b(G_m, a, b)
767
800
 
768
- sol_a = tsp_asymmetric(
769
- G_a,
770
- quality=quality,
771
- shots=shots,
772
- is_alt_gpu_sampling=is_alt_gpu_sampling,
773
- is_base_maxcut_gpu=is_base_maxcut_gpu,
774
- is_combo_maxcut_gpu=is_combo_maxcut_gpu,
775
- monte_carlo=monte_carlo,
776
- is_cyclic=False,
777
- is_top_level=False,
778
- k_neighbors=0,
779
- multi_start=multi_start
780
- )
781
- sol_b = tsp_asymmetric(
782
- G_b,
783
- quality=quality,
784
- shots=shots,
785
- is_alt_gpu_sampling=is_alt_gpu_sampling,
786
- is_base_maxcut_gpu=is_base_maxcut_gpu,
787
- is_combo_maxcut_gpu=is_combo_maxcut_gpu,
788
- monte_carlo=monte_carlo,
789
- is_cyclic=False,
790
- is_top_level=False,
791
- k_neighbors=0,
792
- multi_start=multi_start
793
- )
801
+ if monte_carlo and is_parallel and len(a) > 2 and len(b) > 2:
802
+ args = (
803
+ (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),
804
+ (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)
805
+ )
806
+ with NestablePool(2) as pool:
807
+ sol_a, sol_b = pool.starmap(tsp_asymmetric, args)
808
+ else:
809
+ sol_a = tsp_asymmetric(
810
+ G_a,
811
+ quality=quality,
812
+ shots=shots,
813
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
814
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
815
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
816
+ monte_carlo=monte_carlo,
817
+ is_cyclic=False,
818
+ is_top_level=False,
819
+ k_neighbors=0,
820
+ multi_start=multi_start
821
+ )
822
+ sol_b = tsp_asymmetric(
823
+ G_b,
824
+ quality=quality,
825
+ shots=shots,
826
+ is_alt_gpu_sampling=is_alt_gpu_sampling,
827
+ is_base_maxcut_gpu=is_base_maxcut_gpu,
828
+ is_combo_maxcut_gpu=is_combo_maxcut_gpu,
829
+ monte_carlo=monte_carlo,
830
+ is_cyclic=False,
831
+ is_top_level=False,
832
+ k_neighbors=0,
833
+ multi_start=multi_start
834
+ )
794
835
 
795
836
  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)
796
837
 
@@ -1126,7 +1167,8 @@ def tsp_symmetric_sparse_driver(G_data, G_rows, G_cols, is_top_level, k_neighbor
1126
1167
  def tsp_symmetric_sparse(
1127
1168
  G,
1128
1169
  k_neighbors=20,
1129
- is_top_level=True
1170
+ is_top_level=True,
1171
+ is_parallel=True
1130
1172
  ):
1131
1173
  dtype = opencl_context.dtype
1132
1174
  nodes = None
@@ -1153,16 +1195,24 @@ def tsp_symmetric_sparse(
1153
1195
 
1154
1196
  G_a, G_b = init_G_a_b_sparse(G_m, a, b, dtype)
1155
1197
 
1156
- sol_a = tsp_symmetric_sparse(
1157
- G_a,
1158
- is_top_level=False,
1159
- k_neighbors=0
1160
- )
1161
- sol_b = tsp_symmetric_sparse(
1162
- G_b,
1163
- is_top_level=False,
1164
- k_neighbors=0
1165
- )
1198
+ if is_parallel and len(a) > 3 and len(b) > 3:
1199
+ args = (
1200
+ (G_a, 0, False, True),
1201
+ (G_b, 0, False, True)
1202
+ )
1203
+ with NestablePool(2) as pool:
1204
+ sol_a, sol_b = pool.starmap(tsp_symmetric_sparse, args)
1205
+ else:
1206
+ sol_a = tsp_symmetric_sparse(
1207
+ G_a,
1208
+ is_top_level=False,
1209
+ k_neighbors=0
1210
+ )
1211
+ sol_b = tsp_symmetric_sparse(
1212
+ G_b,
1213
+ is_top_level=False,
1214
+ k_neighbors=0
1215
+ )
1166
1216
 
1167
1217
  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)
1168
1218
 
@@ -1440,7 +1490,8 @@ def tsp_symmetric_streaming(
1440
1490
  G_func,
1441
1491
  nodes,
1442
1492
  k_neighbors=20,
1443
- is_top_level=True
1493
+ is_top_level=True,
1494
+ is_parallel=True
1444
1495
  ):
1445
1496
  dtype = opencl_context.dtype
1446
1497
  n_nodes = len(nodes)
@@ -1455,17 +1506,25 @@ def tsp_symmetric_streaming(
1455
1506
 
1456
1507
  a, b = monte_carlo_loop(n_nodes)
1457
1508
 
1458
- sol_a = tsp_symmetric_streaming(
1459
- G_func,
1460
- a,
1461
- is_top_level=False,
1462
- k_neighbors=0
1463
- )
1464
- sol_b = tsp_symmetric_streaming(
1465
- G_func,
1466
- b,
1467
- is_top_level=False,
1468
- k_neighbors=0
1469
- )
1509
+ if is_parallel and len(a) > 3 and len(b) > 3:
1510
+ args = (
1511
+ (G_func, a, 0, False, True),
1512
+ (G_func, b, 0, False, True)
1513
+ )
1514
+ with NestablePool(2) as pool:
1515
+ sol_a, sol_b = pool.starmap(tsp_symmetric_streaming, args)
1516
+ else:
1517
+ sol_a = tsp_symmetric_streaming(
1518
+ G_func,
1519
+ a,
1520
+ is_top_level=False,
1521
+ k_neighbors=0
1522
+ )
1523
+ sol_b = tsp_symmetric_streaming(
1524
+ G_func,
1525
+ b,
1526
+ is_top_level=False,
1527
+ k_neighbors=0
1528
+ )
1470
1529
 
1471
1530
  return tsp_symmetric_streaming_driver(G_func, is_top_level, k_neighbors, nodes, sol_a[0], sol_b[0])
@@ -73,7 +73,7 @@ def get_bitstring(partition, nodes):
73
73
  return bitstring
74
74
 
75
75
 
76
- def tsp_maxcut(G, k_neighbors=20, is_optimized=False, **kwargs):
76
+ def tsp_maxcut(G, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs):
77
77
  G_m = None
78
78
  if isinstance(G, nx.Graph):
79
79
  nodes = list(G.nodes())
@@ -84,7 +84,7 @@ def tsp_maxcut(G, k_neighbors=20, is_optimized=False, **kwargs):
84
84
  nodes = list(range(n_qubits))
85
85
  G_m = G
86
86
 
87
- path, length = tsp_symmetric(G, is_cyclic=False, monte_carlo=True, k_neighbors=k_neighbors)
87
+ path, length = tsp_symmetric(G, is_cyclic=False, monte_carlo=True, k_neighbors=k_neighbors, is_parallel=is_parallel)
88
88
  partition, cut_value = tsp_to_maxcut_bipartition(path, G_m)
89
89
 
90
90
  if not is_optimized:
@@ -162,7 +162,7 @@ def tsp_to_maxcut_bipartition_sparse(tsp_path, G_data, G_rows, G_cols):
162
162
  return best_partition, best_cut_value
163
163
 
164
164
 
165
- def tsp_maxcut_sparse(G, k_neighbors=20, is_optimized=False, **kwargs):
165
+ def tsp_maxcut_sparse(G, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs):
166
166
  G_m = None
167
167
  if isinstance(G, nx.Graph):
168
168
  nodes = list(G.nodes())
@@ -173,7 +173,7 @@ def tsp_maxcut_sparse(G, k_neighbors=20, is_optimized=False, **kwargs):
173
173
  nodes = list(range(n_qubits))
174
174
  G_m = G
175
175
 
176
- path, length = tsp_symmetric_sparse(G, k_neighbors=k_neighbors)
176
+ path, length = tsp_symmetric_sparse(G, k_neighbors=k_neighbors, is_parallel=is_parallel)
177
177
  partition, cut_value = tsp_to_maxcut_bipartition_sparse(path, G_m.data, G_m.indptr, G_m.indices)
178
178
 
179
179
  if not is_optimized:
@@ -242,9 +242,9 @@ def tsp_to_maxcut_bipartition_streaming(tsp_path, G_func):
242
242
  return best_partition, best_cut_value
243
243
 
244
244
 
245
- def tsp_maxcut_streaming(G_func, nodes, k_neighbors=20, is_optimized=False, **kwargs):
245
+ def tsp_maxcut_streaming(G_func, nodes, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs):
246
246
  n_qubits = len(nodes)
247
- path, length = tsp_symmetric_streaming(G_func, nodes, k_neighbors=k_neighbors)
247
+ path, length = tsp_symmetric_streaming(G_func, nodes, k_neighbors=k_neighbors, is_parallel=is_parallel)
248
248
  partition, cut_value = tsp_to_maxcut_bipartition_streaming(path, G_func)
249
249
 
250
250
  if not is_optimized:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.3.0
3
+ Version: 7.4.0
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.3.0',
54
+ version='7.4.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