← All Projects

Quantum Circuit Optimizer: C++ Quantum Compiler

Quantum ComputingCompilersC++OpenQASMCross-Layer

Status: Complete

Preprint: Integrated into qco-integration — "End-to-End Fidelity Analysis of Quantum Circuit Optimization" (Submitted to arXiv)

Overview

A production-quality C++ quantum circuit optimizer designed to study cross-layer compilation: how gate-level optimization metrics (circuit depth, gate count) translate to pulse-level fidelity. This project bridges the CUDA Quantum Simulator for validation and QubitPulseOpt for pulse-aware analysis.

Key Research Question: Do circuits with fewer gates actually have higher pulse-level fidelity? Initial evidence suggests gate merging can create arbitrary rotation angles that are harder to implement, potentially reducing fidelity despite "better" gate counts.

Architecture

Stage Component Description
1 Parser Hand-written recursive descent parser for OpenQASM 3.0
2 Circuit IR DAG-based intermediate representation
3 Optimization Passes 4 passes: cancellation, commutation, merging, folding
4 SABRE Routing Topology-aware qubit mapping
5 Output/Export Optimized circuit for simulation or pulse generation

Key Features

Parser

  • OpenQASM 3.0 Parser: Hand-written recursive descent parser with error recovery
  • Supports standard gate set, qubit declarations, and circuit structure

Intermediate Representation

  • DAG-based IR: Nodes represent gates, edges represent qubit dependencies
  • Enables topological traversal for optimization
  • Similar to how LLVM uses SSA for data flow analysis

Optimization Passes

  • Identity Cancellation: X·X = I, H·H = I, etc.
  • Gate Commutation: Reorder gates to enable further cancellations
  • Rotation Merging: Rz(θ₁)·Rz(θ₂) = Rz(θ₁ + θ₂)
  • Constant Folding: Simplify known-value operations

Qubit Routing

  • SABRE Algorithm: State-of-the-art routing for NISQ devices
  • Multiple Topologies: Linear, grid, heavy-hex support
  • Minimizes SWAP overhead for hardware constraints

Testing

  • 340 Unit Tests: Comprehensive coverage across parser, IR, passes, and routing
  • GoogleTest framework with CI integration

Cross-Layer Analysis Pipeline

Stage Tool Purpose
Input VQE Circuit From quantum-vqe
1 quantum-circuit-optimizer Measure: depth, gate count
2 cuda-quantum-simulator Validate: correctness
3 QubitPulseOpt Measure: pulse fidelity
Output Analysis Correlate gate metrics with pulse fidelity

Technology Stack

  • Language: C++17
  • Build: CMake
  • Parser: Hand-written recursive descent (OpenQASM 3.0)
  • IR Design: DAG-based (LLVM-inspired)
  • Routing: SABRE algorithm
  • Testing: GoogleTest (340 tests)

Links

Why Build From Scratch?

Building a quantum compiler from scratch (rather than using Qiskit/TKET) demonstrates understanding of compiler infrastructure fundamentals. More importantly, owning the implementation allows precise control over optimization decisions—essential for studying cross-layer fidelity effects.

This project directly supports my PhD application narrative: "I build the software control stack to make noisy quantum hardware perform like a reliable computer."