PyQrackIsing 1.14.11__tar.gz → 1.14.12__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 (21) hide show
  1. {pyqrackising-1.14.11/PyQrackIsing.egg-info → pyqrackising-1.14.12}/PKG-INFO +1 -1
  2. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tsp_symmetric.py +37 -20
  3. {pyqrackising-1.14.11 → pyqrackising-1.14.12/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  4. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/pyproject.toml +1 -1
  5. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/setup.py +1 -1
  6. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/CMakeLists.txt +0 -0
  7. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/LICENSE.md +0 -0
  8. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/MANIFEST.in +0 -0
  9. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/__init__.py +0 -0
  10. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  11. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/generate_tfim_samples.py +0 -0
  12. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/maxcut_tfim.py +0 -0
  13. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/spin_glass_solver.py +0 -0
  14. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tfim_magnetization.py +0 -0
  15. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  16. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/README.md +0 -0
  21. {pyqrackising-1.14.11 → pyqrackising-1.14.12}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.14.11
3
+ Version: 1.14.12
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -2,24 +2,29 @@ from .spin_glass_solver import spin_glass_solver
2
2
  import networkx as nx
3
3
 
4
4
 
5
- def get_best_stitch(adjacency, terminals_a, terminals_b, is_cyclic):
6
- best_weight = float("inf")
7
- best_edge = None
8
- for a in range(2):
9
- a_term = terminals_a[a]
10
- for b in range(2):
11
- b_term = terminals_b[b]
12
- weight = adjacency[a_term][b_term]["weight"]
13
- if is_cyclic:
14
- n_a_term = terminals_a[0 if a else 1]
15
- n_b_term = terminals_b[0 if b else 1]
16
- weight += adjacency[n_a_term][n_b_term]["weight"]
17
- if weight < best_weight:
18
- best_weight = weight
19
- best_edge = (a, b)
20
-
21
- return best_weight, best_edge
22
-
5
+ # two_opt() written by Elara (OpenAI ChatGPT instance)
6
+ def two_opt(path, G):
7
+ improved = True
8
+ best_path = path
9
+ best_dist = path_length(best_path, G)
10
+
11
+ while improved:
12
+ improved = False
13
+ for i in range(1, len(path) - 2):
14
+ for j in range(i+1, len(path) - 1):
15
+ if j - i == 1: # adjacent edges, skip
16
+ continue
17
+ new_path = best_path[:]
18
+ new_path[i:j] = best_path[j-1:i-1:-1] # reverse segment
19
+ new_dist = path_length(new_path, G)
20
+ if new_dist < best_dist:
21
+ best_path, best_dist = new_path, new_dist
22
+ improved = True
23
+ path = best_path
24
+ return best_path, best_dist
25
+
26
+ def path_length(path, G):
27
+ return sum(G[path[i]][path[i+1]].get("weight", 1.0) for i in range(len(path)-1))
23
28
 
24
29
  def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_cyclic=True, start_node=None):
25
30
  nodes = list(G.nodes())
@@ -98,7 +103,13 @@ def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_cyclic=True
98
103
  best_weight = weight
99
104
  best_path = bulk.copy().insert(singlet, i + 1)
100
105
 
101
- return (best_path, sol_weight + best_weight)
106
+ best_path, best_weight = two_opt(best_path, G)
107
+
108
+ if is_cyclic:
109
+ best_weight += G[best_path[-1]][best_path[0]].get("weight", 1.0)
110
+ best_path += [best_path[0]]
111
+
112
+ return best_path, best_weight
102
113
 
103
114
  terminals_a = [path_a[0], path_a[-1]]
104
115
  terminals_b = [path_b[0], path_b[-1]]
@@ -126,4 +137,10 @@ def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_cyclic=True
126
137
  path_a, path_b = path_b, path_a
127
138
  terminals_a, terminals_b = terminals_b, terminals_a
128
139
 
129
- return (best_path, sol_weight + best_weight)
140
+ best_path, best_weight = two_opt(best_path, G)
141
+
142
+ if is_cyclic:
143
+ best_weight += G[best_path[-1]][best_path[0]].get("weight", 1.0)
144
+ best_path += [best_path[0]]
145
+
146
+ return best_path, best_weight
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.14.11
3
+ Version: 1.14.12
4
4
  Summary: Near-ideal closed-form solutions for 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 = "1.14.11"
15
+ version = "1.14.12"
16
16
  requires-python = ">=3.8"
17
17
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
18
18
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='PyQrackIsing',
54
- version='1.14.11',
54
+ version='1.14.12',
55
55
  author='Dan Strano',
56
56
  author_email='stranoj@gmail.com',
57
57
  description='Near-ideal closed-form solutions for transverse field Ising model (TFIM)',
File without changes
File without changes