PyQrackIsing 1.13.1__tar.gz → 1.14.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-1.13.1/PyQrackIsing.egg-info → pyqrackising-1.14.1}/PKG-INFO +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/maxcut_tfim.py +45 -9
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/spin_glass_solver.py +6 -3
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/tsp_symmetric.py +3 -2
- {pyqrackising-1.13.1 → pyqrackising-1.14.1/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/README.md +3 -3
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/pyproject.toml +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/setup.py +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/CMakeLists.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/LICENSE.md +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/MANIFEST.in +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.1}/setup.cfg +0 -0
|
@@ -55,7 +55,7 @@ try:
|
|
|
55
55
|
step = qc // n_qubits
|
|
56
56
|
q = qc % n_qubits
|
|
57
57
|
|
|
58
|
-
if step
|
|
58
|
+
if step >= n_steps:
|
|
59
59
|
return
|
|
60
60
|
|
|
61
61
|
J_eff = J_func[q]
|
|
@@ -76,6 +76,35 @@ try:
|
|
|
76
76
|
for i in range(n_qubits - 1):
|
|
77
77
|
hamming_prob[i] += bias[i] - last_bias[i]
|
|
78
78
|
|
|
79
|
+
|
|
80
|
+
@cuda.jit
|
|
81
|
+
def cuda_maxcut_hamming_cdf_large(n_qubits, n_steps, delta_t, tot_t, h_mult, J_func, degrees, theta, hamming_prob):
|
|
82
|
+
qc = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
|
|
83
|
+
step = qc // n_qubits
|
|
84
|
+
q = qc % n_qubits
|
|
85
|
+
|
|
86
|
+
if step >= n_steps:
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
J_eff = J_func[q]
|
|
90
|
+
if abs(J_eff) <= (2 ** (-54)):
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
z = degrees[q]
|
|
94
|
+
theta_eff = theta[q]
|
|
95
|
+
t = step * delta_t
|
|
96
|
+
tm1 = (step - 1) * delta_t
|
|
97
|
+
h_t = h_mult * (tot_t - t)
|
|
98
|
+
n_bias = n_qubits - 1
|
|
99
|
+
|
|
100
|
+
bias = cuda.local.array(shape=(16384,), dtype=types.float64)
|
|
101
|
+
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits, bias)
|
|
102
|
+
for i in range(n_qubits - 1):
|
|
103
|
+
hamming_prob[i] += bias[i]
|
|
104
|
+
cuda_probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits, bias)
|
|
105
|
+
for i in range(n_qubits - 1):
|
|
106
|
+
hamming_prob[i] -= bias[i]
|
|
107
|
+
|
|
79
108
|
except:
|
|
80
109
|
IS_CUDA_AVAILABLE = False
|
|
81
110
|
|
|
@@ -243,7 +272,7 @@ def int_to_bitstring(integer, length):
|
|
|
243
272
|
|
|
244
273
|
def maxcut_tfim(
|
|
245
274
|
G,
|
|
246
|
-
quality=
|
|
275
|
+
quality=None,
|
|
247
276
|
shots=None,
|
|
248
277
|
):
|
|
249
278
|
# Number of qubits/nodes
|
|
@@ -256,10 +285,19 @@ def maxcut_tfim(
|
|
|
256
285
|
if n_qubits == 1:
|
|
257
286
|
return "0", 0, ([nodes[0]], [])
|
|
258
287
|
|
|
288
|
+
# Warp size is 32:
|
|
289
|
+
group_size = 32
|
|
290
|
+
|
|
291
|
+
if quality is None:
|
|
292
|
+
quality = int(math.ceil(math.log2((128 * group_size + n_qubits - 1) // n_qubits)))
|
|
293
|
+
|
|
259
294
|
if shots is None:
|
|
260
295
|
# Number of measurement shots
|
|
261
296
|
shots = n_qubits << quality
|
|
262
297
|
|
|
298
|
+
n_steps = 1 << quality
|
|
299
|
+
grid_size = (n_steps * n_qubits + group_size - 1) // group_size
|
|
300
|
+
|
|
263
301
|
J_eff = np.array(
|
|
264
302
|
[
|
|
265
303
|
-sum(edge_attributes.get("weight", 1.0) for _, edge_attributes in G.adj[n].items())
|
|
@@ -290,12 +328,7 @@ def maxcut_tfim(
|
|
|
290
328
|
tot_prob += n
|
|
291
329
|
thresholds /= tot_prob
|
|
292
330
|
|
|
293
|
-
|
|
294
|
-
# Warp size is 32:
|
|
295
|
-
group_size = 32
|
|
296
|
-
grid_size = (n_steps * n_qubits + group_size - 1) // group_size
|
|
297
|
-
|
|
298
|
-
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128 and (n_qubits <= 8192):
|
|
331
|
+
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128 and (n_qubits <= 16384):
|
|
299
332
|
delta_t = 1.0 / n_steps
|
|
300
333
|
tot_t = n_steps * delta_t
|
|
301
334
|
h_mult = 32.0 / tot_t
|
|
@@ -314,7 +347,10 @@ def maxcut_tfim(
|
|
|
314
347
|
)
|
|
315
348
|
)
|
|
316
349
|
|
|
317
|
-
|
|
350
|
+
if n_qubits <= 8192:
|
|
351
|
+
cuda_maxcut_hamming_cdf[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
352
|
+
else:
|
|
353
|
+
cuda_maxcut_hamming_cdf_large[grid_size, group_size](n_qubits, n_steps, delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
|
|
318
354
|
|
|
319
355
|
tot_prob = sum(thresholds)
|
|
320
356
|
thresholds /= tot_prob
|
|
@@ -56,7 +56,7 @@ def int_to_bitstring(integer, length):
|
|
|
56
56
|
return (bin(integer)[2:].zfill(length))[::-1]
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def spin_glass_solver(G, quality=
|
|
59
|
+
def spin_glass_solver(G, quality=None, shots=None, correction_quality=2, best_guess=None):
|
|
60
60
|
nodes = list(G.nodes())
|
|
61
61
|
n_qubits = len(nodes)
|
|
62
62
|
|
|
@@ -66,6 +66,9 @@ def spin_glass_solver(G, quality=5, best_guess=None):
|
|
|
66
66
|
if n_qubits == 1:
|
|
67
67
|
return "0", 0, ([nodes[0]], [])
|
|
68
68
|
|
|
69
|
+
# Warp size is 32:
|
|
70
|
+
group_size = 32
|
|
71
|
+
|
|
69
72
|
bitstring = ""
|
|
70
73
|
if isinstance(best_guess, str):
|
|
71
74
|
bitstring = best_guess
|
|
@@ -74,7 +77,7 @@ def spin_glass_solver(G, quality=5, best_guess=None):
|
|
|
74
77
|
elif isinstance(best_guess, list):
|
|
75
78
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
76
79
|
else:
|
|
77
|
-
bitstring, _, _ = maxcut_tfim(G, quality=quality)
|
|
80
|
+
bitstring, _, _ = maxcut_tfim(G, quality=quality, shots=shots)
|
|
78
81
|
best_theta = [b == "1" for b in list(bitstring)]
|
|
79
82
|
|
|
80
83
|
edge_keys = []
|
|
@@ -88,7 +91,7 @@ def spin_glass_solver(G, quality=5, best_guess=None):
|
|
|
88
91
|
improved = True
|
|
89
92
|
while improved:
|
|
90
93
|
improved = False
|
|
91
|
-
for k in range(1, max(
|
|
94
|
+
for k in range(1, max(1, correction_quality + 1)):
|
|
92
95
|
if n_qubits < k:
|
|
93
96
|
break
|
|
94
97
|
|
|
@@ -21,7 +21,7 @@ def get_best_stitch(adjacency, terminals_a, terminals_b, is_cyclic):
|
|
|
21
21
|
return best_weight, best_edge
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def tsp_symmetric(G, quality=
|
|
24
|
+
def tsp_symmetric(G, quality=None, shots=None, correction_quality=2, is_cyclic=True, start_node=None):
|
|
25
25
|
nodes = list(G.nodes())
|
|
26
26
|
n_nodes = len(nodes)
|
|
27
27
|
|
|
@@ -40,7 +40,8 @@ def tsp_symmetric(G, quality=1, is_cyclic=True, start_node=None):
|
|
|
40
40
|
b.remove(start_node)
|
|
41
41
|
else:
|
|
42
42
|
while (len(a) == 0) or (len(b) == 0):
|
|
43
|
-
|
|
43
|
+
bits = ''
|
|
44
|
+
_, _, bits, _ = spin_glass_solver(G, quality=quality, shots=shots, correction_quality=correction_quality)
|
|
44
45
|
a = list(bits[0])
|
|
45
46
|
b = list(bits[1])
|
|
46
47
|
|
|
@@ -49,7 +49,7 @@ G = nx.petersen_graph()
|
|
|
49
49
|
best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=8)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
The (integer) `quality` setting is optional, with a default value
|
|
52
|
+
The (integer) `quality` setting is optional, with a default value optimized to barely engage CUDA, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
|
|
53
53
|
|
|
54
54
|
Based on a combination of the TFIM-inspired MAXCUT solver and another technique for finding ground-state energy in quantum chemistry that we call the _"binary Clifford eigensolver,"_ we also provide an (approximate) spin glass ground-state solver:
|
|
55
55
|
```py
|
|
@@ -69,10 +69,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
G = generate_spin_glass_graph(n_nodes=64, seed=42)
|
|
72
|
-
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=5, best_guess=None)
|
|
72
|
+
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=5, correction_quality=2, best_guess=None)
|
|
73
73
|
# solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=8)[0])
|
|
74
74
|
```
|
|
75
|
-
The (integer) `quality` setting is
|
|
75
|
+
The (integer) `quality` setting is the same as `maxcut_tfim`. `correction_quality` controls an additional convex optimization procedure on top of `best_guess` and defaults to 2. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
|
|
76
76
|
|
|
77
77
|
From the `spin_glass_solver()`, we provide a (recursive) Traveling Salesman Problem (TSP) solver:
|
|
78
78
|
```py
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "PyQrackIsing"
|
|
15
|
-
version = "1.
|
|
15
|
+
version = "1.14.1"
|
|
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.
|
|
54
|
+
version='1.14.1',
|
|
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
|