PyQrackIsing 8.10.0__tar.gz → 8.10.1__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 (28) hide show
  1. {pyqrackising-8.10.0/pyqrackising.egg-info → pyqrackising-8.10.1}/PKG-INFO +1 -1
  2. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyproject.toml +1 -1
  3. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/maxcut_tfim.py +35 -18
  4. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/tsp.py +89 -71
  5. {pyqrackising-8.10.0 → pyqrackising-8.10.1/pyqrackising.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/setup.py +1 -1
  7. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/LICENSE.md +0 -0
  8. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/MANIFEST.in +0 -0
  9. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/README.md +0 -0
  10. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/__init__.py +0 -0
  11. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  12. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/generate_tfim_samples.py +0 -0
  13. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/kernels.cl +0 -0
  14. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  15. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  16. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/maxcut_tfim_util.py +0 -0
  17. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/spin_glass_solver.py +0 -0
  18. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  19. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.10.0 → pyqrackising-8.10.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.10.0
3
+ Version: 8.10.1
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
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "pyqrackising"
13
- version = "8.10.0"
13
+ version = "8.10.1"
14
14
  requires-python = ">=3.8"
15
15
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
16
16
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -158,8 +158,10 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, an
158
158
  return bit_string, best_value, (l, r)
159
159
 
160
160
 
161
- def maxcut_tfim(
162
- G,
161
+ @njit
162
+ def maxcut_tfim_pure_numba(
163
+ G_m,
164
+ nodes,
163
165
  quality=None,
164
166
  shots=None,
165
167
  is_spin_glass=False,
@@ -167,30 +169,22 @@ def maxcut_tfim(
167
169
  anneal_h=None,
168
170
  repulsion_base=None
169
171
  ):
170
- wgs = opencl_context.work_group_size
171
- nodes = None
172
- n_qubits = 0
173
- G_m = None
174
- if isinstance(G, nx.Graph):
175
- nodes = list(G.nodes())
176
- n_qubits = len(nodes)
177
- G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0, dtype=dtype)
178
- else:
179
- n_qubits = len(G)
180
- nodes = list(range(n_qubits))
181
- G_m = G
172
+ n_qubits = len(G_m)
182
173
 
183
174
  if n_qubits < 3:
175
+ empty = [nodes[0]]
176
+ empty.clear()
177
+
184
178
  if n_qubits == 0:
185
- return "", 0, ([], [])
179
+ return "", 0, (empty, empty.copy())
186
180
 
187
181
  if n_qubits == 1:
188
- return "0", 0, (nodes, [])
182
+ return "0", 0, (nodes, empty)
189
183
 
190
184
  if n_qubits == 2:
191
185
  weight = G_m[0, 1]
192
186
  if weight < 0.0:
193
- return "00", 0, (nodes, [])
187
+ return "00", 0, (nodes, empty)
194
188
 
195
189
  return "01", weight, ([nodes[0]], [nodes[1]])
196
190
 
@@ -214,6 +208,29 @@ def maxcut_tfim(
214
208
 
215
209
  if best_value < 0.0:
216
210
  # Best cut is trivial partition, all/empty
217
- return '0' * n_qubits, 0.0, (nodes, [])
211
+ empty = [nodes[0]]
212
+ empty.clear()
213
+
214
+ return '0' * n_qubits, 0.0, (nodes, empty)
218
215
 
219
216
  return bit_string, best_value, partition
217
+
218
+ def maxcut_tfim(
219
+ G,
220
+ quality=None,
221
+ shots=None,
222
+ is_spin_glass=False,
223
+ anneal_t=None,
224
+ anneal_h=None,
225
+ repulsion_base=None
226
+ ):
227
+ nodes = None
228
+ G_m = None
229
+ if isinstance(G, nx.Graph):
230
+ nodes = list(G.nodes())
231
+ G_m = nx.to_numpy_array(G, weight='weight', nonedge=0.0, dtype=dtype)
232
+ else:
233
+ nodes = list(range(len(G)))
234
+ G_m = G
235
+
236
+ return maxcut_tfim_pure_numba(G_m, nodes, quality, shots, is_spin_glass, anneal_t, anneal_h, repulsion_base)
@@ -1,5 +1,5 @@
1
1
  from .maxcut_tfim_util import binary_search, opencl_context, to_scipy_sparse_upper_triangular
2
- from .maxcut_tfim import maxcut_tfim
2
+ from .maxcut_tfim import maxcut_tfim_pure_numba
3
3
  from concurrent.futures import ProcessPoolExecutor
4
4
  import time
5
5
  import itertools
@@ -621,6 +621,47 @@ def tsp_symmetric_driver(G_m, is_cyclic, is_top_level, start_node, end_node, k_n
621
621
  return [nodes[x] for x in best_path], best_weight
622
622
 
623
623
 
624
+ @njit
625
+ def tsp_symmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repulsion_base, start_node, end_node, monte_carlo, is_cyclic, n_nodes, multi_start):
626
+ if is_cyclic:
627
+ start_node = None
628
+ end_node = None
629
+
630
+ if (start_node is None) and not (end_node is None):
631
+ start_node = end_node
632
+ end_node = None
633
+
634
+ a, b, c = [0], [0], [0]
635
+ a.clear()
636
+ b.clear()
637
+ c.clear()
638
+ if (start_node is None) and (end_node is None):
639
+ if monte_carlo:
640
+ a, b = monte_carlo_loop(n_nodes)
641
+ else:
642
+ best_cut = -float("inf")
643
+ for _ in range(multi_start):
644
+ bits = ([0], [0])
645
+ bits[0].clear()
646
+ bits[1].clear()
647
+ while (len(bits[0]) == 0) or (len(bits[1]) == 0):
648
+ _, cut_value, bits = maxcut_tfim_pure_numba(G_m, nodes, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
649
+ if cut_value > best_cut:
650
+ best_cut = cut_value
651
+ a, b = bits
652
+ else:
653
+ is_cyclic = False
654
+ a.append(nodes.index(start_node))
655
+ b = list(range(n_nodes))
656
+ b.remove(a[0])
657
+ if end_node is not None:
658
+ c.append(nodes.index(end_node))
659
+ b.remove(c[0])
660
+
661
+ G_a, G_b = init_G_a_b(G_m, a, b)
662
+
663
+ return a, b, c, G_a, G_b, is_cyclic
664
+
624
665
  def tsp_symmetric(
625
666
  G,
626
667
  start_node=None,
@@ -651,10 +692,6 @@ def tsp_symmetric(
651
692
  nodes = list(range(n_nodes))
652
693
  G_m = G
653
694
 
654
- if is_cyclic:
655
- start_node = None
656
- end_node = None
657
-
658
695
  if n_nodes < 7:
659
696
  if n_nodes > 3:
660
697
  if is_cyclic:
@@ -666,35 +703,7 @@ def tsp_symmetric(
666
703
 
667
704
  return tsp_symmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic)
668
705
 
669
- if (start_node is None) and not (end_node is None):
670
- start_node = end_node
671
- end_node = None
672
-
673
- a = []
674
- b = []
675
- c = []
676
- if (start_node is None) and (end_node is None):
677
- if monte_carlo:
678
- a, b = monte_carlo_loop(n_nodes)
679
- else:
680
- best_cut = -float("inf")
681
- for _ in range(multi_start):
682
- bits = ([], [])
683
- while (len(bits[0]) == 0) or (len(bits[1]) == 0):
684
- _, cut_value, bits = maxcut_tfim(G_m, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
685
- if cut_value > best_cut:
686
- best_cut = cut_value
687
- a, b = bits
688
- else:
689
- is_cyclic = False
690
- a.append(nodes.index(start_node))
691
- b = list(range(n_nodes))
692
- b.remove(a[0])
693
- if end_node is not None:
694
- c.append(nodes.index(end_node))
695
- b.remove(c[0])
696
-
697
- G_a, G_b = init_G_a_b(G_m, a, b)
706
+ a, b, c, G_a, G_b, is_cylic = tsp_symmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repulsion_base, start_node, end_node, monte_carlo, is_cyclic, n_nodes, multi_start)
698
707
 
699
708
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
700
709
  with ProcessPoolExecutor(max_workers=1) as executor:
@@ -827,6 +836,51 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
827
836
  return [nodes[x] for x in final_path], best_weight
828
837
 
829
838
 
839
+ @njit
840
+ def tsp_asymmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repulsion_base, start_node, end_node, monte_carlo, is_cyclic, n_nodes, multi_start):
841
+ if is_cyclic:
842
+ start_node = None
843
+ end_node = None
844
+
845
+ is_reversed = False
846
+ if (start_node is None) and not (end_node is None):
847
+ is_reversed = True
848
+ start_node = end_node
849
+ end_node = None
850
+ G_m = G_m.T
851
+
852
+ a, b, c = [0], [0], [0]
853
+ a.clear()
854
+ b.clear()
855
+ c.clear()
856
+ if (start_node is None) and (end_node is None):
857
+ if monte_carlo:
858
+ a, b = monte_carlo_loop(n_nodes)
859
+ else:
860
+ best_cut = -float("inf")
861
+ for _ in range(multi_start):
862
+ bits = ([0], [0])
863
+ bits[0].clear()
864
+ bits[1].clear()
865
+ while (len(bits[0]) == 0) or (len(bits[1]) == 0):
866
+ _, cut_value, bits = maxcut_tfim_pure_numba((G_m + G_m.T) / 2, nodes, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
867
+ if cut_value > best_cut:
868
+ best_cut = cut_value
869
+ a, b = bits
870
+ else:
871
+ is_cyclic = False
872
+ a.append(nodes.index(start_node))
873
+ b = list(range(n_nodes))
874
+ b.remove(a[0])
875
+ if end_node is not None:
876
+ c.append(nodes.index(end_node))
877
+ b.remove(c[0])
878
+
879
+ G_a, G_b = init_G_a_b(G_m, a, b)
880
+
881
+ return a, b, c, G_a, G_b, is_cyclic, is_reversed
882
+
883
+
830
884
  def tsp_asymmetric(
831
885
  G,
832
886
  start_node=None,
@@ -857,10 +911,6 @@ def tsp_asymmetric(
857
911
  nodes = list(range(n_nodes))
858
912
  G_m = G
859
913
 
860
- if is_cyclic:
861
- start_node = None
862
- end_node = None
863
-
864
914
  if n_nodes < 7:
865
915
  if n_nodes > 2:
866
916
  if is_cyclic:
@@ -872,39 +922,7 @@ def tsp_asymmetric(
872
922
 
873
923
  return tsp_asymmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic)
874
924
 
875
-
876
- is_reversed = False
877
- if (start_node is None) and not (end_node is None):
878
- is_reversed = True
879
- start_node = end_node
880
- end_node = None
881
- G_m = G_m.T
882
-
883
- a = []
884
- b = []
885
- c = []
886
- if (start_node is None) and (end_node is None):
887
- if monte_carlo:
888
- a, b = monte_carlo_loop(n_nodes)
889
- else:
890
- best_cut = -float("inf")
891
- for _ in range(multi_start):
892
- bits = ([], [])
893
- while (len(bits[0]) == 0) or (len(bits[1]) == 0):
894
- _, cut_value, bits = maxcut_tfim((G_m + G_m.T) / 2, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
895
- if cut_value > best_cut:
896
- best_cut = cut_value
897
- a, b = bits
898
- else:
899
- is_cyclic = False
900
- a.append(nodes.index(start_node))
901
- b = list(range(n_nodes))
902
- b.remove(a[0])
903
- if end_node is not None:
904
- c.append(nodes.index(end_node))
905
- b.remove(c[0])
906
-
907
- G_a, G_b = init_G_a_b(G_m, a, b)
925
+ a, b, c, G_a, G_b, is_cyclic, is_reversed = tsp_asymmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repulsion_base, start_node, end_node, monte_carlo, is_cyclic, n_nodes, multi_start)
908
926
 
909
927
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 2) and (len(b) > 2):
910
928
  with ProcessPoolExecutor(max_workers=1) as executor:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.10.0
3
+ Version: 8.10.1
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
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name='pyqrackising',
10
- version='8.10.0',
10
+ version='8.10.1',
11
11
  author='Dan Strano',
12
12
  author_email='stranoj@gmail.com',
13
13
  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