PyQrackIsing 1.10.6__tar.gz → 1.10.7__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.10.6/PyQrackIsing.egg-info → pyqrackising-1.10.7}/PKG-INFO +1 -1
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/maxcut_tfim.py +18 -22
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/spin_glass_solver.py +3 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/tsp_symmetric.py +19 -26
- {pyqrackising-1.10.6 → pyqrackising-1.10.7/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/pyproject.toml +1 -1
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/setup.py +1 -1
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/CMakeLists.txt +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/LICENSE.md +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/MANIFEST.in +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/README.md +0 -0
- {pyqrackising-1.10.6 → pyqrackising-1.10.7}/setup.cfg +0 -0
|
@@ -5,46 +5,39 @@ 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
|
-
# critical angle
|
|
9
|
-
theta_c = np.arcsin(
|
|
10
|
-
max(
|
|
11
|
-
-1.0,
|
|
12
|
-
min(
|
|
13
|
-
1.0,
|
|
14
|
-
(1.0 if J > 0.0 else -1.0) if np.isclose(abs(z * J), 0.0) else (abs(h) / (z * J)),
|
|
15
|
-
),
|
|
16
|
-
)
|
|
17
|
-
)
|
|
18
|
-
delta_theta = theta - theta_c
|
|
19
8
|
bias = np.zeros(n_qubits + 1)
|
|
20
|
-
|
|
21
9
|
if np.isclose(abs(h), 0.0):
|
|
22
10
|
bias[0] = 1.0
|
|
23
11
|
elif np.isclose(abs(J), 0.0):
|
|
24
12
|
bias.fill(1.0 / (n_qubits + 1.0))
|
|
25
13
|
else:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
# critical angle
|
|
15
|
+
theta_c = np.arcsin(
|
|
16
|
+
max(
|
|
17
|
+
-1.0,
|
|
18
|
+
min(
|
|
19
|
+
1.0,
|
|
20
|
+
(1.0 if J > 0.0 else -1.0) if np.isclose(abs(z * J), 0.0) else (abs(h) / (z * J)),
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
)
|
|
29
24
|
p = (
|
|
30
25
|
pow(2.0, abs(J / h) - 1.0)
|
|
31
|
-
* (1.0 +
|
|
26
|
+
* (1.0 + np.sin(theta - theta_c) * np.cos(1.5 * np.pi * J * t + theta) / (1.0 + np.sqrt(t)))
|
|
32
27
|
- 0.5
|
|
33
28
|
)
|
|
34
|
-
|
|
35
|
-
if p >= 1024:
|
|
29
|
+
if (p * n_qubits) >= 1024:
|
|
36
30
|
bias[0] = 1.0
|
|
37
31
|
else:
|
|
38
32
|
tot_n = 0.0
|
|
39
33
|
for q in range(n_qubits + 1):
|
|
40
|
-
n = 1.0 /
|
|
34
|
+
n = 1.0 / pow(2.0, p * q)
|
|
41
35
|
bias[q] = n
|
|
42
36
|
tot_n += n
|
|
43
|
-
|
|
44
|
-
bias[q] /= tot_n
|
|
37
|
+
bias /= tot_n
|
|
45
38
|
|
|
46
39
|
if J > 0.0:
|
|
47
|
-
|
|
40
|
+
return bias[::-1]
|
|
48
41
|
|
|
49
42
|
return bias
|
|
50
43
|
|
|
@@ -179,6 +172,9 @@ def maxcut_tfim(
|
|
|
179
172
|
if n_qubits == 0:
|
|
180
173
|
return "", 0, ([], [])
|
|
181
174
|
|
|
175
|
+
if n_qubits == 1:
|
|
176
|
+
return "0", 0, ([nodes[0]], [])
|
|
177
|
+
|
|
182
178
|
if shots is None:
|
|
183
179
|
# Number of measurement shots
|
|
184
180
|
shots = n_qubits << quality
|
|
@@ -22,12 +22,15 @@ def get_best_stitch(adjacency, terminals_a, terminals_b, is_cyclic):
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def tsp_symmetric(G, quality=2, is_cyclic=True, start_node=None):
|
|
25
|
-
if G.number_of_nodes() == 1:
|
|
26
|
-
return ([0], 0)
|
|
27
|
-
if G.number_of_nodes() == 2:
|
|
28
|
-
return ([0, 1], G[0][1]["weight"])
|
|
29
|
-
|
|
30
25
|
nodes = list(G.nodes())
|
|
26
|
+
n_nodes = len(nodes)
|
|
27
|
+
|
|
28
|
+
if n_nodes == 0:
|
|
29
|
+
return ([], 0)
|
|
30
|
+
if n_nodes == 1:
|
|
31
|
+
return ([nodes[0]], 0)
|
|
32
|
+
if n_nodes == 2:
|
|
33
|
+
return ([nodes[0], nodes[1]], G[nodes[0]][nodes[1]]["weight"])
|
|
31
34
|
|
|
32
35
|
a = []
|
|
33
36
|
b = []
|
|
@@ -37,38 +40,28 @@ def tsp_symmetric(G, quality=2, is_cyclic=True, start_node=None):
|
|
|
37
40
|
b.remove(start_node)
|
|
38
41
|
else:
|
|
39
42
|
while (len(a) == 0) or (len(b) == 0):
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
b.append(nodes[idx])
|
|
44
|
-
else:
|
|
45
|
-
a.append(nodes[idx])
|
|
43
|
+
_, _, bits, _ = spin_glass_solver(G, quality=quality)
|
|
44
|
+
a = list(bits[0])
|
|
45
|
+
b = list(bits[1])
|
|
46
46
|
|
|
47
47
|
G_a = nx.Graph()
|
|
48
48
|
G_b = nx.Graph()
|
|
49
49
|
for u, v, data in G.edges(data=True):
|
|
50
50
|
weight = data.get("weight", 1.0)
|
|
51
51
|
if (u in a) and (v in a):
|
|
52
|
-
G_a.add_edge(
|
|
52
|
+
G_a.add_edge(u, v, weight=weight)
|
|
53
53
|
continue
|
|
54
54
|
elif (u in b) and (v in b):
|
|
55
|
-
G_b.add_edge(
|
|
55
|
+
G_b.add_edge(u, v, weight=weight)
|
|
56
56
|
continue
|
|
57
57
|
|
|
58
|
-
sol_a = (
|
|
59
|
-
|
|
60
|
-
if len(a) > 2
|
|
61
|
-
else (([0, 1], G_a[0][1]["weight"]) if len(a) == 2 else ([0], 0))
|
|
62
|
-
)
|
|
63
|
-
sol_b = (
|
|
64
|
-
tsp_symmetric(G_b, quality=quality, is_cyclic=False)
|
|
65
|
-
if len(b) > 2
|
|
66
|
-
else (([0, 1], G_b[0][1]["weight"]) if len(b) == 2 else ([0], 0))
|
|
67
|
-
)
|
|
68
|
-
sol_weight = sol_a[1] + sol_b[1]
|
|
58
|
+
sol_a = tsp_symmetric(G_a, quality=quality, is_cyclic=False) if len(a) > 1 else (a, 0)
|
|
59
|
+
sol_b = tsp_symmetric(G_b, quality=quality, is_cyclic=False) if len(b) > 1 else (b, 0)
|
|
69
60
|
|
|
70
|
-
path_a =
|
|
71
|
-
path_b =
|
|
61
|
+
path_a = sol_a[0]
|
|
62
|
+
path_b = sol_b[0]
|
|
63
|
+
|
|
64
|
+
sol_weight = sol_a[1] + sol_b[1]
|
|
72
65
|
|
|
73
66
|
terminals_a = (path_a[0], path_a[-1])
|
|
74
67
|
terminals_b = (path_b[0], path_b[-1])
|
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "PyQrackIsing"
|
|
14
|
-
version = "1.10.
|
|
14
|
+
version = "1.10.7"
|
|
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.10.
|
|
54
|
+
version='1.10.7',
|
|
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
|