PyQrackIsing 3.5.5__tar.gz → 4.0.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 (24) hide show
  1. {pyqrackising-3.5.5/pyqrackising.egg-info → pyqrackising-4.0.0}/PKG-INFO +1 -1
  2. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/README.md +2 -3
  3. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyproject.toml +1 -1
  4. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/spin_glass_solver.py +8 -7
  5. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/spin_glass_solver_sparse.py +8 -5
  6. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/tsp.py +8 -8
  7. {pyqrackising-3.5.5 → pyqrackising-4.0.0/pyqrackising.egg-info}/PKG-INFO +1 -1
  8. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/setup.py +1 -1
  9. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/CMakeLists.txt +0 -0
  10. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/LICENSE.md +0 -0
  11. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/MANIFEST.in +0 -0
  12. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
  14. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/generate_tfim_samples.py +0 -0
  15. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/kernels.cl +0 -0
  16. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/maxcut_tfim.py +0 -0
  17. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  18. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/tfim_magnetization.py +0 -0
  19. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising/tfim_square_magnetization.py +0 -0
  20. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
  21. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
  22. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising.egg-info/not-zip-safe +0 -0
  23. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/pyqrackising.egg-info/top_level.txt +0 -0
  24. {pyqrackising-3.5.5 → pyqrackising-4.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 3.5.5
3
+ Version: 4.0.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
@@ -73,10 +73,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
73
73
 
74
74
 
75
75
  G = generate_spin_glass_graph(n_nodes=64, seed=42)
76
- solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=3, correction_quality=2, best_guess=None)
76
+ solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=3, best_guess=None)
77
77
  # solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=8)[0])
78
78
  ```
79
- We also provide `spin_glass_solver_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is the same as `maxcut_tfim`. `correction_quality` controls an additional convex optimization procedure on top of `best_guess` and defaults to 4. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
79
+ We also provide `spin_glass_solver_sparse(G)`, for `scipy` CSR sparse arrays (or `networkx` graphs). The (integer) `quality` setting is the same as `maxcut_tfim`. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
80
80
 
81
81
  From the `spin_glass_solver()`, we provide a (recursive) Traveling Salesman Problem (TSP) solver:
