PyQrackIsing 1.13.1__tar.gz → 1.14.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-1.13.1/PyQrackIsing.egg-info → pyqrackising-1.14.0}/PKG-INFO +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/maxcut_tfim.py +11 -7
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/spin_glass_solver.py +6 -3
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/tsp_symmetric.py +3 -2
- {pyqrackising-1.13.1 → pyqrackising-1.14.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/README.md +3 -3
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/pyproject.toml +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/setup.py +1 -1
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/CMakeLists.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/LICENSE.md +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/MANIFEST.in +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.13.1 → pyqrackising-1.14.0}/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]
|
|
@@ -243,7 +243,7 @@ def int_to_bitstring(integer, length):
|
|
|
243
243
|
|
|
244
244
|
def maxcut_tfim(
|
|
245
245
|
G,
|
|
246
|
-
quality=
|
|
246
|
+
quality=None,
|
|
247
247
|
shots=None,
|
|
248
248
|
):
|
|
249
249
|
# Number of qubits/nodes
|
|
@@ -256,10 +256,19 @@ def maxcut_tfim(
|
|
|
256
256
|
if n_qubits == 1:
|
|
257
257
|
return "0", 0, ([nodes[0]], [])
|
|
258
258
|
|
|
259
|
+
# Warp size is 32:
|
|
260
|
+
group_size = 32
|
|
261
|
+
|
|
262
|
+
if quality is None:
|
|
263
|
+
quality = int(math.ceil(math.log2((128 * group_size + n_qubits - 1) // n_qubits)))
|
|
264
|
+
|
|
259
265
|
if shots is None:
|
|
260
266
|
# Number of measurement shots
|
|
261
267
|
shots = n_qubits << quality
|
|
262
268
|
|
|
269
|
+
n_steps = 1 << quality
|
|
270
|
+
grid_size = (n_steps * n_qubits + group_size - 1) // group_size
|
|
271
|
+
|
|
263
272
|
J_eff = np.array(
|
|
264
273
|
[
|
|
265
274
|
-sum(edge_attributes.get("weight", 1.0) for _, edge_attributes in G.adj[n].items())
|
|
@@ -290,11 +299,6 @@ def maxcut_tfim(
|
|
|
290
299
|
tot_prob += n
|
|
291
300
|
thresholds /= tot_prob
|
|
292
301
|
|
|
293
|
-
n_steps = 1 << quality
|
|
294
|
-
# Warp size is 32:
|
|
295
|
-
group_size = 32
|
|
296
|
-
grid_size = (n_steps * n_qubits + group_size - 1) // group_size
|
|
297
|
-
|
|
298
302
|
if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128 and (n_qubits <= 8192):
|
|
299
303
|
delta_t = 1.0 / n_steps
|
|
300
304
|
tot_t = n_steps * delta_t
|
|
@@ -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.0"
|
|
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.0',
|
|
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
|