Skip to main content

A visual debugging tool bridging quantum circuits and tensor network contraction paths.

Project description

tn-lens

tn-lens is an interactive visualizer that bridges the gap between quantum circuit geometry and tensor network contraction paths.

It maps abstract tensor math back to physical quantum operations, providing a split-screen interactive UI.

Features

  • A RAM slider filters the contraction tree, instantly highlighting intermediate tensors that exceed your hardware limits.
  • Clicking an overgrown tensor highlights the exact causal cone of quantum gates in the circuit that generated it.
  • Natively parses OpenQASM 2.0/3.0 strings, as well as qiskit.QuantumCircuit, cirq.Circuit, and pennylane.QuantumTape objects.
  • Automatically handles mid-circuit measurements (wire re-initialization) and safely wraps custom/exotic gates into generic multi-qubit bounding boxes.

Installation

Install the base package via pip:

pip install tn-lens

To use advanced hypergraph optimizers (highly recommended for circuits > 20 qubits), install the optimizers extra, which pulls in cotengra:

pip install tn-lens[optimizers]

Usage

tn-lens can be used directly from the terminal or imported as a Python library.

Command Line Interface (CLI)

You can analyze any standard OpenQASM file directly from your terminal:

tn-lens my_circuit.qasm --optimizer greedy --memory 16.0

CLI Arguments:

  • input_file: Path to the .qasm file.
  • -o, --output: Path to save the HTML visualization (default: tensor_network.html).
  • -O, --optimizer: Contraction path optimizer (greedy, optimal, auto).
  • -m, --memory: Initial RAM threshold in MB for the UI slider.
  • --no-browser: Prevents the browser from opening automatically.

Python API

You can inject tn-lens directly into your existing quantum workflows. The library uses duck-typing to automatically translate Qiskit, Cirq, or PennyLane objects.

from qiskit import QuantumCircuit
from tn_lens.circuit import QASMParser
from tn_lens.analyzer import analyze_tensors
from tn_lens.renderer import render_graph

# 1. Define your circuit in your preferred framework
qc = QuantumCircuit(10)
for i in range(10):
    qc.h(i)
for i in range(9):
    qc.cx(i, i+1)

# 2. Parse into tensor inputs
parser = QASMParser()
inputs, output, shapes, gate_info = parser.parse(qc)
circuit_svg = parser.generate_svg(gate_info)

# 3. Analyze contraction path
nodes, edges, path, info = analyze_tensors(
    inputs, output, shapes, optimizer='auto'
)

# 4. Render the interactive UI
render_graph(
    nodes, edges, 
    circuit_svg=circuit_svg, 
    memory_limit_mb=10.0, 
    output_html="analysis.html"
)

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

tn_lens-1.0.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

tn_lens-1.0.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file tn_lens-1.0.0.tar.gz.

File metadata

  • Download URL: tn_lens-1.0.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tn_lens-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ded5a96003e63befb40a7aa651cdd9970ab21a176d4945d01ff0820bf1093c9d
MD5 30669e10f76094d7ae2f361c2ff9493e
BLAKE2b-256 2765630c80d1307b465d92536d2b2db3e18a5a2c8cae506fdf52ff9aa3ff7266

See more details on using hashes here.

File details

Details for the file tn_lens-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tn_lens-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tn_lens-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5be24faa653b700961fa931314eaece296e169b0b83d3d8166a47582d526037a
MD5 2179154ca1fc1433d7c8a4870abc8fd1
BLAKE2b-256 6311c3ac32fff783276225f30d61a88f8fcc5ef2a92231f964c0f4eec28725ca

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