PyQrackIsing 1.14.8__tar.gz → 1.14.10__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.14.8/PyQrackIsing.egg-info → pyqrackising-1.14.10}/PKG-INFO +1 -1
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/maxcut_tfim.py +66 -45
- {pyqrackising-1.14.8 → pyqrackising-1.14.10/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/pyproject.toml +1 -1
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/setup.py +1 -1
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/CMakeLists.txt +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/LICENSE.md +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/MANIFEST.in +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/spin_glass_solver.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/README.md +0 -0
- {pyqrackising-1.14.8 → pyqrackising-1.14.10}/setup.cfg +0 -0
|
@@ -11,10 +11,7 @@ try:
|
|
|
11
11
|
warnings.simplefilter('ignore', category=NumbaPerformanceWarning)
|
|
12
12
|
|
|
13
13
|
@cuda.jit(device=True)
|
|
14
|
-
def cuda_probability_by_hamming_weight(q, J, h, z, theta, t, n_qubits
|
|
15
|
-
if J > 0.0:
|
|
16
|
-
q = n_qubits - (2 + q)
|
|
17
|
-
|
|
14
|
+
def cuda_probability_by_hamming_weight(q, J, h, z, theta, t, n_qubits):
|
|
18
15
|
# critical angle
|
|
19
16
|
theta_c = np.arcsin(max(-1.0, min(1.0, abs(h) / (z * J))))
|
|
20
17
|
|
|
@@ -24,15 +21,18 @@ try:
|
|
|
24
21
|
- 0.5
|
|
25
22
|
)
|
|
26
23
|
|
|
27
|
-
if (p * n_qubits) >= 1024:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
if (p * (n_qubits + 2.0)) >= 1024.0:
|
|
25
|
+
return 0.0
|
|
26
|
+
|
|
27
|
+
result = (pow(2.0, (n_qubits + 2.0) * p) - 1.0) * pow(2.0, -((n_qubits + 1.0) * p) - p * q) / (pow(2.0, p) - 1.0)
|
|
28
|
+
|
|
29
|
+
if math.isnan(result) or math.isinf(result):
|
|
30
|
+
return 0.0
|
|
31
|
+
|
|
32
|
+
return result
|
|
32
33
|
|
|
33
34
|
@cuda.jit
|
|
34
35
|
def cuda_maxcut_hamming_cdf(delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
35
|
-
bias = cuda.shared.array(0, dtype=np.float64)
|
|
36
36
|
step = cuda.blockIdx.x
|
|
37
37
|
qi = cuda.blockIdx.y
|
|
38
38
|
J_eff = J_func[qi]
|
|
@@ -47,10 +47,11 @@ try:
|
|
|
47
47
|
h_t = h_mult * (tot_t - t)
|
|
48
48
|
|
|
49
49
|
qo = cuda.threadIdx.x
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff,
|
|
53
|
-
|
|
50
|
+
if J_eff > 0.0:
|
|
51
|
+
qo = cuda.blockDim.x - (1 + qo)
|
|
52
|
+
diff = cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff, t, n_qubits)
|
|
53
|
+
diff -= cuda_probability_by_hamming_weight(qo, J_eff, h_t, z, theta_eff, tm1, n_qubits)
|
|
54
|
+
hamming_prob[qo] += diff
|
|
54
55
|
|
|
55
56
|
except:
|
|
56
57
|
IS_CUDA_AVAILABLE = False
|
|
@@ -58,7 +59,7 @@ except:
|
|
|
58
59
|
|
|
59
60
|
@njit
|
|
60
61
|
def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
61
|
-
bias = np.zeros(n_qubits - 1)
|
|
62
|
+
bias = np.zeros(n_qubits - 1, dtype=np.float64)
|
|
62
63
|
|
|
63
64
|
# critical angle
|
|
64
65
|
theta_c = np.arcsin(
|
|
@@ -96,7 +97,8 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
|
96
97
|
@njit(parallel=True)
|
|
97
98
|
def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
98
99
|
if n_qubits < 2:
|
|
99
|
-
|
|
100
|
+
hamming_prob.fill(0.0)
|
|
101
|
+
return
|
|
100
102
|
|
|
101
103
|
n_steps = 1 << quality
|
|
102
104
|
delta_t = 1.0 / n_steps
|
|
@@ -141,17 +143,19 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
|
|
|
141
143
|
for i in range(n_bias):
|
|
142
144
|
tot_prob += hamming_prob[i]
|
|
143
145
|
hamming_prob[i] = tot_prob
|
|
144
|
-
hamming_prob[-1] =
|
|
146
|
+
hamming_prob[-1] = 2.0
|
|
145
147
|
|
|
146
148
|
|
|
147
149
|
# Written by Elara (OpenAI custom GPT)
|
|
148
|
-
@njit
|
|
150
|
+
@njit
|
|
149
151
|
def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
150
152
|
"""
|
|
153
|
+
|
|
151
154
|
Pick m nodes out of n with repulsion bias:
|
|
152
155
|
- High-degree nodes are already less likely
|
|
153
156
|
- After choosing a node, its neighbors' probabilities are further reduced
|
|
154
157
|
adjacency: 2D int array (n x max_deg), padded with -1
|
|
158
|
+
|
|
155
159
|
degrees: int array of shape (n,)
|
|
156
160
|
weights: float64 array of shape (n,)
|
|
157
161
|
"""
|
|
@@ -162,7 +166,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
162
166
|
mask = np.zeros(n, dtype=np.bool_)
|
|
163
167
|
chosen_count = 0
|
|
164
168
|
|
|
165
|
-
for _ in
|
|
169
|
+
for _ in range(m):
|
|
166
170
|
# Count available
|
|
167
171
|
total_w = 0.0
|
|
168
172
|
for i in range(n):
|
|
@@ -189,7 +193,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
189
193
|
chosen[chosen_count] = node
|
|
190
194
|
chosen_count += 1
|
|
191
195
|
available[node] = 0
|
|
192
|
-
mask[node] =
|
|
196
|
+
mask[node] = 1
|
|
193
197
|
|
|
194
198
|
# Repulsion: penalize neighbors
|
|
195
199
|
deg = degrees[node]
|
|
@@ -201,10 +205,11 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
|
|
|
201
205
|
return mask
|
|
202
206
|
|
|
203
207
|
|
|
208
|
+
@njit(parallel=True)
|
|
204
209
|
def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n):
|
|
205
|
-
samples =
|
|
210
|
+
samples = np.zeros((shots, n), dtype=np.bool_) # (shots × n) boolean mask array
|
|
206
211
|
|
|
207
|
-
for s in
|
|
212
|
+
for s in prange(shots):
|
|
208
213
|
# First dimension: Hamming weight
|
|
209
214
|
mag_prob = np.random.random()
|
|
210
215
|
m = 0
|
|
@@ -213,19 +218,23 @@ def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights
|
|
|
213
218
|
m += 1
|
|
214
219
|
|
|
215
220
|
# Second dimension: permutation within Hamming weight
|
|
216
|
-
samples
|
|
221
|
+
samples[s, :] = local_repulsion_choice(adjacency, degrees, weights, n, m)
|
|
217
222
|
|
|
218
223
|
return samples
|
|
219
224
|
|
|
220
225
|
|
|
221
|
-
def
|
|
222
|
-
|
|
223
|
-
for
|
|
224
|
-
sample
|
|
225
|
-
|
|
226
|
-
sample
|
|
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)
|
|
235
|
+
|
|
236
|
+
return samples
|
|
227
237
|
|
|
228
|
-
return sample
|
|
229
238
|
|
|
230
239
|
def evaluate_cut_edges(samples, edge_keys, edge_values):
|
|
231
240
|
best_value = float("-inf")
|
|
@@ -268,9 +277,19 @@ def maxcut_tfim(
|
|
|
268
277
|
if n_qubits == 1:
|
|
269
278
|
return "0", 0, ([nodes[0]], [])
|
|
270
279
|
|
|
280
|
+
if n_qubits == 2:
|
|
281
|
+
ed = G.get_edge_data(nodes[0], nodes[1], default={})
|
|
282
|
+
if ed == {}:
|
|
283
|
+
return "01", 0, ([nodes[0]], [nodes[1]])
|
|
284
|
+
|
|
285
|
+
weight = ed.get("weight", 1.0)
|
|
286
|
+
if weight < 0.0:
|
|
287
|
+
return "00", 0, (nodes, [])
|
|
288
|
+
|
|
289
|
+
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
290
|
+
|
|
271
291
|
# Warp size is 32:
|
|
272
292
|
group_size = n_qubits - 1
|
|
273
|
-
shared_size = (n_qubits - 1) * 8
|
|
274
293
|
|
|
275
294
|
if quality is None:
|
|
276
295
|
quality = 10
|
|
@@ -298,19 +317,21 @@ def maxcut_tfim(
|
|
|
298
317
|
dtype=np.float64,
|
|
299
318
|
)
|
|
300
319
|
# thresholds = tfim_sampler._maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality)
|
|
320
|
+
|
|
301
321
|
n_bias = n_qubits - 1
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
n = math.comb(n_qubits, q)
|
|
306
|
-
thresholds[q - 1] = n
|
|
307
|
-
thresholds[n_bias - q] = n
|
|
308
|
-
tot_prob += n << 1
|
|
322
|
+
thresholds = np.zeros(n_bias, dtype=np.float64)
|
|
323
|
+
tot_prob = 0
|
|
324
|
+
p = 1.0
|
|
309
325
|
if n_qubits & 1:
|
|
310
326
|
q = n_qubits // 2
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
327
|
+
thresholds[q - 1] = p
|
|
328
|
+
tot_prob = p
|
|
329
|
+
p /= 2
|
|
330
|
+
for q in range(1, n_qubits // 2):
|
|
331
|
+
thresholds[q - 1] = p
|
|
332
|
+
thresholds[n_bias - q] = p
|
|
333
|
+
tot_prob += 2 * p
|
|
334
|
+
p /= 2
|
|
314
335
|
thresholds /= tot_prob
|
|
315
336
|
|
|
316
337
|
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128:
|
|
@@ -332,7 +353,7 @@ def maxcut_tfim(
|
|
|
332
353
|
)
|
|
333
354
|
)
|
|
334
355
|
|
|
335
|
-
cuda_maxcut_hamming_cdf[grid_dims, group_size
|
|
356
|
+
cuda_maxcut_hamming_cdf[grid_dims, group_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
336
357
|
|
|
337
358
|
tot_prob = sum(thresholds)
|
|
338
359
|
thresholds /= tot_prob
|
|
@@ -341,7 +362,7 @@ def maxcut_tfim(
|
|
|
341
362
|
for i in range(n_bias):
|
|
342
363
|
tot_prob += thresholds[i]
|
|
343
364
|
thresholds[i] = tot_prob
|
|
344
|
-
thresholds[-1] =
|
|
365
|
+
thresholds[-1] = 2.0
|
|
345
366
|
else:
|
|
346
367
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
|
|
347
368
|
|
|
@@ -351,12 +372,12 @@ def maxcut_tfim(
|
|
|
351
372
|
for i in range(len(nodes)):
|
|
352
373
|
adj = G_dict.get(nodes[i], [])
|
|
353
374
|
for j in range(len(adj)):
|
|
354
|
-
adjacency[i, j] = adj[j]
|
|
375
|
+
adjacency[i, j] = nodes.index(adj[j])
|
|
355
376
|
|
|
356
377
|
J_max = max(J_eff)
|
|
357
378
|
weights = 1.0 / (1.0 + (J_max - J_eff))
|
|
358
379
|
# We only need unique instances
|
|
359
|
-
samples = list(set(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits)))
|
|
380
|
+
samples = list(set(mask_array_to_python_ints(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits))))
|
|
360
381
|
|
|
361
382
|
edge_keys = []
|
|
362
383
|
edge_values = []
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.14.
|
|
15
|
+
version = "1.14.10"
|
|
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.14.
|
|
54
|
+
version='1.14.10',
|
|
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
|
|
File without changes
|