Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced PyTorch/NumPy einsum tensor networks.
Project description
Tensor-Network-Visualization
Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced
PyTorch/NumPy einsum tensor networks.
Repository: https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization
What It Does
- renders tensor networks in
2dor3d - works with multiple tensor-network ecosystems through one shared API
- returns standard Matplotlib
FigureandAxesobjects for further customization - can also reconstruct and render tensor networks from traced binary
einsumcontractions
There is no custom UI layer. The package builds a normalized graph and draws it with Matplotlib.
Supported Engines
tensorkrowchtensornetworkquimbtenpyeinsum
Documentation
- Extended guide:
docs/guide.md - Examples catalog:
examples/README.md - Third-party licenses:
THIRD_PARTY_LICENSES.md
Installation
As a dependency
The base package includes the shared rendering core. Install the extra that matches the backend you want to visualize:
pip install "tensor-network-visualization[tensorkrowch]"
pip install "tensor-network-visualization[tensornetwork]"
pip install "tensor-network-visualization[quimb]"
pip install "tensor-network-visualization[tenpy]"
pip install "tensor-network-visualization[einsum]"
[einsum] installs PyTorch for executing traced contractions. If you already have NumPy and only
need to render an existing trace, the base package is enough.
Local development
Inside the project virtual environment:
.\.venv\Scripts\python -m pip install -e ".[dev]"
Runtime-only editable install:
.\.venv\Scripts\python -m pip install -e .
The repository also keeps:
requirements.txt->-e .requirements.dev.txt->-e ".[dev]"
These are thin wrappers around the editable installs above.
Quick Start
from tensor_network_viz import PlotConfig, show_tensor_network
config = PlotConfig(figsize=(8, 6))
fig, ax = show_tensor_network(
network,
engine="tensorkrowch",
view="2d",
config=config,
show=False,
)
ax.set_title("My tensor network")
fig.savefig("network.png", bbox_inches="tight")
show_tensor_network(...) is the main dispatcher. You provide:
network: the backend-native object or node/tensor collectionengine: which backend adapter to useview:2dor3dconfig: optionalPlotConfigshow=Falseif you want to save or modify the figure before displaying it
The function returns (fig, ax).
Public API
From the root package:
from tensor_network_viz import (
EinsumTrace,
PlotConfig,
einsum,
pair_tensor,
show_tensor_network,
)
Engine-specific helpers are also available:
from tensor_network_viz.tensorkrowch import plot_tensorkrowch_network_2d
from tensor_network_viz.tensornetwork import plot_tensornetwork_network_3d
from tensor_network_viz.quimb import plot_quimb_network_2d
from tensor_network_viz.tenpy import plot_tenpy_network_3d
from tensor_network_viz.einsum_module import plot_einsum_network_2d
Accepted Inputs at a Glance
tensorkrowch: a network object withnodesorleaf_nodes, or an iterable of nodestensornetwork: an iterable oftensornetwork.Nodequimb: aTensorNetworkor an iterable ofTensortenpy: finite, segment, or infiniteMPS, and finite or infiniteMPOeinsum: anEinsumTraceor an ordered iterable ofpair_tensor
See the extended guide for backend-specific details and caveats.
Plot Configuration
PlotConfig controls figure size, colors, line widths, label visibility, scale parameters, custom
positions, and layout iterations.
from tensor_network_viz import PlotConfig
config = PlotConfig(
figsize=(10, 6),
show_tensor_labels=True,
show_index_labels=True,
layout_iterations=300,
)
Important options:
positions: custom node positions keyed by node idvalidate_positions=True: warn about unknown ids or wrong coordinate dimensionslayout_iterations: tune the force-directed fallback layout
Automatic layout now prefers structural embeddings before falling back to forces:
- linear backbones are drawn as straight chains
- regular 2D meshes are kept on regular lattices
- trees use a deterministic hierarchical layout
- 3D views start from a principal plane and only lift nodes when the planar embedding becomes ambiguous
- dangling legs and other free exits in 3D use deterministic orthogonal directions instead of radial spreading
Important Backend Notes
- Quimb hyper-indices shared by more than two tensors are rendered through internal virtual hubs.
- Infinite TeNPy
MPSandMPOobjects are drawn as one periodic unit cell. - The
einsumbackend reconstructs the network of fundamental tensors rather than plotting intermediate contraction results. - If you pass only a subset of nodes/tensors, connections to outside objects appear as dangling legs.
- Disconnected components are supported.
Examples
The repository includes runnable scripts for every backend plus an extra TensorKrowch TSP example.
See examples/README.md for commands and a short explanation of each script.
Development
.\.venv\Scripts\python -m ruff check .
.\.venv\Scripts\python -m pyright
.\.venv\Scripts\python -m pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tensor_network_visualization-1.3.3.tar.gz.
File metadata
- Download URL: tensor_network_visualization-1.3.3.tar.gz
- Upload date:
- Size: 45.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ded917710c9fa2c72c6f6852c8dfc10378030e7d1b83328ef6da43d17f87c860
|
|
| MD5 |
714aad340b270af2b604bafd7aed8a48
|
|
| BLAKE2b-256 |
568175a8f03f76e5749256650dc9bccf51f9b272733e38a1cc13569c9ad82d82
|
File details
Details for the file tensor_network_visualization-1.3.3-py3-none-any.whl.
File metadata
- Download URL: tensor_network_visualization-1.3.3-py3-none-any.whl
- Upload date:
- Size: 46.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ab7684d13ec69b2ec42ca3173fefd243077abf8d2ee80c8c3bc0be7580d9ea4
|
|
| MD5 |
a6b280b8d9f64e7d8b47aa37a9bd2ea0
|
|
| BLAKE2b-256 |
ed259169c8273fc7244dd7ea6b1d15909fd5744f09e45d6ff79e67d6e69120c3
|