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.
- {pyqrackising-1.14.11/PyQrackIsing.egg-info → pyqrackising-1.14.12}/PKG-INFO +1 -1
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tsp_symmetric.py +37 -20
- {pyqrackising-1.14.11 → pyqrackising-1.14.12/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/pyproject.toml +1 -1
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/setup.py +1 -1
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/CMakeLists.txt +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/LICENSE.md +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/MANIFEST.in +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/maxcut_tfim.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/spin_glass_solver.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/README.md +0 -0
- {pyqrackising-1.14.11 → pyqrackising-1.14.12}/setup.cfg +0 -0
|
@@ -2,24 +2,29 @@ from .spin_glass_solver import spin_glass_solver
|
|
|
2
2
|
import networkx as nx
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.14.
|
|
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.
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|