PyQrackIsing 4.0.1__tar.gz → 4.1.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-4.0.1/pyqrackising.egg-info → pyqrackising-4.1.0}/PKG-INFO +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyproject.toml +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/maxcut_tfim.py +25 -19
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/maxcut_tfim_sparse.py +21 -17
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/spin_glass_solver.py +10 -9
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/spin_glass_solver_sparse.py +10 -11
- {pyqrackising-4.0.1 → pyqrackising-4.1.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/setup.py +1 -1
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/CMakeLists.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/LICENSE.md +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/MANIFEST.in +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/README.md +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-4.0.1 → pyqrackising-4.1.0}/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.0
|
|
14
|
+
version = "4.1.0"
|
|
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,33 @@ 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
|
+
continue
|
|
187
|
+
val = G_m[i, j]
|
|
188
|
+
if val <= 0.0:
|
|
186
189
|
continue
|
|
187
190
|
adjacency_data[k] = j
|
|
191
|
+
adjacency_vals[k] = 0.5 ** (val / nrm)
|
|
188
192
|
k += 1
|
|
189
193
|
adjacency_rows[i + 1] = k
|
|
190
194
|
|
|
191
195
|
np.resize(adjacency_data, k)
|
|
196
|
+
np.resize(adjacency_vals, k)
|
|
192
197
|
|
|
193
|
-
return adjacency_data, adjacency_rows
|
|
198
|
+
return adjacency_data, adjacency_vals, adjacency_rows
|
|
194
199
|
|
|
195
200
|
|
|
196
201
|
@njit(parallel=True)
|
|
197
202
|
def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
198
|
-
adjacency_data, adjacency_rows = compute_adjacency(G_m, degrees_sum)
|
|
203
|
+
adjacency_data, adjacency_vals, adjacency_rows = compute_adjacency(G_m, degrees_sum)
|
|
199
204
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
200
205
|
|
|
201
206
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -210,7 +215,7 @@ def sample_for_solution(G_m, shots, thresholds, degrees_sum, J_eff, n):
|
|
|
210
215
|
m += 1
|
|
211
216
|
|
|
212
217
|
# Second dimension: permutation within Hamming weight
|
|
213
|
-
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)
|
|
214
219
|
|
|
215
220
|
solutions[s] = sample
|
|
216
221
|
energies[s] = compute_energy(sample, G_m, n)
|
|
@@ -302,21 +307,22 @@ def maxcut_tfim(
|
|
|
302
307
|
nodes = list(range(n_qubits))
|
|
303
308
|
G_m = G
|
|
304
309
|
|
|
305
|
-
if n_qubits
|
|
306
|
-
|
|
310
|
+
if n_qubits < 3:
|
|
311
|
+
if n_qubits == 0:
|
|
312
|
+
return "", 0, ([], [])
|
|
307
313
|
|
|
308
|
-
|
|
309
|
-
|
|
314
|
+
if n_qubits == 1:
|
|
315
|
+
return "0", 0, (nodes, [])
|
|
310
316
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
if n_qubits == 2:
|
|
318
|
+
weight = G_m[0, 1]
|
|
319
|
+
if weight < 0.0:
|
|
320
|
+
return "00", 0, (nodes, [])
|
|
315
321
|
|
|
316
|
-
|
|
322
|
+
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
317
323
|
|
|
318
324
|
if quality is None:
|
|
319
|
-
quality =
|
|
325
|
+
quality = 6
|
|
320
326
|
|
|
321
327
|
if shots is None:
|
|
322
328
|
# 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,30 @@ 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
|
if G_data[j] > 0.0:
|
|
189
190
|
adjacency_data[k] = G_cols[j]
|
|
191
|
+
adjacency_vals[k] = 0.5 ** (G_data[j] / nrm)
|
|
190
192
|
k += 1
|
|
191
193
|
adjacency_rows[i + 1] = k
|
|
192
194
|
|
|
193
195
|
np.resize(adjacency_data, k)
|
|
196
|
+
np.resize(adjacency_vals, k)
|
|
194
197
|
|
|
195
|
-
return adjacency_data, adjacency_rows
|
|
198
|
+
return adjacency_data, adjacency_vals, adjacency_rows
|
|
196
199
|
|
|
197
200
|
|
|
198
201
|
@njit(parallel=True)
|
|
199
202
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
200
203
|
n = G_rows.shape[0] - 1
|
|
201
|
-
adjacency_data, adjacency_rows = compute_adjacency(G_data, G_rows, G_cols)
|
|
204
|
+
adjacency_data, adjacency_vals, adjacency_rows = compute_adjacency(G_data, G_rows, G_cols)
|
|
202
205
|
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
203
206
|
|
|
204
207
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
@@ -213,7 +216,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, J_eff):
|
|
|
213
216
|
m += 1
|
|
214
217
|
|
|
215
218
|
# Second dimension: permutation within Hamming weight
|
|
216
|
-
sample = local_repulsion_choice(adjacency_data, adjacency_rows, weights, n, m)
|
|
219
|
+
sample = local_repulsion_choice(adjacency_data, adjacency_vals, adjacency_rows, weights, n, m)
|
|
217
220
|
solutions[s] = sample
|
|
218
221
|
energies[s] = compute_energy(sample, G_data, G_rows, G_cols)
|
|
219
222
|
|
|
@@ -308,21 +311,22 @@ def maxcut_tfim_sparse(
|
|
|
308
311
|
nodes = list(range(n_qubits))
|
|
309
312
|
G_m = G
|
|
310
313
|
|
|
311
|
-
if n_qubits
|
|
312
|
-
|
|
314
|
+
if n_qubits < 3:
|
|
315
|
+
if n_qubits == 0:
|
|
316
|
+
return "", 0, ([], [])
|
|
313
317
|
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
if n_qubits == 1:
|
|
319
|
+
return "0", 0, (nodes, [])
|
|
316
320
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
+
if n_qubits == 2:
|
|
322
|
+
weight = G_m[0, 1]
|
|
323
|
+
if weight < 0.0:
|
|
324
|
+
return "00", 0, (nodes, [])
|
|
321
325
|
|
|
322
|
-
|
|
326
|
+
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
323
327
|
|
|
324
328
|
if quality is None:
|
|
325
|
-
quality =
|
|
329
|
+
quality = 6
|
|
326
330
|
|
|
327
331
|
if shots is None:
|
|
328
332
|
# 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.0
|
|
54
|
+
version='4.1.0',
|
|
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
|