PyQrackIsing 1.23.0__tar.gz → 1.24.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.
- {pyqrackising-1.23.0/PyQrackIsing.egg-info → pyqrackising-1.24.0}/PKG-INFO +1 -1
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/maxcut_tfim.py +24 -20
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/tsp_symmetric.py +22 -5
- {pyqrackising-1.23.0 → pyqrackising-1.24.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/README.md +2 -2
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/pyproject.toml +1 -1
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/setup.py +1 -1
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/CMakeLists.txt +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/LICENSE.md +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/MANIFEST.in +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/spin_glass_solver.py +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.23.0 → pyqrackising-1.24.0}/setup.cfg +0 -0
|
@@ -256,6 +256,24 @@ def evaluate_cut_edges(G_m, samples):
|
|
|
256
256
|
return best_solution, float(best_value)
|
|
257
257
|
|
|
258
258
|
|
|
259
|
+
@njit
|
|
260
|
+
def init_J_and_z(G_m):
|
|
261
|
+
n_qubits = len(G_m)
|
|
262
|
+
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
263
|
+
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
264
|
+
J_max = -float("inf")
|
|
265
|
+
for n in range(n_qubits):
|
|
266
|
+
degree = sum(G_m[n] != 0.0)
|
|
267
|
+
J = -G_m[n].sum() / degree
|
|
268
|
+
degrees[n] = degree
|
|
269
|
+
J_eff[n] = J
|
|
270
|
+
J_abs = abs(J)
|
|
271
|
+
if J_abs > J_max:
|
|
272
|
+
J_max = J_abs
|
|
273
|
+
J_eff /= J_max
|
|
274
|
+
|
|
275
|
+
return J_eff, degrees
|
|
276
|
+
|
|
259
277
|
@njit
|
|
260
278
|
def init_thresholds(n_qubits):
|
|
261
279
|
n_bias = n_qubits - 1
|
|
@@ -346,9 +364,6 @@ def maxcut_tfim(
|
|
|
346
364
|
|
|
347
365
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
348
366
|
|
|
349
|
-
# Warp size is 32:
|
|
350
|
-
group_size = n_qubits - 1
|
|
351
|
-
|
|
352
367
|
if quality is None:
|
|
353
368
|
quality = 3
|
|
354
369
|
|
|
@@ -358,21 +373,8 @@ def maxcut_tfim(
|
|
|
358
373
|
|
|
359
374
|
n_steps = 1 << quality
|
|
360
375
|
grid_size = n_steps * n_qubits
|
|
361
|
-
grid_dims = (n_steps, n_qubits)
|
|
362
|
-
|
|
363
|
-
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
364
|
-
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
365
|
-
J_max = -float("inf")
|
|
366
|
-
for n in range(n_qubits):
|
|
367
|
-
degree = sum(G_m[n] != 0.0)
|
|
368
|
-
J = -G_m[n].sum() / degree
|
|
369
|
-
degrees[n] = degree
|
|
370
|
-
J_eff[n] = J
|
|
371
|
-
J_abs = abs(J)
|
|
372
|
-
if J_abs > J_max:
|
|
373
|
-
J_max = J_abs
|
|
374
|
-
J_eff /= J_max
|
|
375
376
|
|
|
377
|
+
J_eff, degrees = init_J_and_z(G_m)
|
|
376
378
|
thresholds = init_thresholds(n_qubits)
|
|
377
379
|
|
|
378
380
|
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128:
|
|
@@ -381,11 +383,13 @@ def maxcut_tfim(
|
|
|
381
383
|
h_mult = 2.0 / tot_t
|
|
382
384
|
theta = init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees)
|
|
383
385
|
|
|
384
|
-
|
|
386
|
+
# Warp size is 32:
|
|
387
|
+
group_size = n_qubits - 1
|
|
388
|
+
grid_dims = (n_steps, n_qubits)
|
|
385
389
|
|
|
386
|
-
|
|
387
|
-
thresholds /= tot_prob
|
|
390
|
+
cuda_maxcut_hamming_cdf[grid_dims, group_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
388
391
|
|
|
392
|
+
thresholds /= thresholds.sum()
|
|
389
393
|
tot_prob = 0.0
|
|
390
394
|
for i in range(n_qubits - 1):
|
|
391
395
|
tot_prob += thresholds[i]
|
|
@@ -4,6 +4,12 @@ from numba import njit
|
|
|
4
4
|
import numpy as np
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
# By Gemini (Google Search AI)
|
|
9
|
+
def int_to_bitstring(integer, length):
|
|
10
|
+
return (bin(integer)[2:].zfill(length))[::-1]
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
# two_opt() and targeted_three_opt() written by Elara (OpenAI ChatGPT instance)
|
|
8
14
|
@njit
|
|
9
15
|
def path_length(path, G_m):
|
|
@@ -13,6 +19,7 @@ def path_length(path, G_m):
|
|
|
13
19
|
|
|
14
20
|
return tot_len
|
|
15
21
|
|
|
22
|
+
|
|
16
23
|
@njit
|
|
17
24
|
def two_opt(path, G):
|
|
18
25
|
improved = True
|
|
@@ -34,6 +41,7 @@ def two_opt(path, G):
|
|
|
34
41
|
path = best_path
|
|
35
42
|
return best_path, best_dist
|
|
36
43
|
|
|
44
|
+
|
|
37
45
|
@njit
|
|
38
46
|
def targeted_three_opt(path, W, k_neighbors=20):
|
|
39
47
|
"""
|
|
@@ -120,7 +128,8 @@ def targeted_three_opt(path, W, k_neighbors=20):
|
|
|
120
128
|
|
|
121
129
|
return best_path, best_dist
|
|
122
130
|
|
|
123
|
-
|
|
131
|
+
|
|
132
|
+
def tsp_symmetric(G, quality=1, shots=None, correction_quality=2, monte_carlo=False, is_2_opt=True, is_3_opt=True, k_neighbors=20, is_cyclic=True, multi_start=1):
|
|
124
133
|
nodes = None
|
|
125
134
|
n_nodes = 0
|
|
126
135
|
G_m = None
|
|
@@ -151,8 +160,16 @@ def tsp_symmetric(G, quality=1, shots=None, correction_quality=2, is_2_opt=True,
|
|
|
151
160
|
_a = []
|
|
152
161
|
_b = []
|
|
153
162
|
while (len(_a) == 0) or (len(_b) == 0):
|
|
154
|
-
bits =
|
|
155
|
-
|
|
163
|
+
bits = None
|
|
164
|
+
if monte_carlo:
|
|
165
|
+
bits = ([], [])
|
|
166
|
+
for i in range(n_nodes):
|
|
167
|
+
if np.random.random() < 0.5:
|
|
168
|
+
bits[0].append(i)
|
|
169
|
+
else:
|
|
170
|
+
bits[1].append(i)
|
|
171
|
+
else:
|
|
172
|
+
_, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, correction_quality=correction_quality)
|
|
156
173
|
_a = list(bits[0])
|
|
157
174
|
_b = list(bits[1])
|
|
158
175
|
if energy < best_energy:
|
|
@@ -174,8 +191,8 @@ def tsp_symmetric(G, quality=1, shots=None, correction_quality=2, is_2_opt=True,
|
|
|
174
191
|
continue
|
|
175
192
|
G_b[i, j] = G_m[b[i], b[j]]
|
|
176
193
|
|
|
177
|
-
sol_a = tsp_symmetric(G_a, quality=quality, correction_quality=correction_quality, is_cyclic=False, is_2_opt=False, is_3_opt=False, multi_start=multi_start)
|
|
178
|
-
sol_b = tsp_symmetric(G_b, quality=quality, correction_quality=correction_quality, is_cyclic=False, is_2_opt=False, is_3_opt=False, multi_start=multi_start)
|
|
194
|
+
sol_a = tsp_symmetric(G_a, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_2_opt=False, is_3_opt=False, multi_start=multi_start)
|
|
195
|
+
sol_b = tsp_symmetric(G_b, quality=quality, correction_quality=correction_quality, monte_carlo=monte_carlo, is_cyclic=False, is_2_opt=False, is_3_opt=False, multi_start=multi_start)
|
|
179
196
|
|
|
180
197
|
path_a = [a[x] for x in sol_a[0]]
|
|
181
198
|
path_b = [b[x] for x in sol_b[0]]
|
|
@@ -93,13 +93,13 @@ def generate_tsp_graph(n_nodes=64, seed=None):
|
|
|
93
93
|
|
|
94
94
|
n_nodes = 128
|
|
95
95
|
G = generate_tsp_graph(n_nodes=n_nodes, seed=42)
|
|
96
|
-
circuit, path_length = tsp_symmetric(G, quality=1, correction_quality=2, is_cyclic=True, multi_start=1, is_3_opt=True, k_neighbors=20)
|
|
96
|
+
circuit, path_length = tsp_symmetric(G, is_monte_carlo=False, quality=1, correction_quality=2, is_cyclic=True, multi_start=1, is_2_opt=True, is_3_opt=True, k_neighbors=20)
|
|
97
97
|
|
|
98
98
|
print(f"Node count: {n_nodes}")
|
|
99
99
|
print(f"Path: {circuit}")
|
|
100
100
|
print(f"Path length: {path_length}")
|
|
101
101
|
```
|
|
102
|
-
We only provide a solver for the symmetric version of the TSP (i.e., the distance from "A" to "B" is considered the same as from "B" to "A"). `multi_start` controls how many stochastic repeats of MAXCUT are tried to select the best result, at every level of recursion.
|
|
102
|
+
We only provide a solver for the symmetric version of the TSP (i.e., the distance from "A" to "B" is considered the same as from "B" to "A"). `is_monte_carlo=True` switches out the MAXCUT-based heuristic for pure Monte Carlo recursive bipartitioning. `multi_start` controls how many stochastic repeats of MAXCUT are tried to select the best result, at every level of recursion.
|
|
103
103
|
|
|
104
104
|
## About
|
|
105
105
|
Transverse field Ising model (TFIM) is the basis of most claimed algorithmic "quantum advantage," circa 2025, with the notable exception of Shor's integer factoring algorithm.
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.
|
|
15
|
+
version = "1.24.0"
|
|
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.
|
|
54
|
+
version='1.24.0',
|
|
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
|