Source-linked AI summary
TensorCircuit: a Quantum Software Framework for the NISQ Era
Shi-Xin Zhang, Jonathan Allcock, Zhou-Quan Wan, Shuo Liu, Jiace Sun, Hao Yu, Xing-Han Yang, Jiezhong Qiu, Zhaofeng Ye, Yu-Qin Chen, Chee-Kong Lee, Yi-Cong Zheng, Shao-Kai Jian, Hong Yao, Chang-Yu Hsieh, Shengyu Zhang
TL;DR
Quantum simulation needs to scale to larger and more complex circuits while supporting parameter optimization and hybrid quantum-classical workflows. TensorCircuit addresses this gap by combining tensor-network contraction with machine-learning frameworks and reports large speedups across several simulation tasks. Its benefits depend on repeated evaluations that amortize just-in-time compilation and on comparisons with supported baselines.
Problem
Existing quantum simulators leave a gap in combining space- and time-efficient tensor-network simulation with automatic differentiation, just-in-time compilation, vectorization, and GPU support.
Method
TensorCircuit combines a customizable tensor-network simulation engine with machine-learning backends supporting automatic differentiation, vectorized parallelism, just-in-time compilation, and hardware acceleration.
Results
TensorCircuit reports an 85,000 times acceleration for H2O VQE evaluation over a naïve loop and nearly a million times speedup over Qiskit for moderate-sized QFI and Hessian computations.
Takeaways & Limitations
TensorCircuit provides an open-source Python framework for larger and more complex quantum simulations, including vectorized noisy trajectories and compact MPS-based input states.
Takeaways & Limitations
Reported benchmark averages exclude initial JIT compilation, whose cost can outweigh benefits when circuits are evaluated only a few times.
Abstract
from arXiv · showhide
TensorCircuit is an open source quantum circuit simulator based on tensor network contraction, designed for speed, flexibility and code efficiency. Written purely in Python, and built on top of industry-standard machine learning frameworks, TensorCircuit supports automatic differentiation, just-in-time compilation, vectorized parallelism and hardware acceleration. These features allow TensorCircuit to simulate larger and more complex quantum circuits than existing simulators, and are especially suited to variational algorithms based on parameterized quantum circuits. TensorCircuit enables orders of magnitude speedup for various quantum simulation tasks compared to other common quantum software, and can simulate up to 600 qubits with moderate circuit depth and low-dimensional connectivity. With its time and space efficiency, flexible and extensible architecture and compact, user-friendly API, TensorCircuit has been built to facilitate the design, simulation and analysis of quantum algorithms in the Noisy Intermediate-Scale Quantum (NISQ) era.
1 Introduction
TensorCircuit addresses the need to simulate larger, more complex quantum circuits and optimize parameterized circuits by combining tensor-network simulation with modern machine-learning capabilities. Its design targets hybrid and variational quantum algorithms through automatic differentiation, just-in-time compilation, vectorization, and hardware acceleration.
- Motivation: Researchers increasingly need larger, more complex circuit simulations and efficient optimization of circuits with many tunable parameters.
- Challenges: Parameterized-circuit optimization is difficult because ansätze may lack sufficient accuracy, Hamiltonian expectations can require many Pauli-term evaluations, and the objective is generally non-convex.
- Machine-learning capabilities: Automatic differentiation provides efficient gradients for code-defined functions, supporting optimization of machine-learning models and parameterized quantum circuits.
- Machine-learning capabilities: Just-in-time compilation, vectorization, and hardware acceleration can reduce execution costs by compiling functions, evaluating multiple inputs or parameter choices in parallel, and using CPUs, GPUs, or TPUs.
- Contribution: Integration with classical machine-learning frameworks supports quantum machine-learning and hybrid quantum-classical models.
- Contribution: TensorCircuit was designed to fill a gap in combining a tensor-network engine with automatic differentiation, just-in-time compilation, vectorized parallelism, and GPU support.
2 TensorCircuit Overview
TensorCircuit is an open-source Python simulator that combines tensor-network contraction with machine-learning backends through a unified, flexible architecture. Its API supports hybrid models, customizable contraction, multiple hardware targets, and community development.
- Architecture: TensorCircuit combines a flexible tensor-network engine with automatic differentiation, vectorized parallelism, and just-in-time compilation through TensorFlow, JAX, and PyTorch backends.
- Hybrid models: TensorCircuit supports hybrid quantum-classical models in which parameterized-circuit outputs can feed classical neural networks or classical outputs can feed quantum circuits.
- Simulation approach: Tensor-network simulation can avoid the full-state memory bottleneck and is applicable to circuits with many qubits, including relatively shallow NISQ circuits.
- Flexibility: The backend-agnostic design supports CPUs, GPUs, and TPUs, switches between 32-bit and 64-bit precision, and preserves syntax and functionality across machine-learning backends.
- Usability and community: TensorCircuit provides a compact, easy-to-use API and is released as open-source Python software with community contribution pathways.
- Simulation approach: TensorCircuit separates contraction-path selection from tensor contraction, using engines such as cotengra and selected machine-learning backends for execution.
3 Circuits and gates
TensorCircuit provides a compact interface for constructing, composing, simulating, measuring, and visualizing noiseless and noisy quantum circuits. Its circuit objects support standard, parameterized, arbitrary, exponential, and non-unitary operations, plus interoperability with Qiskit.
- TensorCircuit creates quantum circuits with tc.Circuit(n), supporting noiseless and noisy simulations via Monte Carlo trajectory methods.
- Measurement returns bitstring–probability outcomes and does not collapse the circuit output state unless explicit measurement gates are used.
- Expectation values can be computed for individual operators, operator sums, user-defined matrices, and longer Pauli strings.
- Circuits support standard and parameterized gates, arbitrary unitaries, exponential gates, and non-unitary matrices.Fast exp1 implementations are available when G^2 = I; general exponentials use exp.
- Non-unitary gates produce unnormalized output states because normalization is omitted when unnecessary to reduce computational time.
- Initial states may be supplied as amplitude arrays or Matrix Product States, and equal-sized circuits can be composed with append or prepend.
- TensorCircuit circuits can be converted to and from Qiskit QuantumCircuit objects and visualized through LaTeX quantikz code or the draw function.
4 Gradients, optimization and variational algorithms
TensorCircuit combines parameterized circuit construction with machine-learning backends for differentiable energy evaluation and optimization. JIT compilation accelerates repeated evaluations, while TensorFlow, JAX, SciPy, and backend-specific optimizers provide multiple optimization routes.
- Parameterized circuits: Parameterized layered circuits can be defined for general n qubits, k layers, and parameter vectors using nearest-neighbor XX gates followed by single-qubit Z and X rotations.
- Gradients: Machine-learning backends compute energy functions and their parameter gradients through automatic differentiation.
- JIT compilation: Repeated energy-and-gradient evaluations become noticeably faster after the initial compilation overhead when K.jit is used.
- Optimization: Available optimization routes include stochastic gradient descent through TensorFlow or JAX backends and gradient-based or gradient-free SciPy optimizers.
- Backend selection: TensorCircuit defaults to NumPy when no backend is selected, and this backend does not support automatic differentiation.
5 Density matrices and mixed state evolution
TensorCircuit supports noisy and mixed-state evolution through full density-matrix simulation and Monte Carlo trajectories. Both approaches accept quantum channels through Kraus operators, with specialized APIs for common channels and unitary Kraus decompositions.
- Density-matrix simulation: Full density-matrix simulation uses tc.DMCircuit(n) and supports unitary gates and general quantum operations specified by Kraus operators.Compared with pure-state simulation, it is twice as memory intensive, so the maximum simulatable system size is halved.
- Quantum channels: Common channels such as amplitude damping, depolarizing, phase damping, and reset have built-in Kraus-operator methods.
- Monte Carlo simulation: Monte Carlo simulation uses tc.Circuit to represent a mixed state as an ensemble of pure states and applies channels through their Kraus operators.
- Monte Carlo simulation: The unitary_kraus method provides a more efficient Monte Carlo implementation when all Kraus operators are unitary up to constant factors.
- Externalized randomness: External random variables can be passed through the status argument, enabling batched Monte Carlo runs with vmap.
6 Advanced features
Section 6 presents advanced TensorCircuit features used in later benchmark studies.
- The section introduces advanced features that general readers may skip initially.Benchmark examples in Section 7 use several concepts from this section.
6.1 Conditional measurements and post-selection
TensorCircuit supports conditional measurements, measurement-controlled gates, and post-selection for simulating measurement-dependent quantum processes.
- Conditional measurements produce outcomes that can control subsequent quantum gates.The cond_measure command performs a Z measurement, samples using the Born rule, and collapses the wavefunction.
- The conditional_gate API can use measurement outcomes to implement circuits such as quantum teleportation.
- Post-selection selects a post-measurement state for a specified outcome without normalizing the returned state.TensorCircuit provides this behavior through post_select and its keep argument.
- The unnormalized post-selection scheme is described as fast and applicable to measurement-induced entanglement phase transitions.
6.2 Pauli string expectation
TensorCircuit offers multiple representations and evaluation strategies for Pauli-string Hamiltonians, including loops, vectorization, sparse matrices, and MPOs. Benchmarks show substantial speed differences across these approaches.
- Pauli-string Hamiltonians can be evaluated by looping over terms, using operator representations, or vectorizing terms with vmap.
- Pauli structures and weights: A Pauli string on n qubits is encoded as a length-n structure vector with entries 0, 1, 2, or 3 for I, X, Y, and Z.For example, X1X2 is represented as [0, 1, 1] when n = 3.
- The operator_expectation API accepts dense matrices, sparse matrices, or Matrix Product Operators as Hamiltonian representations.
- Benchmark results: 0.008 s CPU time was reported for the sparse matrix representation, compared with 65.7 s for an explicit loop in another benchmark.The corresponding GPU times were 0.0014 s and 119 s, respectively.
- Benchmark results: 85,000 times acceleration was observed for H2O VQE evaluation using a sparse matrix versus a naïve loop.The benchmark used 12 qubits and 1390 Pauli-string terms with the JAX backend.
- Benchmark caveat: Reported benchmark averages exclude initial JIT compilation, whose cost can exceed subsequent evaluation times when circuits are evaluated only a few times.The authors state that this cost is typically amortized in workloads with many circuit evaluations.
- Benchmark results: 0.0007 s CPU time was reported for the MPO representation, compared with 1.73 s for an explicit loop in one benchmark.The corresponding GPU times were 0.0039 s and 0.11 s, respectively.
6.3 vmap and vectorized_value_and_grad
TensorCircuit combines vectorization and automatic differentiation to evaluate batched quantum functions, gradients, circuit parameters, Pauli terms, data, labels, and noisy trajectories. These tools also support simultaneous independent VQE optimization loops.
- vectorized_value_and_grad batches function evaluations while differentiating with respect to selected arguments.It returns values for all batched inputs and gradients aggregated over those inputs.
- Batched input states: Batched input states can be processed simultaneously while computing gradients with respect to circuit weights.
- Batched circuits: The same mechanism batches gradients across differently parameterized circuits that share a parent circuit.
- Batched Pauli terms: Pauli-term expectation values and their gradients can be batch computed by vectorizing over Pauli structure vectors.
- Batched training: Tuple-valued vectorized arguments support batch training over data-label pairs while differentiating the circuit weights.The auxiliary predicted-label output can be retained for metrics such as AUC or ROC.
- Batched VQE: Batched VQE can run independent optimization loops simultaneously from multiple initial parameter points.Combining this workflow with JIT is described as useful for finding ground-state energies.
- Noisy simulation: Vectorization also computes noisy-circuit Monte Carlo trajectories in parallel using externally supplied random inputs.
6.4 QuOperator and QuVector
QuOperator and QuVector provide matrix- and vector-like interfaces backed by compact, flexible tensor networks. They support efficient circuit inputs, operator expectations, and tensor-network manipulation.
- Data structures: QuOperator and QuVector behave like matrices and vectors while storing their inner structures as tensor networks.They support matrix-matrix and matrix-vector multiplication, adjoints, scalar multiplication, tensor products, partial traces, and matrix extraction.
- Flexible representations: QuOperator and QuVector represent standard MPOs and MPSs while also supporting more flexible tensor-network structures.QuVector permits freely chosen dangling-edge dimensions, including arbitrary tensor products of vectors.
- QuVector as circuit input: For an n-qubit circuit, regular vector inputs require 2^n complex values, whereas an MPS QuVector with bond dimension d stores O(nd^2) elements.This compact representation enables DMRG ground states to be passed into quantum machine-learning circuits.
- Circuit integration: A quantum circuit can itself be converted into a QuVector and then further manipulated using QuOperator objects.This treats the circuit’s output-state tensor network as a reusable vector-like object.
- Efficient operators: QuOperators can represent Hamiltonians and multi-controlled gates compactly when their MPO forms have low bond dimension.For TFIM, the MPO bond dimension can be d = 3; multi-controlled gates can use bond dimension d = 2.
6.5 Custom contraction settings
TensorCircuit exposes configurable contraction-path search so users can optimize tensor-network simulation for time and memory. Custom cotengra strategies and subtree reconfiguration improve contraction efficiency over the default contractor.
- Path selection: The default greedy path finder is generally suitable for moderate circuits, while circuits with 16 qubits or more may benefit from customized path finders.Users can configure strategies that target flops, write, size, or combinations of these objectives.
- Contraction metrics: TensorCircuit measures contraction paths using FLOPs for computational work, WRITE for total generated tensor elements, and SIZE for the largest intermediate tensor.Because automatic differentiation caches intermediate results, WRITE is the more relevant spatial metric for TensorCircuit simulations.
- Path optimization: Custom cotengra optimizers and subtree reconfiguration search for improved contraction paths by optimizing selected time- and space-related scores.Subtree reconfiguration repeatedly optimizes parts of an existing contraction tree and can be supplied as a custom path finder.
- Benchmark: For the n = 40, d = 6 example, cotengra optimization and subtree reconfiguration improve contraction efficiency, with more than a factor of two improvement in simulation time and space over the default contractor.The improvement can increase for larger system sizes; Table 5 reports one run and notes that performance varies because the methods are intrinsically random.
6.6 Advanced automatic differentiation
TensorCircuit provides automatic-differentiation interfaces for Jacobians, directional derivatives, quantum natural gradients, Hessians, and related quantities. These tools support parameterized-circuit analysis and substantially accelerate gradient-related computations compared with parameter-shift evaluation.
- Automatic differentiation: TensorCircuit supports forward- and reverse-mode automatic differentiation, with their relative efficiency determined by input and output dimensions.Forward mode is advantageous for tall Jacobians, while reverse mode is advantageous in the opposite dimensional regime.
- Jacobians and JVPs: Jacobian-vector products provide directional derivatives and are available through forward-mode automatic differentiation.Choosing v = e_i yields the partial-derivative vector for the corresponding input coordinate.
- Higher-order quantities: TensorCircuit exposes quantum natural gradients and Hessians for parameterized quantum circuits.Quantum Fisher Information supports quantum natural-gradient optimization, while Hessians can help investigate loss landscapes or second-order optimization.
- Benchmark: Nearly a million times of speedup over Qiskit is reported for QFI and Hessian computations on even moderate-sized quantum circuits.The comparison is against traditional quantum software using parameter shifts for gradient-related quantities.
7 Integrated examples
The integrated examples show TensorCircuit applied to quantum chemistry, VQE, hybrid quantum-classical learning, barren-plateau analysis, and large-circuit simulation, with benchmarks demonstrating substantial acceleration and scaling.
- Molecular VQE and OpenFermion: TensorCircuit interfaces with OpenFermion to generate molecular Hamiltonians and convert qubit Hamiltonians into the Pauli structures and weights used by its circuits.The H2O example uses Jordan–Wigner transformation and supports sparse matrix Hamiltonian representations.
- VQE benchmarking: The TFIM VQE benchmark evaluates both energy expectations and circuit gradients, using an explicit Pauli-string loop to focus comparisons on circuit and gradient efficiency.The authors note that the TFIM benchmark differs from molecular systems mainly in the number and type of Pauli strings.
- Hybrid neural networks: TensorCircuit wraps quantum circuits as Keras-compatible QuantumLayer objects, enabling integration of quantum and classical neural networks for batched supervised learning.The example uses circuit weights as input and expectation values as output.
- Barren plateaus: 155.28 s, 6.24 s, 0.12 s, and 0.011 s are the reported times for Pennylane CPU, TensorFlow Quantum, TensorCircuit CPU, and TensorCircuit GPU, respectively, in the barren-plateau benchmark.The benchmark uses 100 random 10-qubit, 10-layer circuits; vmap and jit provide TensorCircuit with more than 500× speedup over TensorFlow Quantum.
- Very large circuit simulation: n = 200, 400, and 600 systems are benchmarked by evaluating both energy expectations and circuit gradients per computational step.The reported high-accuracy results require no fine-tuning of the optimizer for the tested one-dimensional TFIM systems.
8 Outlook and concluding remarks
TensorCircuit is presented as an open-source Python package combining modern machine-learning engineering paradigms with a customizable tensor-network engine for high-performance quantum simulation. The outlook prioritizes broader contraction, control, distribution, approximation, optimization, and application capabilities.
- Conclusion: TensorCircuit combines modern machine-learning paradigms with a flexible, customizable tensor-network engine for high-performance circuit computation.The package is designed for larger and more complex quantum computing simulations.
- Outlook: The development roadmap includes better tensor-network contraction path finders, pulse-level optimization, distributed simulation, approximate MPS-based simulation, and quantum-aware optimizers.These priorities target more efficient contraction, differentiable control, multi-host computation, larger approximate simulations, and alternative optimization methods.
- Outlook: Future application-level libraries are planned for finance, materials, energy, biology, drug discovery, and climate prediction.The authors hope TensorCircuit will contribute to academic and commercial progress in quantum computing.