82
82
  ```py
@@ -103,7 +103,6 @@ circuit, path_length = tsp_symmetric(
103
103
  end_node=None,
104
104
  monte_carlo=True,
105
105
  quality=2,
106
- correction_quality=2,
107
106
  is_cyclic=True,
108
107
  multi_start=1,
109
108
  k_neighbors=20
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
11
11
 
12
12
  [project]
13
13
  name = "pyqrackising"
14
- version = "3.5.5"
14
+ version = "4.0.0"
15
15
  requires-python = ">=3.8"
16
16
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
17
17
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -56,7 +56,7 @@ def int_to_bitstring(integer, length):
56
56
  return (bin(integer)[2:].zfill(length))[::-1]
57
57
 
58
58
 
59
- def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best_guess=None):
59
+ def spin_glass_solver(G, quality=None, shots=None, best_guess=None):
60
60
  nodes = None
61
61
  n_qubits = 0
62
62
  G_m = None
@@ -82,11 +82,6 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
82
82
 
83
83
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
84
84
 
85
- if correction_quality is None:
86
- # maxcut_tfim(G) scales roughly like n^4,
87
- # so its match order of overhead.
88
- correction_quality = 2
89
-
90
85
  bitstring = ""
91
86
  if isinstance(best_guess, str):
92
87
  bitstring = best_guess
@@ -100,9 +95,11 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
100
95
 
101
96
  min_energy = compute_energy(best_theta, G_m)
102
97
  improved = True
98
+ correction_quality = 1
103
99
  while improved:
104
100
  improved = False
105
- for k in range(1, max(1, correction_quality + 1)):
101
+ k = 1
102
+ while k <= correction_quality:
106
103
  if n_qubits < k:
107
104
  break
108
105
 
@@ -121,8 +118,12 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
121
118
  for i in indices:
122
119
  best_theta[i] = not best_theta[i]
123
120
  improved = True
121
+ if correction_quality < (k + 1):
122
+ correction_quality = k + 1
124
123
  break
125
124
 
125
+ k = k + 1
126
+
126
127
  bitstring = ""
127
128
  l, r = [], []
128
129
  for i in range(len(best_theta)):
@@ -61,7 +61,7 @@ def int_to_bitstring(integer, length):
61
61
  return (bin(integer)[2:].zfill(length))[::-1]
62
62
 
63
63
 
64
- def spin_glass_solver_sparse(G, quality=None, shots=None, correction_quality=None, best_guess=None):
64
+ def spin_glass_solver_sparse(G, quality=None, shots=None, best_guess=None):
65
65
  nodes = None
66
66
  n_qubits = 0
67
67
  G_m = None
@@ -87,9 +87,6 @@ def spin_glass_solver_sparse(G, quality=None, shots=None, correction_quality=Non
87
87
 
88
88
  return "01", weight, ([nodes[0]], [nodes[1]]), -weight
89
89
 
90
- if correction_quality is None:
91
- correction_quality = 2
92
-
93
90
  bitstring = ""
94
91
  if isinstance(best_guess, str):
95
92
  bitstring = best_guess
@@ -105,9 +102,11 @@ def spin_glass_solver_sparse(G, quality=None, shots=None, correction_quality=Non
105
102
 
106
103
  min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices)
107
104
  improved = True
105
+ correction_quality = 1
108
106
  while improved:
109
107
  improved = False
110
- for k in range(1, max(1, correction_quality + 1)):
108
+ k = 1
109
+ while k <= correction_quality:
111
110
  if n_qubits < k:
112
111
  break
113
112
 
@@ -126,8 +125,12 @@ def spin_glass_solver_sparse(G, quality=None, shots=None, correction_quality=Non
126
125
  for i in indices:
127
126
  best_theta[i] = not best_theta[i]
128
127
  improved = True
128
+ if correction_quality < (k + 1):
129
+ correction_quality = k + 1
129
130
  break
130
131
 
132
+ k = k + 1
133
+
131
134
  bitstring = ""
132
135
  l, r = [], []
133
136
  for i in range(len(best_theta)):
@@ -406,7 +406,7 @@ def tsp_bruteforce_acyclic(G_m, perms):
406
406
  return best_path, best_weight
407
407
 
408
408
 
409
- def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, correction_quality=2, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
409
+ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
410
410
  nodes = None
411
411
  n_nodes = 0
412
412
  G_m = None
@@ -480,7 +480,7 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, corr
480
480
  for _ in range(multi_start):
481
481
  bits = ([], [])
482
482
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
483
- _, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, correction_quality=correction_quality)
483
+ _, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots)
484
484
  if energy < best_energy:
485
485
  best_energy = energy
486
486
  a, b = bits
@@ -495,8 +495,8 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, corr
495
495
 
496
496
  G_a, G_b = init_G_a_b(G_m, a, b)
497
497
 
498
- sol_a = tsp_symmetric(G_a, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
499
- sol_b = tsp_symmetric(G_b, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
498
+ sol_a = tsp_symmetric(G_a, quality=quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
499
+ sol_b = tsp_symmetric(G_b, quality=quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
500
500
 
501
501
  path_a = [a[x] for x in sol_a[0]]
502
502
  path_b = [b[x] for x in sol_b[0]]
@@ -541,7 +541,7 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=2, shots=None, corr
541
541
  return [nodes[x] for x in best_path], best_weight
542
542
 
543
543
 
544
- def tsp_asymmetric(G, start_node=None, end_node=None, quality=2, shots=None, correction_quality=2, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
544
+ def tsp_asymmetric(G, start_node=None, end_node=None, quality=2, shots=None, monte_carlo=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
545
545
  nodes = None
546
546
  n_nodes = 0
547
547
  G_m = None
@@ -599,7 +599,7 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=2, shots=None, cor
599
599
  for _ in range(multi_start):
600
600
  bits = ([], [])
601
601
  while (len(bits[0]) == 0) or (len(bits[1]) == 0):
602
- _, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots, correction_quality=correction_quality)
602
+ _, _, bits, energy = spin_glass_solver((G_m + G_m.T) / 2, quality=quality, shots=shots)
603
603
  if energy < best_energy:
604
604
  best_energy = energy
605
605
  a, b = bits
@@ -614,8 +614,8 @@ def tsp_asymmetric(G, start_node=None, end_node=None, quality=2, shots=None, cor
614
614
 
615
615
  G_a, G_b = init_G_a_b(G_m, a, b)
616
616
 
617
- sol_a = tsp_asymmetric(G_a, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
618
- sol_b = tsp_asymmetric(G_b, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
617
+ sol_a = tsp_asymmetric(G_a, quality=quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
618
+ sol_b = tsp_asymmetric(G_b, quality=quality, monte_carlo=monte_carlo, is_cyclic=False, is_top_level=False, k_neighbors=0, multi_start=multi_start)
619
619
 
620
620
  path_a = [a[x] for x in sol_a[0]]
621
621
  path_b = [b[x] for x in sol_b[0]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 3.5.5
3
+ Version: 4.0.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='3.5.5',
54
+ version='4.0.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