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