PyQrackIsing 1.26.1__tar.gz → 1.26.3__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.26.1/PyQrackIsing.egg-info → pyqrackising-1.26.3}/PKG-INFO +1 -1
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/maxcut_tfim.py +42 -58
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/spin_glass_solver.py +2 -3
- {pyqrackising-1.26.1 → pyqrackising-1.26.3/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/pyproject.toml +1 -1
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/setup.py +1 -1
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/CMakeLists.txt +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/LICENSE.md +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/MANIFEST.in +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/README.md +0 -0
- {pyqrackising-1.26.1 → pyqrackising-1.26.3}/setup.cfg +0 -0
|
@@ -162,7 +162,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
162
162
|
|
|
163
163
|
weights = weights.copy()
|
|
164
164
|
chosen = np.zeros(m, dtype=np.int32) # store chosen indices
|
|
165
|
-
available = np.ones(n, dtype=np.
|
|
165
|
+
available = np.ones(n, dtype=np.bool_) # True = available, False = not
|
|
166
166
|
mask = np.zeros(n, dtype=np.bool_)
|
|
167
167
|
chosen_count = 0
|
|
168
168
|
|
|
@@ -170,7 +170,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
170
170
|
# Count available
|
|
171
171
|
total_w = 0.0
|
|
172
172
|
for i in range(n):
|
|
173
|
-
if available[i]
|
|
173
|
+
if available[i]:
|
|
174
174
|
total_w += weights[i]
|
|
175
175
|
if total_w <= 0:
|
|
176
176
|
break
|
|
@@ -180,7 +180,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
180
180
|
cum = 0.0
|
|
181
181
|
node = -1
|
|
182
182
|
for i in range(n):
|
|
183
|
-
if available[i]
|
|
183
|
+
if available[i]:
|
|
184
184
|
cum += weights[i] / total_w
|
|
185
185
|
if r < cum:
|
|
186
186
|
node = i
|
|
@@ -192,22 +192,38 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
192
192
|
# Select node
|
|
193
193
|
chosen[chosen_count] = node
|
|
194
194
|
chosen_count += 1
|
|
195
|
-
available[node] =
|
|
196
|
-
mask[node] =
|
|
195
|
+
available[node] = False
|
|
196
|
+
mask[node] = True
|
|
197
197
|
|
|
198
198
|
# Repulsion: penalize neighbors
|
|
199
|
-
|
|
200
|
-
for j in range(deg):
|
|
199
|
+
for j in range(degrees[node]):
|
|
201
200
|
nbr = adjacency[node, j]
|
|
202
|
-
if nbr
|
|
201
|
+
if nbr < 0:
|
|
202
|
+
break
|
|
203
|
+
if available[nbr]:
|
|
203
204
|
weights[nbr] *= 0.5 # tunable penalty factor
|
|
204
205
|
|
|
205
206
|
return mask
|
|
206
207
|
|
|
207
208
|
|
|
209
|
+
@njit
|
|
210
|
+
def compute_energy(sample, G_m, n_qubits):
|
|
211
|
+
energy = 0
|
|
212
|
+
for u in range(n_qubits):
|
|
213
|
+
for v in range(u + 1, n_qubits):
|
|
214
|
+
eigen = 1 if sample[u] == sample[v] else -1
|
|
215
|
+
energy += G_m[u, v] * eigen
|
|
216
|
+
|
|
217
|
+
return energy
|
|
218
|
+
|
|
219
|
+
|
|
208
220
|
@njit(parallel=True)
|
|
209
|
-
def
|
|
210
|
-
|
|
221
|
+
def sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n):
|
|
222
|
+
adjacency = compute_adjacency(G_m, degrees.max())
|
|
223
|
+
weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
224
|
+
|
|
225
|
+
best_solution = np.zeros(n, dtype=np.bool_)
|
|
226
|
+
best_energy = compute_energy(best_solution, G_m, n)
|
|
211
227
|
|
|
212
228
|
for s in prange(shots):
|
|
213
229
|
# First dimension: Hamming weight
|
|
@@ -218,40 +234,18 @@ def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights
|
|
|
218
234
|
m += 1
|
|
219
235
|
|
|
220
236
|
# Second dimension: permutation within Hamming weight
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return samples
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
def mask_array_to_python_ints(masks):
|
|
227
|
-
samples = []
|
|
228
|
-
for mask in masks:
|
|
229
|
-
sample = 0
|
|
230
|
-
for b in reversed(mask):
|
|
231
|
-
sample <<= 1
|
|
232
|
-
if b:
|
|
233
|
-
sample |= 1
|
|
234
|
-
samples.append(sample)
|
|
237
|
+
sample = local_repulsion_choice(adjacency, degrees, weights, n, m)
|
|
235
238
|
|
|
236
|
-
|
|
239
|
+
energy = compute_energy(sample, G_m, n)
|
|
240
|
+
if energy < best_energy:
|
|
241
|
+
best_energy = energy
|
|
242
|
+
best_solution = sample
|
|
237
243
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
best_cut_edges = None
|
|
244
|
-
|
|
245
|
-
for state in samples:
|
|
246
|
-
cut_edges = []
|
|
247
|
-
cut_value = 0
|
|
248
|
-
for u in range(n_qubits):
|
|
249
|
-
for v in range(u + 1, n_qubits):
|
|
250
|
-
if ((state >> u) & 1) != ((state >> v) & 1):
|
|
251
|
-
cut_value += G_m[u, v]
|
|
252
|
-
if cut_value > best_value:
|
|
253
|
-
best_value = cut_value
|
|
254
|
-
best_solution = state
|
|
244
|
+
best_value = 0
|
|
245
|
+
for u in range(n):
|
|
246
|
+
for v in range(u + 1, n):
|
|
247
|
+
if best_solution[u] != best_solution[v]:
|
|
248
|
+
best_value += G_m[u, v]
|
|
255
249
|
|
|
256
250
|
return best_solution, float(best_value)
|
|
257
251
|
|
|
@@ -313,11 +307,11 @@ def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
|
|
|
313
307
|
|
|
314
308
|
return theta
|
|
315
309
|
|
|
316
|
-
@njit
|
|
317
|
-
def compute_adjacency(G_m):
|
|
310
|
+
@njit(parallel=True)
|
|
311
|
+
def compute_adjacency(G_m, max_degree):
|
|
318
312
|
n_qubits = len(G_m)
|
|
319
|
-
adjacency = np.full((n_qubits,
|
|
320
|
-
for i in
|
|
313
|
+
adjacency = np.full((n_qubits, max_degree), -1, dtype=np.int32)
|
|
314
|
+
for i in prange(n_qubits):
|
|
321
315
|
k = 0
|
|
322
316
|
for j in range(n_qubits):
|
|
323
317
|
if i == j:
|
|
@@ -329,11 +323,6 @@ def compute_adjacency(G_m):
|
|
|
329
323
|
return adjacency
|
|
330
324
|
|
|
331
325
|
|
|
332
|
-
# By Gemini (Google Search AI)
|
|
333
|
-
def int_to_bitstring(integer, length):
|
|
334
|
-
return (bin(integer)[2:].zfill(length))[::-1]
|
|
335
|
-
|
|
336
|
-
|
|
337
326
|
def maxcut_tfim(
|
|
338
327
|
G,
|
|
339
328
|
quality=None,
|
|
@@ -398,14 +387,9 @@ def maxcut_tfim(
|
|
|
398
387
|
else:
|
|
399
388
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
|
|
400
389
|
|
|
401
|
-
|
|
402
|
-
weights = 1.0 / (1.0 + (2 ** -53) - J_eff)
|
|
403
|
-
# We only need unique instances
|
|
404
|
-
samples = list(set(mask_array_to_python_ints(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits))))
|
|
405
|
-
|
|
406
|
-
best_solution, best_value = evaluate_cut_edges(G_m, samples)
|
|
390
|
+
best_solution, best_value = sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n_qubits)
|
|
407
391
|
|
|
408
|
-
bit_string =
|
|
392
|
+
bit_string = "".join(["1" if b else "0" for b in best_solution])
|
|
409
393
|
bit_list = list(bit_string)
|
|
410
394
|
l, r = [], []
|
|
411
395
|
for i in range(len(bit_list)):
|
|
@@ -23,9 +23,8 @@ def compute_energy(theta_bits, G_m):
|
|
|
23
23
|
energy = 0
|
|
24
24
|
for u in range(n_qubits):
|
|
25
25
|
for v in range(u + 1, n_qubits):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
energy += G_m[u, v] * spin_u * spin_v
|
|
26
|
+
eigen = 1 if theta_bits[u] == theta_bits[v] else -1
|
|
27
|
+
energy += G_m[u, v] * eigen
|
|
29
28
|
|
|
30
29
|
return energy
|
|
31
30
|
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.26.
|
|
15
|
+
version = "1.26.3"
|
|
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.26.
|
|
54
|
+
version='1.26.3',
|
|
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
|