English | 简体中文
TensorCircuit-NG is the next-generation open-source high-performance quantum software framework and an AI-native quantum research runtime for turning research questions into executable, optimized, and validated quantum experiments.
TensorCircuit-NG is built upon tensornetwork engines, supporting for automatic differentiation, just-in-time compiling, hardware acceleration, vectorized parallelism and distributed training, providing unified infrastructures and interfaces for quantum programming. It can compose quantum circuits, neural networks and tensor networks seamlessly with high simulation efficiency and flexibility.
TensorCircuit-NG is built on top of modern machine learning frameworks: Jax, TensorFlow, and PyTorch. It is specifically suitable for large-scale simulations of quantum-classical hybrid paradigm and variational quantum algorithms in ideal (Circuit), noisy (DMCircuit), Clifford (StabilizerCircuit), qudit (QuditCircuit), approximate (MPSCircuit), analog (AnalogCircuit), symmetric (U1Circuit) and fermionic (FGSCircuit) cases. It also supports quantum hardware access and provides CPU/GPU/QPU hybrid deployment solutions.
TensorCircuit-NG is the technical successor to TensorCircuit, led and maintained by the original TensorCircuit development team. As a fully compatible drop-in replacement, TensorCircuit-NG delivers next-gen capabilities—including stabilizer/qudit/analog/symmetric circuit simulation and multi-node multi-GPU distributed simulation.
New companion project: We recently launched TenCirPauli, a Python-first, Rust-native companion that brings Pauli-native propagation and fixed-particle-number U(1) circuit execution to TensorCircuit-NG.
Getting Started
Please begin with Quick Start in the full documentation.
For more information on software usage, sota algorithm implementation and engineer paradigm demonstration, please refer to 200+ example scripts and 40+ tutorial notebooks. API docstrings and test cases in tests are also informative. One can also refer to AI-native docs for tensorcircuit-ng: Devin Deepwiki, Google Code Wiki, and Context7 MCP.
For beginners, please refer to quantum computing lectures with TC-NG to learn both quantum computing basics and representative usage of TensorCircuit-NG.
Agentic Quantum Research (Recommended)
TensorCircuit-NG is designed to give AI agents the context, rules, skills, and execution backends required for serious quantum research—not only code generation. To write TC-NG scripts and applications efficiently with AI coding agents (e.g., Claude Code, Cursor, CodeX), we strongly recommend working directly within the local tensorcircuit-ng repository rather than an empty folder.
In the ORBIT-Q benchmark, TensorCircuit-NG leads the evaluated quantum software frameworks on agent solve success and artifact runtime.
- Rich Context: The 100+ scripts in
examples/ and extensive test cases in tests/ provide essential references that significantly reduce AI hallucinations.
- Built-in Rules: We provide a dedicated AGENTS.md file. It serves as the "handbook" (i.e.
CLAUDE.md) for AI agents, defining coding standards and best practices to ensure the generated code is idiomatic.
- Specialized Agentic Skills: The
.agents/skills/ directory contains workflows to guide AI assistants on complex, multi-step tasks.
List of built-in agentic skills (click for details)
arxiv-reproduce: Translates published methods into standardized, runnable, and validated research artifacts.
performance-optimize: Scientific execution and memory optimization workflow (JAX scanning, vectorized parallelism, etc.).
tc-rosetta: End-to-end framework translation (from Qiskit, PennyLane, etc.) with intrinsic mathematical intent rewriting.
tutorial-crafter: Transforms raw TC-NG scripts into comprehensive, narrative-driven Markdown or/and HTML educational tutorials.
demo-generator: Transforms TC-NG scripts into interactive, sleek, and high-performance Streamlit GUI applications.
code-reviewer: Autonomously reviews and refactors TC-NG code for mathematical correctness, JAX-native performance, and engineering rigor.
sanity-checker: Systematic audit and refactoring to reduce technical debt, improve abstractions, and ensure codebase health.
meta-explorer: High-intensity autonomous research agent for circuit architecture and optimization strategy discovery (VQE, QML, QAOA, etc.).
Recommended Workflow:
- Clone the repository:
git clone https://github.com/tensorcircuit/tensorcircuit-ng.git
- Switch to a local playground branch:
git checkout -b my-playground in case messing up with the original repository.
- Open the repository folder in your AI IDE. And you are ready to start writing TC-NG-based scripts.
Now, enjoy exploring quantum research through natural language. By combining extreme performance with an autonomous, intent-driven AI workflow (via embedded .agents/skills/), TC-NG helps researchers move from a research question to implementation, exploration, optimization, validation, and a reusable scientific artifact.
Quick Demos
The following are some minimal demos.
import tensorcircuit as tc
c = tc.Circuit(2)
c.H(0)
c.CNOT(0,1)
c.rx(1, theta=0.2)
print(c.wavefunction())
print(c.expectation_ps(z=[0, 1]))
print(c.sample(allow_state=True, batch=1024, format="count_dict_bin"))
- Runtime behavior customization:
tc.set_backend("jax")
tc.set_dtype("complex128")
tc.set_contractor("cotengra")
- Automatic differentiation with jit:
def forward(theta):
c = tc.Circuit(2)
c.R(0, theta=theta, alpha=0.5, phi=0.8)
return tc.backend.real(c.expectation((tc.gates.z(), [0])))
g = tc.backend.grad(forward)
g = tc.backend.jit(g)
theta = tc.array_to_tensor(1.0)
print(g(theta))
More highlight features for TensorCircuit (click for details)
- Sparse Hamiltonian generation and expectation evaluation:
n = 6
pauli_structures = []
weights = []
for i in range(n):
pauli_structures.append(tc.quantum.xyz2ps({"z": [i, (i + 1) % n]}, n=n))
weights.append(1.0)
for i in range(n):
pauli_structures.append(tc.quantum.xyz2ps({"x": [i]}, n=n))
weights.append(-1.0)
h = tc.quantum.PauliStringSum2COO(pauli_structures, weights)
print(h)
# BCOO(complex64[64, 64], nse=448)
c = tc.Circuit(n)
c.h(range(n))
energy = tc.templates.measurements.operator_expectation(c, h)
# -6
- Large-scale simulation with tensor network engine
# tc.set_contractor("cotengra-30-10")
n=500
c = tc.Circuit(n)
c.h(0)
c.cx(range(n-1), range(1, n))
c.expectation_ps(z=[0, n-1], reuse=False)
- Density matrix simulator and quantum info quantities
c = tc.DMCircuit(2)
c.h(0)
c.cx(0, 1)
c.depolarizing(1, px=0.1, py=0.1, pz=0.1)
dm = c.state()
print(tc.quantum.entropy(dm))
print(tc.quantum.entanglement_entropy(dm, [0]))
print(tc.quantum.entanglement_negativity(dm, [0]))
print(tc.quantum.log_negativity(dm, [0]))
Install
The package is written in pure Python and can be obtained via pip as:
pip install tensorcircuit-ng
We recommend you install this package with tensorflow or jax also installed as:
pip install "tensorcircuit-ng[jax]"
Other optional dependencies include [torch], [tensorflow], [qiskit] and [cloud].
Try nightly build for the newest features:
pip install tensorcircuit-nightly
Advantages
Tensor network simulation engine based
JIT, AD, vectorized parallelism compatible
GPU support, QPU access support, hybrid deployment support
HPC native, distributed simulation enabled, multiple devices/hosts support
Efficiency
Time: 10 to 10^6+ times acceleration compared to TensorFlow Quantum, Pennylane, CuQuantum, TorchQuantum or Qiskit
Space: 1000+ qubits 1D VQE workflow (converged energy inaccuracy: < 0.5%)
Elegance
Flexibility: customized contraction, multiple ML backend/interface choices, multiple dtype precisions, multiple QPU providers
API design: quantum for humans, less code, more power
Batteries included