tensor-network-visualization 1.3.3__tar.gz → 1.4.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.
- tensor_network_visualization-1.4.1/PKG-INFO +390 -0
- tensor_network_visualization-1.4.1/README.md +343 -0
- tensor_network_visualization-1.4.1/pyproject.toml +68 -0
- tensor_network_visualization-1.4.1/src/tensor_network_visualization.egg-info/PKG-INFO +390 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_visualization.egg-info/SOURCES.txt +31 -3
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_visualization.egg-info/requires.txt +7 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/__init__.py +26 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/_draw_common.py +6 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/_label_format.py +195 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/contractions.py +53 -13
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/__init__.py +46 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/constants.py +135 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/disk_metrics.py +73 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/edges.py +697 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/fonts_and_scale.py +182 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/graph_pipeline.py +251 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/hover.py +250 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/labels_misc.py +154 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/pick_distance.py +82 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/plotter.py +285 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/tensors.py +198 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/vectors.py +33 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/draw/viewport_geometry.py +693 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/graph.py +22 -3
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/graph_cache.py +101 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/layout/__init__.py +17 -0
- tensor_network_visualization-1.3.3/src/tensor_network_viz/_core/layout.py → tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/layout/body.py +1108 -830
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/layout/force_directed.py +225 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/layout/parameters.py +44 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/layout/types.py +13 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/layout_structure.py +506 -423
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_core/renderer.py +444 -0
- tensor_network_visualization-1.4.1/src/tensor_network_viz/_engine_specs.py +35 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_registry.py +2 -30
- tensor_network_visualization-1.4.1/src/tensor_network_viz/config.py +89 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/quimb/graph.py +35 -26
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/viewer.py +31 -8
- tensor_network_visualization-1.4.1/tests/test_contraction_groups_once.py +75 -0
- tensor_network_visualization-1.4.1/tests/test_draw_performance.py +139 -0
- tensor_network_visualization-1.4.1/tests/test_edge_index_label_2d.py +80 -0
- tensor_network_visualization-1.4.1/tests/test_edge_index_label_3d.py +58 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_einsum_backend.py +13 -2
- tensor_network_visualization-1.4.1/tests/test_graph_cache.py +65 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_integration_quimb.py +3 -1
- tensor_network_visualization-1.4.1/tests/test_label_draw_metrics_perf.py +94 -0
- tensor_network_visualization-1.4.1/tests/test_label_format.py +60 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_layout_core.py +780 -469
- tensor_network_visualization-1.4.1/tests/test_node_degrees_perf.py +73 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_plotting.py +136 -10
- tensor_network_visualization-1.4.1/tests/test_public_api.py +183 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_quimb_backend.py +11 -4
- tensor_network_visualization-1.4.1/tests/test_show_tensor_network_throughput.py +120 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_tenpy_backend.py +42 -9
- tensor_network_visualization-1.3.3/PKG-INFO +0 -223
- tensor_network_visualization-1.3.3/README.md +0 -186
- tensor_network_visualization-1.3.3/pyproject.toml +0 -54
- tensor_network_visualization-1.3.3/src/tensor_network_visualization.egg-info/PKG-INFO +0 -223
- tensor_network_visualization-1.3.3/src/tensor_network_viz/__init__.py +0 -19
- tensor_network_visualization-1.3.3/src/tensor_network_viz/_core/_draw_common.py +0 -397
- tensor_network_visualization-1.3.3/src/tensor_network_viz/_core/draw_2d.py +0 -36
- tensor_network_visualization-1.3.3/src/tensor_network_viz/_core/draw_3d.py +0 -36
- tensor_network_visualization-1.3.3/src/tensor_network_viz/_core/renderer.py +0 -246
- tensor_network_visualization-1.3.3/src/tensor_network_viz/config.py +0 -63
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/LICENSE +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/setup.cfg +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_visualization.egg-info/dependency_links.txt +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_visualization.egg-info/top_level.txt +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/_nodes_edges_common.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/axis_directions.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/curves.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/_core/graph_utils.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/_backend.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/_equation.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/_trace_state.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/_trace_types.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/graph.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/renderer.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/einsum_module/trace.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/py.typed +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/quimb/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/quimb/renderer.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tenpy/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tenpy/graph.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tenpy/renderer.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensorkrowch/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensorkrowch/graph.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensorkrowch/renderer.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensornetwork/__init__.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensornetwork/graph.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/src/tensor_network_viz/tensornetwork/renderer.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_einsum_autotrace.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_examples.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_integration_einsum.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_integration_tenpy.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_integration_tensorkrowch.py +0 -0
- {tensor_network_visualization-1.3.3 → tensor_network_visualization-1.4.1}/tests/test_integration_tensornetwork.py +0 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tensor-network-visualization
|
|
3
|
+
Version: 1.4.1
|
|
4
|
+
Summary: Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced PyTorch/NumPy einsum tensor networks.
|
|
5
|
+
Author: Alejandro Mata Ali
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization
|
|
8
|
+
Project-URL: Documentation, https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/blob/main/docs/guide.md
|
|
9
|
+
Project-URL: Changelog, https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Repository, https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization
|
|
11
|
+
Project-URL: Issues, https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/issues
|
|
12
|
+
Keywords: tensor-network,visualization,pytorch,numpy,tensorkrowch,tensornetwork,quimb,tenpy,einsum,quantum-inspired,matplotlib
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: matplotlib>=3.7
|
|
21
|
+
Requires-Dist: networkx>=3.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
|
+
Requires-Dist: pyright; extra == "dev"
|
|
26
|
+
Requires-Dist: ipython; extra == "dev"
|
|
27
|
+
Requires-Dist: tensorkrowch; extra == "dev"
|
|
28
|
+
Requires-Dist: tensornetwork; extra == "dev"
|
|
29
|
+
Requires-Dist: quimb; extra == "dev"
|
|
30
|
+
Requires-Dist: physics-tenpy; extra == "dev"
|
|
31
|
+
Provides-Extra: jupyter
|
|
32
|
+
Requires-Dist: ipympl>=0.9.0; extra == "jupyter"
|
|
33
|
+
Requires-Dist: ipywidgets>=8.0; extra == "jupyter"
|
|
34
|
+
Requires-Dist: jupyterlab>=4.0; extra == "jupyter"
|
|
35
|
+
Requires-Dist: notebook>=7.0; extra == "jupyter"
|
|
36
|
+
Provides-Extra: tensorkrowch
|
|
37
|
+
Requires-Dist: tensorkrowch; extra == "tensorkrowch"
|
|
38
|
+
Provides-Extra: tensornetwork
|
|
39
|
+
Requires-Dist: tensornetwork; extra == "tensornetwork"
|
|
40
|
+
Provides-Extra: quimb
|
|
41
|
+
Requires-Dist: quimb; extra == "quimb"
|
|
42
|
+
Provides-Extra: tenpy
|
|
43
|
+
Requires-Dist: physics-tenpy; extra == "tenpy"
|
|
44
|
+
Provides-Extra: einsum
|
|
45
|
+
Requires-Dist: torch; extra == "einsum"
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# Tensor-Network-Visualization
|
|
49
|
+
|
|
50
|
+
[](https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/actions/workflows/ci.yml)
|
|
51
|
+
[](https://pypi.org/project/tensor-network-visualization/)
|
|
52
|
+
[](https://pypi.org/project/tensor-network-visualization/)
|
|
53
|
+
[](https://opensource.org/licenses/MIT)
|
|
54
|
+
|
|
55
|
+
Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced
|
|
56
|
+
PyTorch/NumPy `einsum` tensor networks.
|
|
57
|
+
|
|
58
|
+
**Repository:** [https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization](https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization)
|
|
59
|
+
|
|
60
|
+
## What this project does
|
|
61
|
+
|
|
62
|
+
Tensor network libraries use different object models and rarely share a single visualization path.
|
|
63
|
+
This package **normalizes** each backend into one graph description, **lays out** nodes (chains,
|
|
64
|
+
grids, trees, planar embeddings, or force-directed fallback), and **draws** with Matplotlib in
|
|
65
|
+
**2D** (filled disks) or **3D** (lightweight octahedra). There is no custom GUI: you get standard
|
|
66
|
+
`Figure` and `Axes` objects for saving, composing subplots, and further styling.
|
|
67
|
+
|
|
68
|
+
**Audience:** Researchers who work with tensor networks and want consistent, publication-friendly
|
|
69
|
+
diagrams across Quimb, TeNPy, TensorNetwork, TensorKrowch, or traced `einsum` contraction graphs.
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
PyPI package name: `tensor-network-visualization`. Import module: `tensor_network_viz`.
|
|
74
|
+
|
|
75
|
+
### Base install
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python -m pip install tensor-network-visualization
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Depends on `matplotlib` and `networkx` only. You can render **`einsum`** traces built from ordered
|
|
82
|
+
`pair_tensor` entries without installing PyTorch.
|
|
83
|
+
|
|
84
|
+
### Optional backends (extras)
|
|
85
|
+
|
|
86
|
+
| Backend | Pip extra | Notes |
|
|
87
|
+
|----------------|-------------------------------|--------|
|
|
88
|
+
| TensorKrowch | `tensorkrowch` | `pip install "tensor-network-visualization[tensorkrowch]"` |
|
|
89
|
+
| TensorNetwork | `tensornetwork` | `pip install "tensor-network-visualization[tensornetwork]"` |
|
|
90
|
+
| Quimb | `quimb` | `pip install "tensor-network-visualization[quimb]"` |
|
|
91
|
+
| TeNPy | `tenpy` | Resolves to PyPI package **`physics-tenpy`**. |
|
|
92
|
+
| Einsum tracing | `einsum` | Adds **PyTorch** for the traced `einsum` helper. |
|
|
93
|
+
| Jupyter widgets| `jupyter` | `ipympl`, widgets, JupyterLab / Notebook 7+ for interactive figures. |
|
|
94
|
+
|
|
95
|
+
Combine extras, for example:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python -m pip install "tensor-network-visualization[quimb,jupyter]"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Windows and Linux quick setup
|
|
102
|
+
|
|
103
|
+
From the project root (development) or any environment (end users):
|
|
104
|
+
|
|
105
|
+
**Windows (PowerShell):**
|
|
106
|
+
|
|
107
|
+
```powershell
|
|
108
|
+
python -m venv .venv
|
|
109
|
+
.\.venv\Scripts\Activate.ps1
|
|
110
|
+
python -m pip install -U pip
|
|
111
|
+
python -m pip install "tensor-network-visualization[quimb]"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Linux / macOS:**
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python3 -m venv .venv
|
|
118
|
+
source .venv/bin/activate
|
|
119
|
+
python -m pip install -U pip
|
|
120
|
+
python -m pip install "tensor-network-visualization[quimb]"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Editable install for contributors:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
python -m pip install -e ".[dev]"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Jupyter and interactive figures
|
|
130
|
+
|
|
131
|
+
For pan, zoom, and (with `%matplotlib widget`) smoother interaction, install the **`jupyter`**
|
|
132
|
+
extra and select the ipympl backend **before** creating figures.
|
|
133
|
+
|
|
134
|
+
For **interactive** figures (e.g. rotatable 3D), install `[jupyter]` (`ipympl`, `ipywidgets`,
|
|
135
|
+
JupyterLab, and classic Jupyter Notebook 7+) and run **`jupyter notebook`** or **`jupyter lab`** in
|
|
136
|
+
the **browser**. The **Cursor / VS Code notebook tab** may not load the full widget stack; if
|
|
137
|
+
figures fail to show, use **`%matplotlib inline`** or set **`MPLBACKEND=inline`** before importing
|
|
138
|
+
`pyplot`, or open the same notebook in the browser with a normal Jupyter install.
|
|
139
|
+
|
|
140
|
+
## Modes and API knobs
|
|
141
|
+
|
|
142
|
+
Everything below maps to real parameters—there are no hidden mode switches.
|
|
143
|
+
|
|
144
|
+
| Concept | Where | Meaning |
|
|
145
|
+
|--------|--------|---------|
|
|
146
|
+
| **View mode** | `show_tensor_network(..., view=...)` | `"2d"` — disk nodes; `"3d"` — octahedra. Same normalized graph. |
|
|
147
|
+
| **Engine mode** | `engine=...` | Adapter: `"tensorkrowch"`, `"tensornetwork"`, `"quimb"`, `"tenpy"`, `"einsum"`. Invalid → `ValueError`. |
|
|
148
|
+
| **Display mode** | `show=True` / `False` | If `True`: Jupyter **kernel** uses `IPython.display.display(fig)`; otherwise `plt.show()`. If `False`: neither runs—use for `savefig` / batch. |
|
|
149
|
+
| **Label policy** | `PlotConfig` + overrides | Defaults: `show_tensor_labels`, `show_index_labels`. Per-call: `show_tensor_network(..., show_tensor_labels=..., show_index_labels=...)`. |
|
|
150
|
+
| **Hover labels** | `PlotConfig(hover_labels=True)` | Tensor names and bond labels appear on pointer hover (2D axes hit-test; 3D screen-space distance). Needs an **interactive** Matplotlib window. |
|
|
151
|
+
| **Einsum workflow** | `engine="einsum"` | **Auto:** `EinsumTrace` + `tensor_network_viz.einsum`. **Manual:** ordered list of `pair_tensor(...)`. |
|
|
152
|
+
|
|
153
|
+
## Minimal examples
|
|
154
|
+
|
|
155
|
+
### Quimb 2D, save to PNG
|
|
156
|
+
|
|
157
|
+
After `python -m pip install "tensor-network-visualization[quimb]"`:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
import numpy as np
|
|
161
|
+
import quimb.tensor as qtn
|
|
162
|
+
from tensor_network_viz import PlotConfig, show_tensor_network
|
|
163
|
+
|
|
164
|
+
tensors = []
|
|
165
|
+
for i in range(3):
|
|
166
|
+
inds = ([f"b{i-1}_{i}"] if i > 0 else []) + [f"p{i}"] + ([f"b{i}_{i+1}"] if i < 2 else [])
|
|
167
|
+
shape = tuple(2 for _ in inds)
|
|
168
|
+
tensors.append(qtn.Tensor(np.ones(shape), inds=inds, tags=(f"A{i}",)))
|
|
169
|
+
network = qtn.TensorNetwork(tensors)
|
|
170
|
+
|
|
171
|
+
fig, ax = show_tensor_network(
|
|
172
|
+
network,
|
|
173
|
+
engine="quimb",
|
|
174
|
+
view="2d",
|
|
175
|
+
config=PlotConfig(figsize=(8, 6)),
|
|
176
|
+
show=False,
|
|
177
|
+
)
|
|
178
|
+
fig.savefig("network.png", bbox_inches="tight")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Quimb 3D, hide index labels on this call only
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
fig, ax = show_tensor_network(
|
|
185
|
+
network,
|
|
186
|
+
engine="quimb",
|
|
187
|
+
view="3d",
|
|
188
|
+
config=PlotConfig(figsize=(9, 7)),
|
|
189
|
+
show_index_labels=False,
|
|
190
|
+
show=False,
|
|
191
|
+
)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Hover labels (interactive session only)
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
fig, ax = show_tensor_network(
|
|
198
|
+
network,
|
|
199
|
+
engine="quimb",
|
|
200
|
+
view="2d",
|
|
201
|
+
config=PlotConfig(figsize=(8, 6), hover_labels=True),
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
No effect for headless `show=False` without a GUI event loop; pair with an interactive backend
|
|
206
|
+
(e.g. `%matplotlib widget` in Jupyter).
|
|
207
|
+
|
|
208
|
+
### TeNPy finite MPS (sketch)
|
|
209
|
+
|
|
210
|
+
Requires `python -m pip install "tensor-network-visualization[tenpy]"`. See the
|
|
211
|
+
[extended guide](docs/guide.md) for exact `MPS` construction; the call shape is always:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from tensor_network_viz import show_tensor_network, PlotConfig
|
|
215
|
+
|
|
216
|
+
fig, ax = show_tensor_network(
|
|
217
|
+
mps,
|
|
218
|
+
engine="tenpy",
|
|
219
|
+
view="2d",
|
|
220
|
+
config=PlotConfig(figsize=(8, 6)),
|
|
221
|
+
show=False,
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### `show_tensor_network` reference
|
|
226
|
+
|
|
227
|
+
```text
|
|
228
|
+
show_tensor_network(
|
|
229
|
+
network,
|
|
230
|
+
*,
|
|
231
|
+
engine: EngineName,
|
|
232
|
+
view: ViewName,
|
|
233
|
+
config: PlotConfig | None = None,
|
|
234
|
+
show_tensor_labels: bool | None = None,
|
|
235
|
+
show_index_labels: bool | None = None,
|
|
236
|
+
show: bool = True,
|
|
237
|
+
) -> tuple[Figure, Axes | Axes3D]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
- **`network`:** Backend-native object or iterable (see [guide — supported inputs](docs/guide.md)).
|
|
241
|
+
- **`engine`:** `"tensorkrowch"` \| `"tensornetwork"` \| `"quimb"` \| `"tenpy"` \| `"einsum"`.
|
|
242
|
+
- **`view`:** `"2d"` \| `"3d"`.
|
|
243
|
+
- **`config`:** Styling and layout; defaults to `PlotConfig()` if omitted.
|
|
244
|
+
- **`show_tensor_labels` / `show_index_labels`:** If `None`, use values from `config`; else override for this call only.
|
|
245
|
+
- **`show`:** Whether to push the figure to the current UI (`display`/`show`).
|
|
246
|
+
- **Returns:** `(fig, ax)` for titles, `savefig`, colorbars, or embedding in a subplot.
|
|
247
|
+
|
|
248
|
+
Backend-specific shortcuts (same renderer core) accept **`ax=`** and **`seed=`** for subplots and
|
|
249
|
+
reproducible layout; see the [guide](docs/guide.md).
|
|
250
|
+
|
|
251
|
+
### `PlotConfig` quick reference
|
|
252
|
+
|
|
253
|
+
Frozen dataclass; all fields optional beyond defaults. Values shown are **constructor defaults**.
|
|
254
|
+
Numeric fields with **`None`** use the corresponding `DEFAULT_*` on the class (see table footnote).
|
|
255
|
+
|
|
256
|
+
| Field | Default | Role |
|
|
257
|
+
|-------|---------|------|
|
|
258
|
+
| `node_color` | `"#E8E8E8"` | Tensor node fill. |
|
|
259
|
+
| `node_edge_color` | `"#2D3748"` | Tensor node outline. |
|
|
260
|
+
| `node_color_degree_one` | `"#E8D6D6"` | Fill for tensors with total graph degree 1. |
|
|
261
|
+
| `node_edge_color_degree_one` | `"#4A3436"` | Outline for degree-1 tensors. |
|
|
262
|
+
| `tensor_label_color` | `"#1A202C"` | Tensor name text. |
|
|
263
|
+
| `label_color` | `"#0C1319"` | Index / bond label text. |
|
|
264
|
+
| `bond_edge_color` | `"#00008B"` | Contraction edges. |
|
|
265
|
+
| `dangling_edge_color` | `"#8B0000"` | Dangling (open) legs. |
|
|
266
|
+
| `figsize` | `(8, 6)` | `inches`; `None` uses Matplotlib fallback `(14, 10)` when the renderer creates a new figure. |
|
|
267
|
+
| `show_tensor_labels` | `True` | Draw tensor names on nodes. |
|
|
268
|
+
| `show_index_labels` | `True` | Draw axis names on bonds / stubs. |
|
|
269
|
+
| `node_radius` | `None` | → `0.08` data units (scaled with layout; multiplies geometric radius). |
|
|
270
|
+
| `stub_length` | `None` | → `0.16` (dangling stub length scale). |
|
|
271
|
+
| `self_loop_radius` | `None` | → `0.2` (self-contraction loops). |
|
|
272
|
+
| `line_width_2d` | `None` | → `0.85` |
|
|
273
|
+
| `line_width_3d` | `None` | → `0.75` |
|
|
274
|
+
| `layout_iterations` | `None` | → automatic: `int(min(220, max(45, 14*√n)))` with `n = max(n_nodes, 1)` when unset; explicit int always wins. |
|
|
275
|
+
| `positions` | `None` | `dict[int, tuple[float, ...]]` — custom positions keyed by **normalized node id** (`id` of adapter node); partial dicts get layout for missing ids. |
|
|
276
|
+
| `validate_positions` | `False` | If `True`, warn on unknown keys or short coordinates vs `view`. |
|
|
277
|
+
| `refine_tensor_labels` | `True` | Extra passes to fit tensor names inside the node marker (2D or 3D); set `False` for speed. |
|
|
278
|
+
| `hover_labels` | `False` | Hide labels until hover (interactive only). |
|
|
279
|
+
|
|
280
|
+
Defaults `0.08`, `0.16`, `0.2`, `0.85`, `0.75`, `220` are also available as
|
|
281
|
+
`PlotConfig.DEFAULT_NODE_RADIUS`, `DEFAULT_STUB_LENGTH`, `DEFAULT_SELF_LOOP_RADIUS`,
|
|
282
|
+
`DEFAULT_LINE_WIDTH_2D`, `DEFAULT_LINE_WIDTH_3D`, `DEFAULT_LAYOUT_ITERATIONS`.
|
|
283
|
+
|
|
284
|
+
## Public Python API
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from tensor_network_viz import (
|
|
288
|
+
EngineName,
|
|
289
|
+
EinsumTrace,
|
|
290
|
+
PlotConfig,
|
|
291
|
+
ViewName,
|
|
292
|
+
einsum,
|
|
293
|
+
pair_tensor,
|
|
294
|
+
show_tensor_network,
|
|
295
|
+
)
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Per-backend plotters (optional; same as `show_tensor_network` internals):
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
from tensor_network_viz.tensorkrowch import plot_tensorkrowch_network_2d, plot_tensorkrowch_network_3d
|
|
302
|
+
from tensor_network_viz.tensornetwork import plot_tensornetwork_network_2d, plot_tensornetwork_network_3d
|
|
303
|
+
from tensor_network_viz.quimb import plot_quimb_network_2d, plot_quimb_network_3d
|
|
304
|
+
from tensor_network_viz.tenpy import plot_tenpy_network_2d, plot_tenpy_network_3d
|
|
305
|
+
from tensor_network_viz.einsum_module import plot_einsum_network_2d, plot_einsum_network_3d
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Accepted inputs (summary)
|
|
309
|
+
|
|
310
|
+
| Backend | Input |
|
|
311
|
+
|---------|--------|
|
|
312
|
+
| tensorkrowch | Network with `nodes` / `leaf_nodes`, or iterable of nodes |
|
|
313
|
+
| tensornetwork | Iterable of `tensornetwork.Node` |
|
|
314
|
+
| quimb | `TensorNetwork` or iterable of `Tensor` |
|
|
315
|
+
| tenpy | Finite/segment/infinite `MPS`, finite/infinite `MPO` |
|
|
316
|
+
| einsum | `EinsumTrace` or ordered iterable of `pair_tensor` |
|
|
317
|
+
|
|
318
|
+
Details, subgraph behavior, and Quimb hyperindex hubs are in **[docs/guide.md](docs/guide.md)**.
|
|
319
|
+
|
|
320
|
+
## Example scripts
|
|
321
|
+
|
|
322
|
+
Runnable demos live under **`examples/`**. From the repo root with the right extra installed:
|
|
323
|
+
|
|
324
|
+
| Script | Purpose |
|
|
325
|
+
|--------|---------|
|
|
326
|
+
| `demo_cli.py` | Shared helpers (`--hover-labels` → `PlotConfig(hover_labels=True)`); imported by demos. |
|
|
327
|
+
| `tensorkrowch_demo.py` | MPS, MPO, PEPS, weird, disconnected; `--from-list` subset. |
|
|
328
|
+
| `tensornetwork_demo.py` | Same topologies with `tensornetwork.Node`. |
|
|
329
|
+
| `mera_tree_demo.py` | Large MERA + binary TTN stress test. |
|
|
330
|
+
| `cubic_peps_demo.py` | 3D cubic PEPS lattice. |
|
|
331
|
+
| `quimb_demo.py` | Includes hyper-index example; `--from-list`. |
|
|
332
|
+
| `tenpy_demo.py` | Finite and infinite MPS/MPO. |
|
|
333
|
+
| `einsum_demo.py` | Auto trace vs manual `pair_tensor`. |
|
|
334
|
+
| `tn_tsp.py` | Larger TensorKrowch TSP construction. |
|
|
335
|
+
|
|
336
|
+
Catalog and one-liner commands: **[examples/README.md](examples/README.md)**.
|
|
337
|
+
|
|
338
|
+
## Backend notes
|
|
339
|
+
|
|
340
|
+
- Quimb **hyper-indices** (three or more tensors) are drawn via internal virtual hubs.
|
|
341
|
+
- Infinite TeNPy **MPS/MPO** use one periodic unit cell.
|
|
342
|
+
- The **einsum** backend visualizes the **fundamental** tensor network, not each intermediate
|
|
343
|
+
contraction tensor.
|
|
344
|
+
- Passing a **subset** of nodes/tensors shows connections outside the subset as **dangling** legs.
|
|
345
|
+
|
|
346
|
+
## Quick verification (reviewers)
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
python -m pip install -e ".[quimb]"
|
|
350
|
+
python examples/quimb_demo.py mps 2d --save quimb_mps.png --no-show
|
|
351
|
+
python -m pytest
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Expect `quimb_mps.png` and all tests passing.
|
|
355
|
+
|
|
356
|
+
## Troubleshooting (short)
|
|
357
|
+
|
|
358
|
+
| Symptom | What to try |
|
|
359
|
+
|---------|-------------|
|
|
360
|
+
| `ModuleNotFoundError` for quimb, tenpy, torch, … | Install the matching extra, e.g. `"tensor-network-visualization[quimb]"`. |
|
|
361
|
+
| `ValueError: Unsupported tensor network engine` / `view` | Use only listed `engine` / `view` literals (see above). |
|
|
362
|
+
| Blank or double figure in Jupyter | Assign `fig, ax = show_tensor_network(...)`; avoid bare tuple as last line; try `%matplotlib widget` or inline. |
|
|
363
|
+
| Hover labels do nothing | Requires interactive backend and `show` path that runs a GUI or widget event loop; not for `--no-show` PNG only. |
|
|
364
|
+
| Huge graphs are slow | `PlotConfig(refine_tensor_labels=False)`; lower `layout_iterations` or pass `positions`. Force layout samples repulsion when node count is large (about 72+; see [guide](docs/guide.md#layout-and-draw-scale)). |
|
|
365
|
+
|
|
366
|
+
**Full troubleshooting:** [docs/guide.md — Troubleshooting](docs/guide.md#troubleshooting).
|
|
367
|
+
|
|
368
|
+
## Documentation index
|
|
369
|
+
|
|
370
|
+
- **[docs/guide.md](docs/guide.md)** — Installation, backends, `PlotConfig` recipes, layout/draw
|
|
371
|
+
behavior, architecture, **extended troubleshooting**.
|
|
372
|
+
- **[CHANGELOG.md](CHANGELOG.md)** — Release notes by version.
|
|
373
|
+
- **[examples/README.md](examples/README.md)** — CLI examples per script.
|
|
374
|
+
- **[THIRD_PARTY_LICENSES.md](THIRD_PARTY_LICENSES.md)**
|
|
375
|
+
|
|
376
|
+
## Support and contributing
|
|
377
|
+
|
|
378
|
+
- **Issues:** [GitHub Issues](https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/issues)
|
|
379
|
+
- **Contributing:** [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
380
|
+
- **Code of Conduct:** [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
|
|
381
|
+
|
|
382
|
+
## Development
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
python -m pip install -e ".[dev]"
|
|
386
|
+
ruff check .
|
|
387
|
+
ruff format .
|
|
388
|
+
pyright
|
|
389
|
+
pytest
|
|
390
|
+
```
|