PyQrackIsing 1.18.1__tar.gz → 1.18.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.18.1/PyQrackIsing.egg-info → pyqrackising-1.18.3}/PKG-INFO +1 -1
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/maxcut_tfim.py +8 -20
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/spin_glass_solver.py +21 -33
- {pyqrackising-1.18.1 → pyqrackising-1.18.3/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/pyproject.toml +1 -1
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/setup.py +1 -1
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/CMakeLists.txt +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/LICENSE.md +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/MANIFEST.in +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/README.md +0 -0
- {pyqrackising-1.18.1 → pyqrackising-1.18.3}/setup.cfg +0 -0
|
@@ -236,7 +236,8 @@ def mask_array_to_python_ints(masks):
|
|
|
236
236
|
return samples
|
|
237
237
|
|
|
238
238
|
|
|
239
|
-
def evaluate_cut_edges(
|
|
239
|
+
def evaluate_cut_edges(G_m, samples):
|
|
240
|
+
n_qubits = len(G_m)
|
|
240
241
|
best_value = float("-inf")
|
|
241
242
|
best_solution = None
|
|
242
243
|
best_cut_edges = None
|
|
@@ -244,12 +245,10 @@ def evaluate_cut_edges(samples, edge_keys, edge_values):
|
|
|
244
245
|
for state in samples:
|
|
245
246
|
cut_edges = []
|
|
246
247
|
cut_value = 0
|
|
247
|
-
for
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
cut_value += edge_values[i]
|
|
252
|
-
|
|
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]
|
|
253
252
|
if cut_value > best_value:
|
|
254
253
|
best_value = cut_value
|
|
255
254
|
best_solution = state
|
|
@@ -351,7 +350,7 @@ def maxcut_tfim(
|
|
|
351
350
|
group_size = n_qubits - 1
|
|
352
351
|
|
|
353
352
|
if quality is None:
|
|
354
|
-
quality =
|
|
353
|
+
quality = 8
|
|
355
354
|
|
|
356
355
|
if shots is None:
|
|
357
356
|
# Number of measurement shots
|
|
@@ -391,18 +390,7 @@ def maxcut_tfim(
|
|
|
391
390
|
# We only need unique instances
|
|
392
391
|
samples = list(set(mask_array_to_python_ints(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits))))
|
|
393
392
|
|
|
394
|
-
|
|
395
|
-
edge_values = []
|
|
396
|
-
for i in range(n_qubits):
|
|
397
|
-
for j in range(i + 1, n_qubits):
|
|
398
|
-
weight = G_m[i, j]
|
|
399
|
-
if weight == 0.0:
|
|
400
|
-
continue
|
|
401
|
-
edge_keys.append(i)
|
|
402
|
-
edge_keys.append(j)
|
|
403
|
-
edge_values.append(weight)
|
|
404
|
-
|
|
405
|
-
best_solution, best_value = evaluate_cut_edges(samples, edge_keys, edge_values)
|
|
393
|
+
best_solution, best_value = evaluate_cut_edges(G_m, samples)
|
|
406
394
|
|
|
407
395
|
bit_string = int_to_bitstring(best_solution, n_qubits)
|
|
408
396
|
bit_list = list(bit_string)
|
|
@@ -6,48 +6,47 @@ from numba import njit, prange
|
|
|
6
6
|
import os
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def evaluate_cut_edges(state,
|
|
9
|
+
def evaluate_cut_edges(state, G_m):
|
|
10
|
+
n_qubits = len(G_m)
|
|
10
11
|
cut_value = 0
|
|
11
|
-
for
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
cut_value += edge_values[i]
|
|
12
|
+
for u in range(n_qubits):
|
|
13
|
+
for v in range(u + 1, n_qubits):
|
|
14
|
+
if ((state >> u) & 1) != ((state >> v) & 1):
|
|
15
|
+
cut_value += G_m[u, v]
|
|
16
16
|
|
|
17
17
|
return float(cut_value)
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
@njit
|
|
21
|
-
def compute_energy(theta_bits,
|
|
21
|
+
def compute_energy(theta_bits, G_m):
|
|
22
|
+
n_qubits = len(G_m)
|
|
22
23
|
energy = 0
|
|
23
|
-
for
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
energy += edge_values[i] * spin_u * spin_v
|
|
24
|
+
for u in range(n_qubits):
|
|
25
|
+
for v in range(u + 1, n_qubits):
|
|
26
|
+
spin_u = 1 if theta_bits[u] else -1
|
|
27
|
+
spin_v = 1 if theta_bits[v] else -1
|
|
28
|
+
energy += G_m[u, v] * spin_u * spin_v
|
|
29
29
|
|
|
30
30
|
return energy
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
@njit
|
|
34
|
-
def bootstrap_worker(theta,
|
|
34
|
+
def bootstrap_worker(theta, G_m, indices):
|
|
35
35
|
local_theta = theta.copy()
|
|
36
36
|
for i in indices:
|
|
37
37
|
local_theta[i] = not local_theta[i]
|
|
38
|
-
energy = compute_energy(local_theta,
|
|
38
|
+
energy = compute_energy(local_theta, G_m)
|
|
39
39
|
|
|
40
40
|
return energy
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
@njit(parallel=True)
|
|
44
|
-
def bootstrap(theta,
|
|
44
|
+
def bootstrap(theta, G_m, k, indices_array):
|
|
45
45
|
n = len(indices_array) // k
|
|
46
46
|
energies = np.empty(n)
|
|
47
|
-
j = 0
|
|
48
47
|
for i in prange(n):
|
|
49
|
-
|
|
50
|
-
j
|
|
48
|
+
j = i * k
|
|
49
|
+
energies[i] = bootstrap_worker(theta, G_m, indices_array[j : j + k])
|
|
51
50
|
|
|
52
51
|
return energies
|
|
53
52
|
|
|
@@ -99,18 +98,7 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
|
|
|
99
98
|
bitstring, _, _ = maxcut_tfim(G_m, quality=quality, shots=shots)
|
|
100
99
|
best_theta = [b == "1" for b in list(bitstring)]
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
edge_values = []
|
|
104
|
-
for i in range(n_qubits):
|
|
105
|
-
for j in range(i + 1, n_qubits):
|
|
106
|
-
weight = G_m[i, j]
|
|
107
|
-
if weight == 0.0:
|
|
108
|
-
continue
|
|
109
|
-
edge_keys.append(i)
|
|
110
|
-
edge_keys.append(j)
|
|
111
|
-
edge_values.append(weight)
|
|
112
|
-
|
|
113
|
-
min_energy = compute_energy(best_theta, edge_keys, edge_values)
|
|
101
|
+
min_energy = compute_energy(best_theta, G_m)
|
|
114
102
|
improved = True
|
|
115
103
|
while improved:
|
|
116
104
|
improved = False
|
|
@@ -123,7 +111,7 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
|
|
|
123
111
|
combos = list(
|
|
124
112
|
item for sublist in itertools.combinations(range(n_qubits), k) for item in sublist
|
|
125
113
|
)
|
|
126
|
-
energies = bootstrap(theta,
|
|
114
|
+
energies = bootstrap(theta, G_m, k, combos)
|
|
127
115
|
|
|
128
116
|
energy = min(energies)
|
|
129
117
|
if energy < min_energy:
|
|
@@ -148,6 +136,6 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
|
|
|
148
136
|
bitstring += "0"
|
|
149
137
|
l.append(nodes[i])
|
|
150
138
|
|
|
151
|
-
cut_value = evaluate_cut_edges(sample,
|
|
139
|
+
cut_value = evaluate_cut_edges(sample, G_m)
|
|
152
140
|
|
|
153
141
|
return bitstring, float(cut_value), (l, r), float(min_energy)
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.18.
|
|
15
|
+
version = "1.18.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.18.
|
|
54
|
+
version='1.18.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
|