Skip to main content

Minimal Matplotlib visualizations for TensorKrowch and TensorNetwork tensor networks.

Project description

Tensor-Network-Visualization

Minimal Matplotlib visualizations for TensorKrowch and TensorNetwork tensor networks.

Repository: https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization

Features

  • 2D and 3D plotting for TensorKrowch and TensorNetwork tensor networks
  • Tensors rendered as nodes
  • Contractions rendered as edges between tensors
  • Dangling indices rendered as labeled stubs
  • Self-contractions rendered as loops
  • No UI; uses Matplotlib for rendering and NetworkX for graph layouts

Installation

As a dependency

Add to your project's pyproject.toml:

[project]
dependencies = ["tensor-network-visualization>=0.1.0"]

Or install with pip:

pip install tensor-network-visualization

If you also want to visualize google/TensorNetwork nodes, install tensornetwork in your environment as well:

pip install tensornetwork

Local development

Inside the project virtual environment:

.\.venv\Scripts\python -m pip install -e ".[dev]"

For runtime-only (editable install without dev tools):

.\.venv\Scripts\python -m pip install -e .

Usage

Input formats

Supported inputs depend on the selected engine:

  • engine="tensorkrowch":
    • a TensorKrowch network object with nodes or leaf_nodes
    • any iterable of TensorKrowch nodes, e.g. [node1, node2, node3]
  • engine="tensornetwork":
    • any iterable of tensornetwork.Node, e.g. [node1, node2, node3] or {node1, node2}

Each node must have edges, axes_names or axis_names, and name. Each edge must have node1, node2, and name.

When passing a subset of nodes, edges to nodes outside the input collection are drawn as dangling legs. Disconnected components (for example nodes from different networks) are supported.

from tensor_network_viz import PlotConfig, show_tensor_network

config = PlotConfig(figsize=(8, 6))

# TensorKrowch network object
fig, ax = show_tensor_network(network, engine="tensorkrowch", view="2d", config=config)

# TensorKrowch node collection
fig, ax = show_tensor_network([node1, node2, node3], engine="tensorkrowch", view="2d", config=config)

# TensorNetwork node collection
fig, ax = show_tensor_network([node1, node2, node3], engine="tensornetwork", view="2d", config=config)

You can also use engine-specific helpers directly:

from tensor_network_viz.tensorkrowch import plot_tensorkrowch_network_2d, plot_tensorkrowch_network_3d
from tensor_network_viz.tensornetwork import plot_tensornetwork_network_2d, plot_tensornetwork_network_3d

plot_tensorkrowch_network_2d(network)   # or plot_tensorkrowch_network_2d([node1, node2, ...])
plot_tensorkrowch_network_3d(network)
plot_tensornetwork_network_2d([node1, node2, node3])
plot_tensornetwork_network_3d([node1, node2, node3])

Internal architecture

The public API is split by backend, but the render pipeline is now shared:

  • tensor_network_viz._core contains the normalized graph model, layout, curve geometry, drawing, and shared renderer.
  • tensor_network_viz.tensorkrowch contains the TensorKrowch adapter that converts TensorKrowch inputs into the shared graph model.
  • tensor_network_viz.tensornetwork contains the TensorNetwork adapter that converts TensorNetwork node collections into the shared graph model.

This means TensorKrowch and TensorNetwork are not converted into each other. Each backend normalizes its own input to the common _GraphData structure and the shared core handles the rest.

Project layout

  • examples/ - Demo scripts. Run python examples/tensorkrowch_demo.py mps 2d for TensorKrowch or python examples/tensornetwork_demo.py mps 2d for TensorNetwork.
  • scripts/ - Utility scripts (for example clean.py to remove caches and build artifacts).

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.2.0.tar.gz (18.0 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.2.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tensor_network_visualization-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5fb78e8312fb7e05152645ea5b11e336128d63d16121a99a58cd030f72a9a37c
MD5 3f677334d3d68a850e1ac43f49823d23
BLAKE2b-256 f00411c44b6112a923e4916f7276a0e6ea28bc23e110a051612c1b09a35fa36c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensor_network_visualization-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7836247a61f1c530fcd3b93bacef3655db3380c40d64e903b9b8d9d6c8ed8819
MD5 f4dca50f1719c385a49b8d17008239a7
BLAKE2b-256 9dd9be556c13c3823c30c4183dd67964ae4828455bdd1814832ff236e3dc047e

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