PyQrackIsing 1.9.0__tar.gz → 1.10.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.9.0/PyQrackIsing.egg-info → pyqrackising-1.10.3}/PKG-INFO +1 -1
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/_pyqrack_ising.cpp +1 -9
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/maxcut_tfim.py +4 -1
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/spin_glass_solver.py +2 -2
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/tsp_symmetric.py +13 -8
- {pyqrackising-1.9.0 → pyqrackising-1.10.3/PyQrackIsing.egg-info}/PKG-INFO +1 -1
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/README.md +2 -2
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/pyproject.toml +1 -1
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/setup.py +1 -1
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/CMakeLists.txt +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/LICENSE.md +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/MANIFEST.in +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/__init__.py +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/generate_tfim_samples.py +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/tfim_magnetization.py +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing.egg-info/not-zip-safe +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/PyQrackIsing.egg-info/top_level.txt +0 -0
- {pyqrackising-1.9.0 → pyqrackising-1.10.3}/setup.cfg +0 -0
|
@@ -73,15 +73,7 @@ static inline std::string int_to_bitstring(BigInteger integer, size_t length) {
|
|
|
73
73
|
return s;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
std::vector<double> maxcut_hamming_cdf(
|
|
77
|
-
py::array_t<double, py::array::c_style | py::array::forcecast> _J_func,
|
|
78
|
-
py::array_t<double, py::array::c_style | py::array::forcecast> _degrees,
|
|
79
|
-
int mult_log2
|
|
80
|
-
) {
|
|
81
|
-
auto bufj = _J_func.request();
|
|
82
|
-
size_t n_qubits = bufj.shape[0];
|
|
83
|
-
double* J_func = static_cast<double*>(bufj.ptr);
|
|
84
|
-
double* degrees = static_cast<double*>(_degrees.request().ptr);
|
|
76
|
+
std::vector<double> maxcut_hamming_cdf(size_t n_qubits, std::vector<double> J_func, std::vector<double> degrees, int mult_log2) {
|
|
85
77
|
const int n_steps = n_qubits << mult_log2;
|
|
86
78
|
const int shots = n_qubits << mult_log2;
|
|
87
79
|
const double delta_t = 1.0 / (n_steps << (mult_log2 >> 1));
|
|
@@ -92,7 +92,7 @@ def maxcut_tfim(
|
|
|
92
92
|
|
|
93
93
|
J_eff = np.array([-sum(edge_attributes.get('weight', 1.0) for _, edge_attributes in G.adj[n].items()) for n in nodes], dtype=np.float64)
|
|
94
94
|
degrees = np.array([sum(abs(edge_attributes.get('weight', 1.0)) for _, edge_attributes in G.adj[n].items()) for n in nodes], dtype=np.float64)
|
|
95
|
-
thresholds = tfim_sampler._maxcut_hamming_cdf(J_eff, degrees, quality)
|
|
95
|
+
thresholds = tfim_sampler._maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality)
|
|
96
96
|
G_dict = nx.to_dict_of_lists(G)
|
|
97
97
|
J_max = max(J_eff)
|
|
98
98
|
weights = 1.0 / (1.0 + (J_max - J_eff))
|
|
@@ -107,6 +107,9 @@ def maxcut_tfim(
|
|
|
107
107
|
# Second dimension: permutation within Hamming weight
|
|
108
108
|
samples.append(local_repulsion_choice(nodes, G_dict, degrees, weights, n_qubits, m))
|
|
109
109
|
|
|
110
|
+
# We only need unique instances
|
|
111
|
+
samples = list(set(samples))
|
|
112
|
+
|
|
110
113
|
edge_keys = []
|
|
111
114
|
edge_values = []
|
|
112
115
|
for u, v, data in G.edges(data=True):
|
|
@@ -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=1, best_guess=None):
|
|
60
60
|
bitstring = ''
|
|
61
61
|
if isinstance(best_guess, str):
|
|
62
62
|
bitstring = best_guess
|
|
@@ -65,7 +65,7 @@ def spin_glass_solver(G, quality=2, best_guess=None):
|
|
|
65
65
|
elif isinstance(best_guess, list):
|
|
66
66
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
67
67
|
else:
|
|
68
|
-
bitstring, _, _ = maxcut_tfim(G, quality=0)
|
|
68
|
+
bitstring, _, _ = maxcut_tfim(G, quality=max(0, quality - 1))
|
|
69
69
|
best_theta = [ b == '1' for b in list(bitstring)]
|
|
70
70
|
nodes = list(G.nodes())
|
|
71
71
|
n_qubits = len(nodes)
|
|
@@ -20,7 +20,7 @@ def get_best_stitch(adjacency, terminals_a, terminals_b, is_cyclic):
|
|
|
20
20
|
return best_weight, best_edge
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def tsp_symmetric(G, quality=2, is_cyclic=True):
|
|
23
|
+
def tsp_symmetric(G, quality=2, is_cyclic=True, start_node=None):
|
|
24
24
|
if G.number_of_nodes() == 1:
|
|
25
25
|
return ([0], 0)
|
|
26
26
|
if G.number_of_nodes() == 2:
|
|
@@ -30,13 +30,18 @@ def tsp_symmetric(G, quality=2, is_cyclic=True):
|
|
|
30
30
|
|
|
31
31
|
a = []
|
|
32
32
|
b = []
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
if not (start_node is None):
|
|
34
|
+
a = [start_node]
|
|
35
|
+
b = nodes
|
|
36
|
+
b.remove(start_node)
|
|
37
|
+
else:
|
|
38
|
+
while (len(a) == 0) or (len(b) == 0):
|
|
39
|
+
bitstring, _, _, _ = spin_glass_solver(G, quality=quality)
|
|
40
|
+
for idx, bit in enumerate(bitstring):
|
|
41
|
+
if bit == '1':
|
|
42
|
+
b.append(nodes[idx])
|
|
43
|
+
else:
|
|
44
|
+
a.append(nodes[idx])
|
|
40
45
|
|
|
41
46
|
G_a = nx.Graph()
|
|
42
47
|
G_b = nx.Graph()
|
|
@@ -93,13 +93,13 @@ 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=2, is_cyclic=True)
|
|
96
|
+
circuit, path_length = tsp_symmetric(G, quality=2, is_cyclic=True, start_node=None)
|
|
97
97
|
|
|
98
98
|
print(f"Node count: {n_nodes}")
|
|
99
99
|
print(f"Path: {circuit}")
|
|
100
100
|
print(f"Path length: {path_length}")
|
|
101
101
|
```
|
|
102
|
-
We only provide a solver for the symmetric version of the TSP (i.e., the distance from "A" to "B" is considered the same as from "B" to "A"). `is_cyclic` controls whether the path must ultimately complete a circuit, if `True`, or a one-way trip, if `False`.
|
|
102
|
+
We only provide a solver for the symmetric version of the TSP (i.e., the distance from "A" to "B" is considered the same as from "B" to "A"). `is_cyclic` controls whether the path must ultimately complete a circuit, if `True`, or a one-way trip, if `False`. When the desired route is acyclic, a fixed starting point can optionally be specified via passing the node label to `start_node` (or, without this parameter, the solver will also attempt to pick an optimal starting point).
|
|
103
103
|
|
|
104
104
|
## About
|
|
105
105
|
Transverse field Ising model (TFIM) is the basis of most claimed algorithmic "quantum advantage," circa 2025, with the notable exception of Shor's integer factoring algorithm.
|
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "PyQrackIsing"
|
|
14
|
-
version = "1.
|
|
14
|
+
version = "1.10.3"
|
|
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.10.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
|