PyQrackIsing 1.11.0__tar.gz → 1.12.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.11.0/PyQrackIsing.egg-info → pyqrackising-1.12.0}/PKG-INFO +1 -1
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/maxcut_tfim.py +12 -15
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/spin_glass_solver.py +2 -2
- {pyqrackising-1.11.0 → pyqrackising-1.12.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/README.md +4 -4
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/pyproject.toml +1 -1
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/setup.py +1 -1
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/CMakeLists.txt +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/LICENSE.md +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/MANIFEST.in +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing/tsp_symmetric.py +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.11.0 → pyqrackising-1.12.0}/setup.cfg +0 -0
|
@@ -5,12 +5,7 @@ from numba import njit, prange
|
|
|
5
5
|
|
|
6
6
|
@njit
|
|
7
7
|
def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
8
|
-
if np.isclose(abs(J), 0.0):
|
|
9
|
-
return np.full(n_qubits - 1, 1.0 / (n_qubits - 1.0))
|
|
10
|
-
|
|
11
8
|
bias = np.zeros(n_qubits - 1)
|
|
12
|
-
if np.isclose(abs(h), 0.0):
|
|
13
|
-
return bias
|
|
14
9
|
|
|
15
10
|
# critical angle
|
|
16
11
|
theta_c = np.arcsin(
|
|
@@ -50,10 +45,10 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality):
|
|
|
50
45
|
if n_qubits < 2:
|
|
51
46
|
return np.empty(0, dtype=np.float64)
|
|
52
47
|
|
|
53
|
-
n_steps =
|
|
54
|
-
delta_t = 1.0 /
|
|
55
|
-
tot_t =
|
|
56
|
-
h_mult =
|
|
48
|
+
n_steps = 1 << quality
|
|
49
|
+
delta_t = 1.0 / n_steps
|
|
50
|
+
tot_t = n_steps * delta_t
|
|
51
|
+
h_mult = 32.0 / tot_t
|
|
57
52
|
n_bias = n_qubits - 1
|
|
58
53
|
hamming_prob = np.full(n_bias, 1 / n_bias)
|
|
59
54
|
theta = np.zeros(n_qubits)
|
|
@@ -73,13 +68,15 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality):
|
|
|
73
68
|
for qc in prange(n_qubits, n_steps * n_qubits):
|
|
74
69
|
step = qc // n_qubits
|
|
75
70
|
q = qc % n_qubits
|
|
76
|
-
t = step * delta_t
|
|
77
|
-
tm1 = (step - 1) * delta_t
|
|
78
|
-
z = degrees[q]
|
|
79
71
|
J_eff = J_func[q]
|
|
72
|
+
if np.isclose(abs(J_eff), 0.0):
|
|
73
|
+
continue
|
|
74
|
+
z = degrees[q]
|
|
80
75
|
theta_eff = theta[q]
|
|
76
|
+
t = step * delta_t
|
|
77
|
+
tm1 = (step - 1) * delta_t
|
|
81
78
|
h_t = h_mult * (tot_t - t)
|
|
82
|
-
bias = probability_by_hamming_weight(J_eff,
|
|
79
|
+
bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_qubits)
|
|
83
80
|
last_bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_qubits)
|
|
84
81
|
for i in range(n_bias):
|
|
85
82
|
hamming_prob[i] += bias[i] - last_bias[i]
|
|
@@ -171,7 +168,7 @@ def int_to_bitstring(integer, length):
|
|
|
171
168
|
|
|
172
169
|
def maxcut_tfim(
|
|
173
170
|
G,
|
|
174
|
-
quality=
|
|
171
|
+
quality=8,
|
|
175
172
|
shots=None,
|
|
176
173
|
):
|
|
177
174
|
# Number of qubits/nodes
|
|
@@ -186,7 +183,7 @@ def maxcut_tfim(
|
|
|
186
183
|
|
|
187
184
|
if shots is None:
|
|
188
185
|
# Number of measurement shots
|
|
189
|
-
shots = n_qubits <<
|
|
186
|
+
shots = n_qubits << quality
|
|
190
187
|
|
|
191
188
|
J_eff = np.array(
|
|
192
189
|
[
|
|
@@ -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=5, best_guess=None):
|
|
60
60
|
nodes = list(G.nodes())
|
|
61
61
|
n_qubits = len(nodes)
|
|
62
62
|
|
|
@@ -88,7 +88,7 @@ def spin_glass_solver(G, quality=4, best_guess=None):
|
|
|
88
88
|
improved = True
|
|
89
89
|
while improved:
|
|
90
90
|
improved = False
|
|
91
|
-
for k in range(1, max(
|
|
91
|
+
for k in range(1, max(3, quality - 2)):
|
|
92
92
|
if n_qubits < k:
|
|
93
93
|
break
|
|
94
94
|
|
|
@@ -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 of `
|
|
52
|
+
The (integer) `quality` setting is optional, with a default value of `8`, 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=
|
|
72
|
+
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=5, 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 optional, with a default value of `
|
|
75
|
+
The (integer) `quality` setting is optional, with a default value of `5`. `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
|
|
@@ -93,7 +93,7 @@ def generate_tsp_graph(n_nodes=64, seed=None):
|
|
|
93
93
|
|
|
94
94
|
n_nodes = 128
|
|
95
95
|
G = generate_tsp_graph(n_nodes=n_nodes, seed=42)
|
|
96
|
-
circuit, path_length = tsp_symmetric(G, quality=
|
|
96
|
+
circuit, path_length = tsp_symmetric(G, quality=1, is_cyclic=True, start_node=None)
|
|
97
97
|
|
|
98
98
|
print(f"Node count: {n_nodes}")
|
|
99
99
|
print(f"Path: {circuit}")
|
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "PyQrackIsing"
|
|
14
|
-
version = "1.
|
|
14
|
+
version = "1.12.0"
|
|
15
15
|
requires-python = ">=3.8"
|
|
16
16
|
description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
|
|
17
17
|
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.12.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
|
|
File without changes
|