PyQrackIsing 8.10.0__tar.gz → 8.10.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 (28) hide show
  1. {pyqrackising-8.10.0/pyqrackising.egg-info → pyqrackising-8.10.2}/PKG-INFO +1 -1
  2. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyproject.toml +1 -1
  3. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/maxcut_tfim.py +35 -18
  4. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/tsp.py +93 -71
  5. {pyqrackising-8.10.0 → pyqrackising-8.10.2/pyqrackising.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/setup.py +1 -1
  7. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/LICENSE.md +0 -0
  8. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/MANIFEST.in +0 -0
  9. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/README.md +0 -0
  10. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/__init__.py +0 -0
  11. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  12. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/generate_tfim_samples.py +0 -0
  13. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/kernels.cl +0 -0
  14. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  15. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  16. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/maxcut_tfim_util.py +0 -0
  17. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/spin_glass_solver.py +0 -0
  18. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  19. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/spin_glass_solver_util.py +0 -0
  21. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/tfim_magnetization.py +0 -0
  22. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/tfim_square_magnetization.py +0 -0
  23. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-8.10.0 → pyqrackising-8.10.2}/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.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
@@ -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.2"
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,49 @@ 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
+ n_x = nodes[0]
627
+
628
+ if is_cyclic:
629
+ start_node = None
630
+ end_node = None
631
+
632
+ if (start_node is None) and not (end_node is None):
633
+ start_node = end_node
634
+ end_node = None
635
+
636
+ a, b, c = [n_x], [n_x], [n_x]
637
+ a.clear()
638
+ b.clear()
639
+ c.clear()
640
+ if (start_node is None) and (end_node is None):
641
+ if monte_carlo:
642
+ a, b = monte_carlo_loop(n_nodes)
643
+ else:
644
+ best_cut = -float("inf")
645
+ for _ in range(multi_start):
646
+ bits = ([n_x], [n_x])
647
+ bits[0].clear()
648
+ bits[1].clear()
649
+ while (len(bits[0]) == 0) or (len(bits[1]) == 0):
650
+ _, 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)
651
+ if cut_value > best_cut:
652
+ best_cut = cut_value
653
+ a, b = bits
654
+ else:
655
+ is_cyclic = False
656
+ a.append(nodes.index(start_node))
657
+ b = list(range(n_nodes))
658
+ b.remove(a[0])
659
+ if end_node is not None:
660
+ c.append(nodes.index(end_node))
661
+ b.remove(c[0])
662
+
663
+ G_a, G_b = init_G_a_b(G_m, a, b)
664
+
665
+ return a, b, c, G_a, G_b, is_cyclic
666
+
624
667
  def tsp_symmetric(
625
668
  G,
626
669
  start_node=None,
@@ -651,10 +694,6 @@ def tsp_symmetric(
651
694
  nodes = list(range(n_nodes))
652
695
  G_m = G
653
696
 
654
- if is_cyclic:
655
- start_node = None
656
- end_node = None
657
-
658
697
  if n_nodes < 7:
659
698
  if n_nodes > 3:
660
699
  if is_cyclic:
@@ -666,35 +705,7 @@ def tsp_symmetric(
666
705
 
667
706
  return tsp_symmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic)
668
707
 
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)
708
+ 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
709
 
699
710
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 3) and (len(b) > 3):
700
711
  with ProcessPoolExecutor(max_workers=1) as executor:
@@ -827,6 +838,53 @@ def tsp_asymmetric_driver(G_m, is_reversed, is_cyclic, is_top_level, start_node,
827
838
  return [nodes[x] for x in final_path], best_weight
828
839
 
829
840
 
841
+ @njit
842
+ 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):
843
+ n_x = nodes[0]
844
+
845
+ if is_cyclic:
846
+ start_node = None
847
+ end_node = None
848
+
849
+ is_reversed = False
850
+ if (start_node is None) and not (end_node is None):
851
+ is_reversed = True
852
+ start_node = end_node
853
+ end_node = None
854
+ G_m = G_m.T
855
+
856
+ a, b, c = [n_x], [n_x], [n_x]
857
+ a.clear()
858
+ b.clear()
859
+ c.clear()
860
+ if (start_node is None) and (end_node is None):
861
+ if monte_carlo:
862
+ a, b = monte_carlo_loop(n_nodes)
863
+ else:
864
+ best_cut = -float("inf")
865
+ for _ in range(multi_start):
866
+ bits = ([n_x], [n_x])
867
+ bits[0].clear()
868
+ bits[1].clear()
869
+ while (len(bits[0]) == 0) or (len(bits[1]) == 0):
870
+ _, 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)
871
+ if cut_value > best_cut:
872
+ best_cut = cut_value
873
+ a, b = bits
874
+ else:
875
+ is_cyclic = False
876
+ a.append(nodes.index(start_node))
877
+ b = list(range(n_nodes))
878
+ b.remove(a[0])
879
+ if end_node is not None:
880
+ c.append(nodes.index(end_node))
881
+ b.remove(c[0])
882
+
883
+ G_a, G_b = init_G_a_b(G_m, a, b)
884
+
885
+ return a, b, c, G_a, G_b, is_cyclic, is_reversed
886
+
887
+
830
888
  def tsp_asymmetric(
831
889
  G,
832
890
  start_node=None,
@@ -857,10 +915,6 @@ def tsp_asymmetric(
857
915
  nodes = list(range(n_nodes))
858
916
  G_m = G
859
917
 
860
- if is_cyclic:
861
- start_node = None
862
- end_node = None
863
-
864
918
  if n_nodes < 7:
865
919
  if n_nodes > 2:
866
920
  if is_cyclic:
@@ -872,39 +926,7 @@ def tsp_asymmetric(
872
926
 
873
927
  return tsp_asymmetric_brute_force_driver(G_m, n_nodes, nodes, is_cyclic)
874
928
 
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)
929
+ 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
930
 
909
931
  if monte_carlo and is_parallel and (parallel_level < max_parallel_level) and (len(a) > 2) and (len(b) > 2):
910
932
  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.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
@@ -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.2',
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