PyQrackIsing 6.1.3__tar.gz → 6.2.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-6.1.3/pyqrackising.egg-info → pyqrackising-6.2.0}/PKG-INFO +1 -1
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyproject.toml +1 -1
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/__init__.py +1 -0
- pyqrackising-6.2.0/pyqrackising/convert_tensor_network_to_tsp.py +96 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising.egg-info/SOURCES.txt +1 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/setup.py +1 -1
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/CMakeLists.txt +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/LICENSE.md +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/MANIFEST.in +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/README.md +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-6.1.3 → pyqrackising-6.2.0}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "6.
|
|
15
|
+
version = "6.2.0"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
18
18
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -8,3 +8,4 @@ from .spin_glass_solver import spin_glass_solver
|
|
|
8
8
|
from .spin_glass_solver_sparse import spin_glass_solver_sparse
|
|
9
9
|
from .spin_glass_solver_streaming import spin_glass_solver_streaming
|
|
10
10
|
from .tsp import tsp_symmetric, tsp_asymmetric
|
|
11
|
+
from .convert_tensor_network_to_tsp import convert_tensor_network_to_tsp, convert_quimb_tree_to_tsp
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Provided by Elara, the custom OpenAI GPT
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
import itertools
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
def convert_tensor_network_to_tsp(tensors, index_dims, dtype=np.float32):
|
|
7
|
+
"""
|
|
8
|
+
Converts a tensor network to a symmetric TSP distance matrix based on pairwise contraction costs.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
tensors: List of dictionaries, each with keys:
|
|
12
|
+
- 'id': Unique tensor identifier (str)
|
|
13
|
+
- 'indices': Set of indices (Set[str])
|
|
14
|
+
index_dims: Dictionary mapping index name to its dimension (e.g., {'i': 2, 'j': 4})
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
A tuple containing:
|
|
18
|
+
- A normalized 2D numpy array representing the symmetric TSP distance matrix.
|
|
19
|
+
- A list of tensor IDs corresponding to the node order in the distance matrix.
|
|
20
|
+
"""
|
|
21
|
+
# Step 1: Build inverse map: index -> tensors using it
|
|
22
|
+
index_to_tensors = defaultdict(set)
|
|
23
|
+
for tensor in tensors:
|
|
24
|
+
for idx in tensor["indices"]:
|
|
25
|
+
index_to_tensors[idx].add(tensor["id"])
|
|
26
|
+
|
|
27
|
+
# Step 2: Build graph of neighboring tensors
|
|
28
|
+
graph = defaultdict(set)
|
|
29
|
+
for idx, tensor_ids in index_to_tensors.items():
|
|
30
|
+
for t1, t2 in itertools.combinations(tensor_ids, 2):
|
|
31
|
+
graph[t1].add(t2)
|
|
32
|
+
graph[t2].add(t1)
|
|
33
|
+
|
|
34
|
+
# Step 3: Estimate pairwise contraction costs
|
|
35
|
+
def estimate_cost(t1, t2):
|
|
36
|
+
common = t1["indices"] & t2["indices"]
|
|
37
|
+
if not common:
|
|
38
|
+
return float("inf")
|
|
39
|
+
all_indices = t1["indices"] | t2["indices"]
|
|
40
|
+
return sum(index_dims.get(i, 1) for i in all_indices)
|
|
41
|
+
|
|
42
|
+
max_cost = float("-inf")
|
|
43
|
+
edge_costs = {}
|
|
44
|
+
for t1, neighbors in graph.items():
|
|
45
|
+
for t2 in neighbors:
|
|
46
|
+
key = tuple(sorted([t1, t2]))
|
|
47
|
+
if key not in edge_costs:
|
|
48
|
+
t1_data = next(t for t in tensors if t["id"] == t1)
|
|
49
|
+
t2_data = next(t for t in tensors if t["id"] == t2)
|
|
50
|
+
cost = estimate_cost(t1_data, t2_data)
|
|
51
|
+
edge_costs[key] = cost
|
|
52
|
+
if (cost < float("inf")) and (cost > max_cost):
|
|
53
|
+
max_cost = cost
|
|
54
|
+
|
|
55
|
+
# Step 4: Build distance matrix
|
|
56
|
+
tensor_ids = [t["id"] for t in tensors]
|
|
57
|
+
id_to_node = {tid: i for i, tid in enumerate(tensor_ids)}
|
|
58
|
+
n = len(tensor_ids)
|
|
59
|
+
dist_matrix = np.full((n, n), 1e8, dtype=dtype)
|
|
60
|
+
|
|
61
|
+
for (t1, t2), cost in edge_costs.items():
|
|
62
|
+
if cost == float("inf"):
|
|
63
|
+
continue
|
|
64
|
+
i, j = id_to_node[t1], id_to_node[t2]
|
|
65
|
+
dist_matrix[i, j] = dist_matrix[j, i] = cost / max_cost
|
|
66
|
+
|
|
67
|
+
return dist_matrix, tensor_ids
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def convert_quimb_tree_to_tsp(tn, dtype=np.float32):
|
|
72
|
+
"""
|
|
73
|
+
Converts a quimb TensorNetwork to a TSP distance matrix for contraction optimization.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
tn: A quimb.tensor.TensorNetwork instance.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
- Normalized symmetric distance matrix (2D numpy array of floats)
|
|
80
|
+
- List of tensor IDs (tags) corresponding to the matrix order
|
|
81
|
+
"""
|
|
82
|
+
tensors = []
|
|
83
|
+
index_dims = {}
|
|
84
|
+
|
|
85
|
+
for tensor in tn.tensors:
|
|
86
|
+
# Use a unique tag or fallback to name
|
|
87
|
+
tensor_id = sorted(tensor.tags)[0] if tensor.tags else str(tensor.name)
|
|
88
|
+
tensors.append({
|
|
89
|
+
"id": tensor_id,
|
|
90
|
+
"indices": set(tensor.inds)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
for ind, dim in zip(tensor.inds, tensor.shape):
|
|
94
|
+
index_dims[ind] = dim # capture dimension size
|
|
95
|
+
|
|
96
|
+
return convert_tensor_network_to_tsp(tensors, index_dims, dtype)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='6.
|
|
54
|
+
version='6.2.0',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
57
|
description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal 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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|