Skip to main content

Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, and TeNPy 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 2d or 3d
  • works with multiple tensor-network ecosystems through one shared API
  • returns standard Matplotlib Figure and Axes objects for further customization
  • can also reconstruct and render tensor networks from traced binary einsum contractions

There is no custom UI layer. The package builds a normalized graph and draws it with Matplotlib.

Supported Engines

  • tensorkrowch
  • tensornetwork
  • quimb
  • tenpy
  • einsum

Documentation

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 collection
  • engine: which backend adapter to use
  • view: 2d or 3d
  • config: optional PlotConfig
  • show=False if 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 with nodes or leaf_nodes, or an iterable of nodes
  • tensornetwork: an iterable of tensornetwork.Node
  • quimb: a TensorNetwork or an iterable of Tensor
  • tenpy: finite, segment, or infinite MPS, and finite or infinite MPO
  • einsum: an EinsumTrace or an ordered iterable of pair_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 id
  • validate_positions=True: warn about unknown ids or wrong coordinate dimensions
  • layout_iterations: tune the force-directed fallback layout

Important Backend Notes

  • Quimb hyper-indices shared by more than two tensors are rendered through internal virtual hubs.
  • Infinite TeNPy MPS and MPO objects are drawn as one periodic unit cell.
  • The einsum backend 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensor_network_visualization-1.3.0.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensor_network_visualization-1.3.0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file tensor_network_visualization-1.3.0.tar.gz.

File metadata

File hashes

Hashes for tensor_network_visualization-1.3.0.tar.gz
Algorithm Hash digest
SHA256 64abef6a359ef9c48c28587389f072d0f4dd0320b4094b459845df8df6b4dd76
MD5 f592bb87044659f91593b3b7e3f12065
BLAKE2b-256 f9569a2b30401272f1fef071bee8b61bb6d830fed3d6837f987dae7b926e4359

See more details on using hashes here.

File details

Details for the file tensor_network_visualization-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tensor_network_visualization-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30a6f430ec588cd91054dccd5cbb7f9816a67e0e41480d21486f74d7f7b4a9a0
MD5 8465460f34d8a1c281c3922895ecb1bd
BLAKE2b-256 8476d489eb6e5f6c2fb37a170b35f50cecde25a45b735ebfcc4040990d847194

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page