Source-linked AI summary
Yao.jl: Extensible, Efficient Framework for Quantum Algorithm Design
Xiu-Zhe Luo, Jin-Guo Liu, Pan Zhang, Lei Wang
TL;DR
Quantum algorithm design needs practical software that supports differentiable programming and efficient handling of near-term circuits. Yao provides a hardware-agnostic QBIR, reversible-computation automatic differentiation, and batched GPU-capable registers, achieving top performance for relevant applications while not directly supporting noisy simulation.
Problem
Near-term quantum algorithm research needs software for practical quantum-computation problems, especially differentiable programming of variational circuits under noisy intermediate-scale quantum limitations.
Method
Yao uses a hardware-agnostic quantum block intermediate representation with reversible-computation automatic differentiation and batched quantum registers supporting GPU acceleration.
Results
Yao achieves top performance for relevant applications and supports efficient differentiation, including reverse-mode optimization of a 10,000-layer variational circuit on a laptop.
Takeaways & Limitations
Yao’s extensibility and efficiency provide a framework for constructing, manipulating, differentiating, and simulating quantum circuits in near-term algorithm design.
Takeaways & Limitations
Yao does not currently support noisy simulations directly, although batched registers can be converted to reduced density matrices for noisy simulation through QuantumInformation.jl.
Abstract
from arXiv · showhide
We introduce Yao, an extensible, efficient open-source framework for quantum algorithm design. Yao features generic and differentiable programming of quantum circuits. It achieves state-of-the-art performance in simulating small to intermediate-sized quantum circuits that are relevant to near-term applications. We introduce the design principles and critical techniques behind Yao. These include the quantum block intermediate representation of quantum circuits, a builtin automatic differentiation engine optimized for reversible computing, and batched quantum registers with GPU acceleration. The extensibility and efficiency of Yao help boost innovation in quantum algorithm design.
1 Introduction
Yao addresses practical quantum-computation problems by combining differentiable programming with a hardware-agnostic quantum block intermediate representation. Its reversible automatic differentiation, generic extensibility, GPU support, and symbolic capabilities target efficient design and simulation of near-term quantum algorithms.
- Motivation: Yao targets practical quantum-computation problems, including variational algorithms whose circuit parameters are optimized through differentiable programming.The motivation is linked to limitations of near-term noisy intermediate-scale quantum circuits and the difficulty of designing quantum algorithms without strong quantum intuition.
- Quantum block intermediate representation: QBIR represents quantum operations as composable tensor blocks, bridging high-level algorithms and low-level device-specific instructions through a hardware-agnostic abstraction.Yao provides functionality to construct, inspect, manipulate, and differentiate circuits in terms of QBIR.
- Capabilities: 10,000 layers can be optimized with reverse-mode automatic differentiation on a laptop, while other examples include a 20-site Heisenberg Hamiltonian constructed in approximately 5 seconds.The introduction also reports symbolic simulation of Shor’s 9-qubit error-correction code and GPU-based optimization of a 6×6 lattice spin model.
- Automatic differentiation: Yao’s builtin automatic differentiation exploits reversible quantum computation, providing speed and constant memory cost with respect to circuit depth.The reversible computational graph supports differentiation through very deep circuits and avoids building on existing machine-learning frameworks.
- Extensibility and performance: Yao combines generic quantum registers, batched registers with GPU acceleration, symbolic manipulation, and extensible QBIR nodes without sacrificing performance.Its small- to intermediate-sized circuit simulation performance is described as among the best for near-term quantum algorithm design.
2 Quantum Block Intermediate Representation
Yao represents quantum operators, including circuits and observables, as a domain-specific abstract syntax tree called QBIR. This compositional representation supports circuit construction, manipulation, compilation, symbolic computation, and performance-oriented execution.
- QBIR is a domain-specific abstract syntax tree for quantum operators, including circuits and observables.
- Representing Quantum Circuits: Yao constructs a quantum Fourier transform QBIR in three lines using recursive hcphases blocks composed of Hadamard and controlled phase operations.The hcphases function places a Hadamard gate and chains several controlled shift gates.
- Representing Quantum Circuits: Yao’s QBIR represents circuits as composite and primitive blocks arranged in a tree, with ChainBlock, ControlBlock, and PutBlock encoding composition relations.In the QFT example, composite blocks form subtrees and primitive blocks form leaves.
- Execution and Performance: Yao applies QBIR circuits to quantum registers and provides sparse matrix representations for Hamiltonians, while caching can accelerate repeated Hamiltonian time-evolution applications.For circuit simulation, specialized apply! methods can instead operate without generating matrix representations.
- Circuit Manipulation: QBIR supports generic numeric and symbolic data types, allowing users to inspect symbolic matrix representations and manipulate circuits through Julia multiple dispatch.
3 Reversible Computing and Automatic Differentiation
Yao uses quantum circuits’ reversibility to implement automatic differentiation directly over QBIR. Its reverse-mode engine reduces memory complexity to constant with respect to circuit depth, enabling deep variational-circuit simulation.
- Automatic differentiation computes program gradients, and Yao’s AD engine is designed specifically for differentiable quantum circuits.
- Reverse Mode: Yao’s reverse-mode AD exploits reversible quantum computation to reduce memory complexity to constant with respect to circuit depth.The engine avoids the intermediate-state storage typical of reverse-mode differentiation by uncomputing states during backpropagation.
- Reverse Mode: Yao.AD backpropagates through quantum circuits using computational-graph information recorded in QBIR.
- Reverse Mode: 10,000-layer VQE with 300,010 variational parameters is simulated on a laptop using Yao’s AD engine.The paper presents this experiment as evidence that the customized engine supports very deep variational circuits.
- Forward Mode: For rotation gates with hermitian, reflexive generators, Yao’s faithful gradient evaluates parameter gradients by running the simulator twice.The method mirrors gradient measurement on a real quantum device and is implemented with Julia broadcasting semantics.
4 Quantum Registers
Yao presents quantum registers through hardware-specific storage and a unified instruction interface, while supporting active-qubit scoping and batched execution across processors.
- Register abstraction: Quantum registers store states in CPU or other hardware memory, including CUDA devices, while a unified apply! interface dispatches operations by register and block types.This abstraction covers classical CPU simulation, GPU simulation, and eventual quantum-device registers.
- Register interfaces: The instruction-set interface defines gate, measurement, and qubit-management operations, allowing new backends without changing frontend interfaces.The listed operations are instruct!, measure and measure!, focus!, and relax!.
- Examples: The phase-estimation example combines Hadamards, a controlled unitary, and a local inverse QFT over selected ancilla qubits.The circuit uses active-qubit scoping to apply the inverse QFT within the larger register.
- Active and environment qubits: Active and environment qubits let circuit blocks operate on selected qubits even when the block size differs from the full register.focus! activates selected qubits, while relax! restores the surrounding scope; Subroutine automates recurring focus–relax patterns.
- Batched registers: A batched register stores multiple quantum wave functions and applies the same circuit across them in parallel using SPMD execution.Batches support quantum machine-learning samples and ensembles of pure states for thermal-state simulation, with CPU or GPU acceleration.
5 Performance
Yao is benchmarked for individual gates, parameterized circuits, batched simulation, and automatic differentiation, emphasizing small to intermediate circuits relevant to repeated near-term workloads.
- Gate benchmarks: Yao, ProjectQ, and qulacs reach similar gate-simulation performance above 20 qubits and are several times faster than other packages.The comparison covers Pauli-X, Hadamard, CNOT, and Toffoli gate instructions.
- Parameterized circuits: Yao achieves the best CPU performance for parameterized circuits above 10 qubits, while matching qulacs on CUDA devices.CUDA parallelization becomes beneficial beyond 16 qubits; qiskit’s CUDA backend performs better above 20 qubits.
- Batched simulation: More than 10x speedup is obtained from Yao’s CUDA batched-register backend over its CPU backend for batch size 1000.Batching also provides substantial speedup for small circuits compared with repeated CPU execution.
- Simulation overhead: Yao shows the least overhead in benchmarks of small to intermediate-sized circuits, which are relevant when variational algorithms repeat circuits millions of times.The benchmark comparison identifies qulacs as also effective at suppressing overhead.
- Automatic differentiation: A laptop benchmark differentiates a depth-20 variational circuit with 200 parameters after constructing a sparse 20-site Heisenberg Hamiltonian.The forward-mode automatic-differentiation approach is slower by about two orders of magnitude in these simulations.
6 Extensibility
Yao prioritizes extensibility through new quantum blocks, gates, and register backends built on dispatch-based interfaces while retaining efficient execution paths.
- Design priority: Yao identifies flexibility and extensibility as its most important feature despite its demonstrated simulation efficiency.The framework supports extensions through new gates, quantum block nodes, and register types.
- Extending gates: New constant gates can be defined from matrix representations, with macros generating gate types and dispatch properties such as unitarity.The FSim example composes ISWAP and cphase gates with a fixed angle.
- Extending registers: New register types extend Yao by dispatching the instruction-set interfaces to device-specific implementations.CuYao dispatches instructions to CUDA kernels, parallelizing computation across the batch dimension and boosting performance.
7 Applications
Yao supports practical quantum-algorithm projects by simplifying implementations, enabling reduced-qubit tensor-network circuits, compiling gates through optimization, and integrating differentiable quantum–classical training.
- Quantum circuit Born machines: Yao reduced a quantum circuit Born machine implementation from about 200 lines to fewer than 50, with about 1000x performance improvement.The simpler codebase enabled further exploration of the algorithm.
- Tensor-network-inspired circuits: Tensor-network-inspired circuits can solve a 6 × 6 frustrated Heisenberg lattice model with only 12 qubits and support measuring and reusing qubits.These circuits can also compress quantum states onto hardware using fewer qubits.
- Gate learning: Automatic differentiation approximates an arbitrary U(4) unitary, up to global phase, by optimizing operator fidelity for a fixed circuit structure.The target gate set includes single-qubit gates and CNOT gates.
- Hybrid training: Yao’s efficient automatic differentiation and batched registers support joint training of quantum circuits and classical neural networks for thermal quantum states.This integration extends variational quantum eigensolver workflows to thermal quantum states through Zygote.
8 Roadmap
Yao’s roadmap extends its framework toward hardware control, compilation, circuit optimization, noisy simulation, and tensor-network methods. These directions target broader device integration and larger-scale or more realistic quantum-circuit studies.
- Hardware control: YaoScript already supports serializing QBIR for file or internet communication, providing a lightweight path toward cloud device control.The roadmap also plans parsing and code generation for OpenQASM, eQASM, and Quil through YaoQASM.
- Compilation: A planned compiler and language interface aims to make Yao more compilation-friendly and support seamless modeling of quantum channels through Julia’s compiler.The design builds on Julia’s native abstract syntax tree.
- Circuit optimization: Ongoing circuit simplification work targets pattern matching, term rewriting, and ZX calculus for smarter, more systematic circuit optimization.The stated motivation is reducing the cost of both simulations and experiments.
- Noisy simulation: Yao does not currently support noisy simulations directly, although batched registers can be converted to reduced density matrices for noisy simulation through QuantumInformation.jl.This provides a supported route through density-matrix methods rather than direct native noisy simulation.
- Tensor networks: Tensor-network methods offer a route to larger-scale simulation, especially for shallow circuits with many qubits, by exploiting low-rank structure with nearly negligible errors.YaoTensorNetwork can export circuits for exact or approximate tensor-network contraction and related circuit simplification.
- Tensor networks: Tensor networks may also support quantum machine learning by training unitary tensor networks classically and loading them onto quantum devices for fast sampling.In this envisioned use, quantum devices act as specialized inference hardware.
9 Summary
Yao is an open-source Julia package whose central quantum-block abstraction supports differentiable programming, batched GPU-enabled registers, symbolic circuit manipulation, and efficient quantum-algorithm development. Its extensible blocks and utilities cover circuit construction, inspection, serialization, error-correction examples, and integration with existing workflows.
- Core features: Yao provides differentiable programming with a built-in automatic-differentiation engine that leverages reversible computing.This is presented as a core framework feature.
- Core features: Yao provides batched quantum registers with CUDA parallelization for processing multiple quantum states in parallel.The feature is listed among the package’s principal capabilities.
- Core features: Yao supports symbolic manipulation of quantum circuits.The summary identifies symbolic manipulation as a core feature enabled by its quantum-block abstraction.
- Core features: Yao reports top performance for relevant applications, including small- to intermediate-sized quantum-circuit simulation.The framework links this efficiency to generic programming, Julia’s type system, and multiple dispatch.
- Design principles: The quantum-block abstraction is central to Yao’s features, while generic programming provides extensibility and efficiency.The abstraction represents the organizing principle of the framework’s design.
- Examples and utilities: Users can construct molecule Hamiltonian blocks and apply them to exact diagonalization, time evolution, or VQE workflows.The example uses an external OpenFermion module and then represents the Hamiltonian within Yao.
- Examples and utilities: Yao includes inspectable block types and supports defining new QBIR nodes for specialized simulation methods.The block hierarchy includes composite, primitive, matrix, measurement, and evolution-related blocks.
- Examples and utilities: YaoScript parses circuit strings into QBIR and supports dumping or loading circuits through files or internet data streams.The macro presents an alternative syntax while preventing code injection through parsing.
E Matrix Types in Yao
Yao uses specialized matrix representations for quantum gates and low-rank backpropagation, while allowing quantum blocks to be extended with optimized implementations such as FFT-based QFT emulation. These representations support operator analysis and quantum many-body computations.
- Matrix representations: Yao documents the matrix types used for basic quantum gates and their conversions under multiplication, Kronecker product, addition, and Hadamard product.The conversion table abbreviates IMatrix, Diagonal, PermMatrix, SparseMatrixCSC, and Matrix types.
- Matrix representations: LuxurySparse supplies specialized sparse matrices, including IMatrix and PermMatrix, for quantum-computation operations.PermMatrix supports nonzero entries with values other than one.
- Differentiation: Yao.AD uses OuterProduct low-rank matrices to improve memory and computation efficiency during backpropagation.The passage connects this type to the low-rank matrix formulation used for automatic differentiation.
- Extensible blocks: Users can define new QBIR nodes by subtyping primitive blocks and dispatching specialized simulation methods.The QFT example wraps a custom implementation as a primitive block.
- Extensible blocks: Overloading apply! lets Yao emulate QFT with a classical inverse FFT rather than the faithful circuit simulation route.Both faithful simulation and FFT emulation are included in YaoExtensions.
- Extensible blocks: Custom QFT blocks inherit built-in property inference such as hermiticity, unitarity, reflexivity, and commutativity.The inverse QFT can be obtained directly through the block’s adjoint operation.
G Symbolic Differentiation
Yao’s symbolic-differentiation example constructs a parameterized three-qubit circuit, derives symbolic energy gradients, and evaluates them numerically. The evaluated symbolic results agree with the corresponding numerical energy and gradient outputs shown in the example.
- Symbolic differentiation: Yao’s AD engine computes the gradient of a Heisenberg Hamiltonian with respect to circuit parameters symbolically and analytically.The example uses a three-qubit circuit and a Hamiltonian defined in Yao.
- Circuit setup: The example circuit contains parameterized Rx, controlled Ry, and two-qubit rotation blocks with parameters α, β, and γ.The circuit is represented as a three-qubit chain.
- Symbolic differentiation: Yao returns symbolic expressions for both the Hamiltonian expectation and its three-component gradient.The symbolic outputs are generated using expect and expect'.
- Numerical evaluation: The evaluated symbolic gradient contains the same displayed first two components as the numerical gradient: -1.22808300500511 and -0.311108582564352.The symbolic and numerical outputs are shown after substituting the same parameter assignment.
- Numerical evaluation: 1.9542144196548 is the numerical energy expectation for the example circuit and Hamiltonian.The displayed value is returned by the numerical expect call.
H Gate Learning
Yao supports gate learning by optimizing a parameterized circuit against a target unitary, using differentiable fidelity-based optimization. The example reaches essentially perfect fidelity and illustrates Yao’s broader algorithm and developer ecosystem.
- Gate-learning workflow: Gate learning minimizes the distance between a target unitary matrix and a parameterized circuit, supporting quantum compiling, diagonalization, and automated quantum algorithm design.
- Gate-learning results: 0.1387857997337068 to 0.9999999999999997: operator fidelity improves from the initial to final value after 150 iterations.
- Gate-learning results: The learned two-qubit ansatz is represented as a sequence of parameterized Z and Y rotations placed on the circuit.
- Gate-learning workflow: The example optimizes a general_U4 two-qubit ansatz with operator-fidelity gradients and the LBFGS optimizer.general_U4 is the minimal universal two-qubit gate decomposition defined in YaoExtensions.
- Broader ecosystem: Yao includes implementations of quantum Fourier transformation, variational eigensolvers, HHL, QAOA, and generative quantum models.
- Broader ecosystem: Its tutorials demonstrate extending register types, implementing CUDA gates, porting automatic differentiation, and integrating with QuantumInformation.