Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

yao-rs

Quantum circuit description and tensor network export in Rust.

What is yao-rs?

yao-rs is a library for describing quantum circuits and exporting them as tensor networks. It provides a type-safe circuit construction API with validation, and converts circuits into einsum representations suitable for contraction order optimization via omeco.

Ported from the Julia library Yao.jl, focused on the circuit description and tensor network layers.

Module Architecture

Core Simulation Tensor Export Utilities Higher-level Visualization
Click a module to expand/collapse its public items. Double-click to open rustdoc.

Why Tensor Network Export?

Tensor networks provide an alternative to full state-vector simulation. Instead of tracking the entire 2^n-dimensional state vector, a circuit is decomposed into a network of small tensors. The contraction order determines computational cost — and can make an exponential difference:

ApproachMemoryScaling
State vectorO(2^n)Exponential in qubits
Tensor networkDepends on orderCan be much better for structured circuits

yao-rs further optimizes by recognizing diagonal gates (Z, S, T, Phase, Rz), which reduce tensor rank in the network.

Key Features

  • Circuit Description: put/control builder API with qudit support
  • Tensor Network Export: circuit_to_einsum with diagonal gate optimization
  • Contraction Optimization: Integration with omeco
  • State-Vector Simulation: Direct apply for verification

Example

#![allow(unused)]
fn main() {
use yao_rs::{Gate, Circuit, State, put, control, apply, circuit_to_einsum};

// Build a Bell circuit
let circuit = Circuit::new(vec![2, 2], vec![
    put(vec![0], Gate::H),
    control(vec![0], vec![1], Gate::X),
]).unwrap();

// Simulate
let state = State::zero_state(&[2, 2]);
let result = apply(&circuit, &state);

// Export as tensor network
let tn = circuit_to_einsum(&circuit);
println!("Tensors: {}, Labels: {}", tn.tensors.len(), tn.size_dict.len());
}

Next Steps