PyQrackIsing 4.0.1__tar.gz → 4.1.1__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-4.0.1/pyqrackising.egg-info → pyqrackising-4.1.1}/PKG-INFO +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyproject.toml +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/maxcut_tfim.py +22 -19
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/maxcut_tfim_sparse.py +23 -20
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/spin_glass_solver.py +10 -9
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/spin_glass_solver_sparse.py +10 -11
- {pyqrackising-4.0.1 → pyqrackising-4.1.1/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/setup.py +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/CMakeLists.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/LICENSE.md +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/MANIFEST.in +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/README.md +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/__init__.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising/tsp.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.1}/setup.cfg +0 -0
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "pyqrackising"
|
|
14
|
-
version = "4.
|
|
14
|
+
version = "4.1.1"
|
|
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"}
|
|
@@ -108,10 +108,8 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
|
108
108
|
|
|
109
109
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
110
110
|
@njit
|
|
111
|
-
def local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m):
|
|
111
|
+
def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m):
|
|
112
112
|
"""
|
|
113
|
-
|
|
114
|
-
|
|
115
113
|
Pick m nodes out of n with repulsion bias:
|
|
116
114
|
- High-degree nodes are already less likely
|
|
117
115
|
- After choosing a node, its neighbors' probabilities are further reduced
|
|
@@ -158,7 +156,7 @@ def local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m):
|
|
|
158
156
|
for j in range(adjacency_rows[node], adjacency_rows[node + 1]):
|
|
159
157
|
nbr = adjacency_data[j]
|
|
160
158
|
if available[nbr]:
|
|
161
|
-
weights[nbr] *=
|
|
159
|
+
weights[nbr] *= adjacency_vals[j] # tunable penalty factor
|
|
162
160
|
|
|
163
161
|
return mask
|
|
164
162
|
|
|
@@ -176,26 +174,30 @@ def compute_energy(sample, G_m, n_qubits):
|
|
|
176
174
|
@njit(parallel=True)
|
|
177
175
|
def compute_adjacency(G_m, size):
|
|
178
176
|
n_qubits = G_m.shape[0]
|
|
177
|
+
nrm = G_m.max()
|
|
179
178
|
adjacency_rows = np.empty(n_qubits + 1, dtype=np.int32)
|
|
180
179
|
adjacency_rows[0] = 0
|
|
181
|
-
adjacency_data = np.
|
|
180
|
+
adjacency_data = np.empty(size, dtype=np.int32)
|
|
181
|
+
adjacency_vals = np.empty(size, dtype=np.float64)
|
|
182
182
|
k = 0
|
|
183
183
|
for i in prange(n_qubits):
|
|
184
184
|
for j in range(n_qubits):
|
|
185
|
-
if
|
|
185
|
+
if i == j:
|
|
186
186
|
continue
|
|
187
187
|
adjacency_data[k] = j
|
|
188
|
+
adjacency_vals[k] = 0.5 ** (G_m[i, j] / nrm)
|
|
188
189
|
k += 1
|
|
189
190
|
adjacency_rows[i + 1] = k
|
|
190
191
|
|
|
191
192
|
np.resize(adjacency_data, k)
|
|
193
|
+
np.resize(adjacency_vals, k)
|
|
192
194
|
|
|
193
|
-
return adjacency_data, adjacency_rows
|
|
195
|
+
return adjacency_data, adjacency_vals, adjacency_rows
|
|
194
196
|
|
|
195
197
|
|
|
196
198
|
@njit(parallel=True)
|
|
197
199
|
def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
198
|
-
adjacency_data, adjacency_rows = compute_adjacency(G_m, degrees_sum)
|
|
200
|
+
adjacency_data, adjacency_vals, adjacency_rows = compute_adjacency(G_m, degrees_sum)
|
|
199
201
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
200
202
|
|
|
201
203
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -210,7 +212,7 @@ def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
|
210
212
|
m += 1
|
|
211
213
|
|
|
212
214
|
# Second dimension: permutation within Hamming weight
|
|
213
|
-
sample = local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m)
|
|
215
|
+
sample = local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m)
|
|
214
216
|
|
|
215
217
|
solutions[s] = sample
|
|
216
218
|
energies[s] = compute_energy(sample, G_m, n)
|
|
@@ -302,21 +304,22 @@ def maxcut_tfim(
|
|
|
302
304
|
nodes = list(range(n_qubits))
|
|
303
305
|
G_m = G
|
|
304
306
|
|
|
305
|
-
if n_qubits
|
|
306
|
-
|
|
307
|
+
if n_qubits < 3:
|
|
308
|
+
if n_qubits == 0:
|
|
309
|
+
return "", 0, ([], [])
|
|
307
310
|
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
if n_qubits == 1:
|
|
312
|
+
return "0", 0, (nodes, [])
|
|
310
313
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
314
|
+
if n_qubits == 2:
|
|
315
|
+
weight = G_m[0, 1]
|
|
316
|
+
if weight < 0.0:
|
|
317
|
+
return "00", 0, (nodes, [])
|
|
315
318
|
|
|
316
|
-
|
|
319
|
+
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
317
320
|
|
|
318
321
|
if quality is None:
|
|
319
|
-
quality =
|
|
322
|
+
quality = 6
|
|
320
323
|
|
|
321
324
|
if shots is None:
|
|
322
325
|
# Number of measurement shots
|
|
@@ -108,9 +108,8 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
|
108
108
|
|
|
109
109
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
110
110
|
@njit
|
|
111
|
-
def local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m):
|
|
111
|
+
def local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m):
|
|
112
112
|
"""
|
|
113
|
-
|
|
114
113
|
Pick m nodes out of n with repulsion bias:
|
|
115
114
|
- High-degree nodes are already less likely
|
|
116
115
|
- After choosing a node, its neighbors' probabilities are further reduced
|
|
@@ -157,7 +156,7 @@ def local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m):
|
|
|
157
156
|
for j in range(adjacency_rows[node], adjacency_rows[node + 1]):
|
|
158
157
|
nbr = adjacency_data[j]
|
|
159
158
|
if available[nbr]:
|
|
160
|
-
weights[nbr] *=
|
|
159
|
+
weights[nbr] *= adjacency_vals[j] # tunable penalty factor
|
|
161
160
|
|
|
162
161
|
return mask
|
|
163
162
|
|
|
@@ -179,26 +178,29 @@ def compute_energy(sample, G_data, G_rows, G_cols):
|
|
|
179
178
|
@njit(parallel=True)
|
|
180
179
|
def compute_adjacency(G_data, G_rows, G_cols):
|
|
181
180
|
n_qubits = G_rows.shape[0] - 1
|
|
181
|
+
nrm = G_data.max()
|
|
182
182
|
adjacency_rows = np.empty(n_qubits + 1, dtype=np.int32)
|
|
183
183
|
adjacency_rows[0] = 0
|
|
184
|
-
adjacency_data = np.
|
|
184
|
+
adjacency_data = np.empty(G_data.shape[0], dtype=np.int32)
|
|
185
|
+
adjacency_vals = np.empty(G_data.shape[0], dtype=np.float64)
|
|
185
186
|
k = 0
|
|
186
187
|
for i in prange(n_qubits):
|
|
187
188
|
for j in range(G_rows[i], G_rows[i + 1]):
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
adjacency_data[k] = G_cols[j]
|
|
190
|
+
adjacency_vals[k] = 0.5 ** (G_data[j] / nrm)
|
|
191
|
+
k += 1
|
|
191
192
|
adjacency_rows[i + 1] = k
|
|
192
193
|
|
|
193
194
|
np.resize(adjacency_data, k)
|
|
195
|
+
np.resize(adjacency_vals, k)
|
|
194
196
|
|
|
195
|
-
return adjacency_data, adjacency_rows
|
|
197
|
+
return adjacency_data, adjacency_vals, adjacency_rows
|
|
196
198
|
|
|
197
199
|
|
|
198
200
|
@njit(parallel=True)
|
|
199
201
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
200
202
|
n = G_rows.shape[0] - 1
|
|
201
|
-
adjacency_data, adjacency_rows = compute_adjacency(G_data, G_rows, G_cols)
|
|
203
|
+
adjacency_data, adjacency_vals, adjacency_rows = compute_adjacency(G_data, G_rows, G_cols)
|
|
202
204
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
203
205
|
|
|
204
206
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -213,7 +215,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
|
213
215
|
m += 1
|
|
214
216
|
|
|
215
217
|
# Second dimension: permutation within Hamming weight
|
|
216
|
-
sample = local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m)
|
|
218
|
+
sample = local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m)
|
|
217
219
|
solutions[s] = sample
|
|
218
220
|
energies[s] = compute_energy(sample, G_data, G_rows, G_cols)
|
|
219
221
|
|
|
@@ -308,21 +310,22 @@ def maxcut_tfim_sparse(
|
|
|
308
310
|
nodes = list(range(n_qubits))
|
|
309
311
|
G_m = G
|
|
310
312
|
|
|
311
|
-
if n_qubits
|
|
312
|
-
|
|
313
|
+
if n_qubits < 3:
|
|
314
|
+
if n_qubits == 0:
|
|
315
|
+
return "", 0, ([], [])
|
|
313
316
|
|
|
314
|
-
|
|
315
|
-
|
|
317
|
+
if n_qubits == 1:
|
|
318
|
+
return "0", 0, (nodes, [])
|
|
316
319
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
320
|
+
if n_qubits == 2:
|
|
321
|
+
weight = G_m[0, 1]
|
|
322
|
+
if weight < 0.0:
|
|
323
|
+
return "00", 0, (nodes, [])
|
|
321
324
|
|
|
322
|
-
|
|
325
|
+
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
323
326
|
|
|
324
327
|
if quality is None:
|
|
325
|
-
quality =
|
|
328
|
+
quality = 6
|
|
326
329
|
|
|
327
330
|
if shots is None:
|
|
328
331
|
# Number of measurement shots
|
|
@@ -69,18 +69,19 @@ def spin_glass_solver(G, quality=None, shots=None, best_guess=None):
|
|
|
69
69
|
nodes = list(range(n_qubits))
|
|
70
70
|
G_m = G
|
|
71
71
|
|
|
72
|
-
if n_qubits
|
|
73
|
-
|
|
72
|
+
if n_qubits < 3:
|
|
73
|
+
if n_qubits == 0:
|
|
74
|
+
return "", 0, ([], []), 0
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
if n_qubits == 1:
|
|
77
|
+
return "0", 0, (nodes, []), 0
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if n_qubits == 2:
|
|
80
|
+
weight = G_m[0, 1]
|
|
81
|
+
if weight < 0.0:
|
|
82
|
+
return "00", 0, (nodes, []), weight
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
return "01", weight, ([nodes[0]], [nodes[1]]), -weight
|
|
84
85
|
|
|
85
86
|
bitstring = ""
|
|
86
87
|
if isinstance(best_guess, str):
|
|
@@ -74,18 +74,19 @@ def spin_glass_solver_sparse(G, quality=None, shots=None, best_guess=None):
|
|
|
74
74
|
nodes = list(range(n_qubits))
|
|
75
75
|
G_m = G
|
|
76
76
|
|
|
77
|
-
if n_qubits
|
|
78
|
-
|
|
77
|
+
if n_qubits < 3:
|
|
78
|
+
if n_qubits == 0:
|
|
79
|
+
return "", 0, ([], []), 0
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if n_qubits == 1:
|
|
82
|
+
return "0", 0, (nodes, []), 0
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
if n_qubits == 2:
|
|
85
|
+
weight = G_m[0, 1]
|
|
86
|
+
if weight < 0.0:
|
|
87
|
+
return "00", 0, (nodes, []), weight
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
return "01", weight, ([nodes[0]], [nodes[1]]), -weight
|
|
89
90
|
|
|
90
91
|
bitstring = ""
|
|
91
92
|
if isinstance(best_guess, str):
|
|
@@ -98,8 +99,6 @@ def spin_glass_solver_sparse(G, quality=None, shots=None, best_guess=None):
|
|
|
98
99
|
bitstring, _, _ = maxcut_tfim_sparse(G_m, quality=quality, shots=shots)
|
|
99
100
|
best_theta = [b == "1" for b in list(bitstring)]
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
102
|
min_energy = compute_energy(best_theta, G_m.data, G_m.indptr, G_m.indices)
|
|
104
103
|
improved = True
|
|
105
104
|
correction_quality = 1
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='4.
|
|
54
|
+
version='4.1.1',
|
|
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
|
|
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
|