Skip to main content

Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced PyTorch/NumPy einsum tensor networks.

Project description

Tensor-Network-Visualization

CI PyPI version Python versions License: MIT

Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced PyTorch/NumPy einsum tensor networks.

Why This Exists

Tensor-network libraries expose different Python objects. This package gives them a small shared visualization API so you can inspect structure, tensor values, contraction playback, and normalized graph exports without rewriting plotting code for every backend.

The common entry points are:

show_tensor_network(...)
show_tensor_elements(...)
show_tensor_comparison(...)
normalize_tensor_network(...)
export_tensor_network_snapshot(...)

Install

  • PyPI package name: tensor-network-visualization
  • Import package: tensor_network_viz
  • Requires Python 3.11 or newer.
python -m pip install tensor-network-visualization

The base install only depends on numpy, matplotlib, and networkx.

For interactive Jupyter figures:

python -m pip install "tensor-network-visualization[jupyter]"

For backend-specific packages, install the matching extra, for example:

python -m pip install "tensor-network-visualization[quimb]"

See docs/installation.md for virtual environments, all optional extras, and local development installs.

Basic Usage

NumPy einsum trace (base install)

This example uses only base dependencies and a NumPy-backed EinsumTrace.

import numpy as np
from tensor_network_viz import EinsumTrace, PlotConfig, einsum, show_tensor_network

trace = EinsumTrace()
a = np.ones((2, 3), dtype=float)
x = np.array([1.0, -0.5, 0.25], dtype=float)

trace.bind("A", a)
trace.bind("x", x)
einsum("ab,b->a", a, x, trace=trace, backend="numpy")

fig, ax = show_tensor_network(
    trace,
    config=PlotConfig(show_tensor_labels=True, hover_labels=True),
    show=False,
)
fig.savefig("einsum-network.png", bbox_inches="tight")

TensorKrowch

Install the TensorKrowch extra (see Installation for details):

python -m pip install "tensor-network-visualization[tensorkrowch]"
import tensorkrowch as tk
from tensor_network_viz import PlotConfig, show_tensor_network

network = tk.TensorNetwork(name="demo")
left = tk.Node(shape=(2, 2), axes_names=("a", "b"), name="L", network=network)
right = tk.Node(shape=(2, 2), axes_names=("b", "c"), name="R", network=network)
left["b"] ^ right["b"]

fig, ax = show_tensor_network(
    network,
    config=PlotConfig(show_tensor_labels=True, show_index_labels=False),
    show=False,
)
fig.savefig("tensorkrowch-network.png", bbox_inches="tight")

Use show=False when you want to save or customize the figure yourself. Use show_controls=False when you want a clean static figure with no embedded Matplotlib controls.

In a notebook, use this exact recipe:

%pip install "tensor-network-visualization[jupyter]"

If you just installed that extra in the current kernel, restart the kernel once. Then, in the first plotting cell:

%matplotlib widget

from tensor_network_viz import PlotConfig, show_tensor_network

fig, ax = show_tensor_network(
    network,
    config=PlotConfig(show_tensor_labels=True, hover_labels=True),
)

See Installation and User Guide for details.

Documentation

  • Installation: virtual environments, optional extras, Jupyter, and local editable installs.
  • API Reference: public functions, configuration objects, snapshots, exceptions, and logging.
  • User Guide: workflows, notebooks, exports, layouts, tensor inspection, comparisons, snapshots, and performance tips.
  • Layout Algorithms: node placement and free-edge direction rules in 2D and 3D.
  • Backend Examples: copy-paste examples for TensorKrowch, TensorNetwork, Quimb, TeNPy, and einsum.
  • Troubleshooting: common install, Jupyter, Matplotlib, backend, and data issues.
  • Repository Examples: command-line demo launcher and example catalog.
  • Demo Commands: copy-paste commands for every repository demo.

Demo Gallery

The repository examples are organized around the same launcher:

python examples/run_demo.py <group> <demo>

The gallery includes backend demos for TensorKrowch, TensorNetwork, Quimb, TeNPy, and einsum, plus three focused groups:

  • themes overview: compares default, paper, and colorblind visual modes.
  • placements: shows object, list, 2D grid, 3D grid, manual positions, manual schemes, and named index inputs.
  • geometry: renders larger irregular, incomplete, triangular, pyramidal, circular, and disconnected networks.

For batch checks, use:

python examples/run_all_examples.py --group engines --views 2d --list
python examples/run_all_examples.py --group all --views 2d --output-dir .tmp/examples

Project Links

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.6.3.tar.gz (324.6 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.6.3-py3-none-any.whl (265.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tensor_network_visualization-1.6.3.tar.gz
Algorithm Hash digest
SHA256 a1f88f7bd1fd54ffb98fe74d25d82b4ef869464163b7dccee285e8bfda4cab6a
MD5 70bba7c04a5fecdd1993408757408d72
BLAKE2b-256 6a90f9a2383fb8957070ec96968ed4afe93c1932352905fed31a04c629611ff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensor_network_visualization-1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d57c452f40c1acb169b97d422f7718ccecaea49f9b4d89e663d25e93fd9f868a
MD5 6bc519b37b2b0c71c1b2c99728d7ebce
BLAKE2b-256 a3b82ba463bc19664ed49d101d72396586ddc2dcc816856895dbaabdade5d986

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