PyQrackIsing 1.6.2__tar.gz → 1.8.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.6.2/PyQrackIsing.egg-info → pyqrackising-1.8.0}/PKG-INFO +1 -1
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/maxcut_tfim.py +1 -1
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/spin_glass_solver.py +30 -36
- {pyqrackising-1.6.2 → pyqrackising-1.8.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/README.md +3 -2
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/pyproject.toml +1 -1
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/setup.py +1 -1
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/CMakeLists.txt +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/LICENSE.md +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/MANIFEST.in +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.6.2 → pyqrackising-1.8.0}/setup.cfg +0 -0
|
@@ -86,7 +86,7 @@ def maxcut_tfim(
|
|
|
86
86
|
# Number of measurement shots
|
|
87
87
|
shots = n_qubits << quality
|
|
88
88
|
|
|
89
|
-
J_eff = np.array([sum(
|
|
89
|
+
J_eff = np.array([-sum(edge_attributes.get('weight', 1.0) for _, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
|
|
90
90
|
degrees = np.array([sum(abs(edge_attributes.get('weight', 1.0)) for _, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
|
|
91
91
|
thresholds = tfim_sampler._maxcut_hamming_cdf(J_eff, degrees, quality)
|
|
92
92
|
G_dict = nx.to_dict_of_lists(G)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from .maxcut_tfim import maxcut_tfim
|
|
2
|
+
import itertools
|
|
2
3
|
import multiprocessing
|
|
3
4
|
import os
|
|
4
5
|
|
|
@@ -17,10 +18,11 @@ def evaluate_cut_edges(state, G):
|
|
|
17
18
|
def compute_energy(theta_bits, G):
|
|
18
19
|
# Reconstruct Ising energy (note: MAXCUT flips sign!)
|
|
19
20
|
spins = {i: 1 if theta_bits[i] else -1 for i in range(len(theta_bits))}
|
|
20
|
-
energy =
|
|
21
|
+
energy = sum(G[u][v].get("weight", 1) * spins[u] * spins[v] for u, v in G.edges())
|
|
21
22
|
|
|
22
23
|
return energy
|
|
23
24
|
|
|
25
|
+
|
|
24
26
|
# Parallelization by Elara (OpenAI custom GPT):
|
|
25
27
|
def bootstrap_worker(args):
|
|
26
28
|
theta, G, indices = args
|
|
@@ -33,24 +35,39 @@ def bootstrap_worker(args):
|
|
|
33
35
|
|
|
34
36
|
return indices, energy, flipped
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
# By Gemini (Google Search AI)
|
|
40
|
+
def int_to_bitstring(integer, length):
|
|
41
|
+
return (bin(integer)[2:].zfill(length))[::-1]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def spin_glass_solver(G, quality=2, best_guess=None):
|
|
45
|
+
bitstring = ''
|
|
46
|
+
if isinstance(best_guess, str):
|
|
47
|
+
bitstring = best_guess
|
|
48
|
+
elif isinstance(best_guess, int):
|
|
49
|
+
bitstring = int_to_bitstring(best_guess)
|
|
50
|
+
elif isinstance(best_guess, list):
|
|
51
|
+
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
52
|
+
else:
|
|
53
|
+
cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=0)
|
|
38
54
|
best_theta = [ b == '1' for b in list(bitstring)]
|
|
39
|
-
min_energy = compute_energy(best_theta, G)
|
|
40
55
|
n_qubits = len(best_theta)
|
|
41
|
-
|
|
56
|
+
min_energy = compute_energy(best_theta, G)
|
|
42
57
|
improved = True
|
|
43
58
|
while improved:
|
|
44
59
|
improved = False
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
for k in range(1, quality + 1):
|
|
61
|
+
if n_qubits < k:
|
|
62
|
+
break
|
|
63
|
+
|
|
48
64
|
theta = best_theta.copy()
|
|
65
|
+
args = []
|
|
66
|
+
|
|
67
|
+
for combo in itertools.combinations(range(n_qubits), k):
|
|
68
|
+
args.append((theta, G, combo))
|
|
49
69
|
|
|
50
70
|
with multiprocessing.Pool(processes=os.cpu_count()) as pool:
|
|
51
|
-
args = []
|
|
52
|
-
for i in range(n_qubits):
|
|
53
|
-
args.append((theta, G, (i,)))
|
|
54
71
|
results = pool.map(bootstrap_worker, args)
|
|
55
72
|
|
|
56
73
|
results.sort(key=lambda r: r[1])
|
|
@@ -59,31 +76,8 @@ def spin_glass_solver(G, quality=0):
|
|
|
59
76
|
min_energy = energy
|
|
60
77
|
for i in range(len(indices)):
|
|
61
78
|
best_theta[indices[i]] = flipped[i]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
iter_count += 1
|
|
65
|
-
|
|
66
|
-
if n_qubits < 2:
|
|
67
|
-
break
|
|
68
|
-
|
|
69
|
-
theta = best_theta.copy()
|
|
70
|
-
|
|
71
|
-
with multiprocessing.Pool(processes=os.cpu_count()) as pool:
|
|
72
|
-
args = []
|
|
73
|
-
for i in range(n_qubits):
|
|
74
|
-
for j in range(i + 1, n_qubits):
|
|
75
|
-
args.append((theta, G, (i, j)))
|
|
76
|
-
results = pool.map(bootstrap_worker, args)
|
|
77
|
-
|
|
78
|
-
results.sort(key=lambda r: r[1])
|
|
79
|
-
indices, energy, flipped = results[0]
|
|
80
|
-
if energy < min_energy:
|
|
81
|
-
min_energy = energy
|
|
82
|
-
for i in range(len(indices)):
|
|
83
|
-
best_theta[indices[i]] = flipped[i]
|
|
84
|
-
improved = True
|
|
85
|
-
|
|
86
|
-
iter_count += 1
|
|
79
|
+
improved = True
|
|
80
|
+
break
|
|
87
81
|
|
|
88
82
|
sample = 0
|
|
89
83
|
bitstring = ""
|
|
@@ -68,9 +68,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
|
|
|
68
68
|
return G
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
G = generate_spin_glass_graph(n_nodes=64, seed=42)
|
|
72
|
-
cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G, quality=
|
|
71
|
+
G = generate_spin_glass_graph(n_nodes=64, seed=42, best_guess=None)
|
|
72
|
+
cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G, quality=2)
|
|
73
73
|
```
|
|
74
|
+
The `quality` setting default is `2`, and overhead grows roughly like the qubit count to the power of `quality` (so `O(n ** 2)` for default). `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). 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.
|
|
74
75
|
|
|
75
76
|
## About
|
|
76
77
|
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.
|
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "PyQrackIsing"
|
|
13
|
-
version = "1.
|
|
13
|
+
version = "1.8.0"
|
|
14
14
|
requires-python = ">=3.8"
|
|
15
15
|
description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
|
|
16
16
|
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.8.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
|