Relaxed Peephole Optimization: A Novel Compiler Optimization for Quantum Circuits

Ji Liu, Luciano Bello, Huiyang Zhou · DOI

Abstract

In this paper, we propose a novel quantum compiler optimization, named relaxed peephole optimization (RPO) for quantum computers. RPO leverages the single-qubit state information that can be determined statically by the compiler. We define that a qubit is in a basis state when, at a given point in time, its state is either in the X-, Y-, or Z-basis. When basis qubits are used as inputs to quantum gates, there exist opportunities for strength reduction, which replaces quantum operations with equivalent but less expensive ones. Compared to the existing peephole optimization for quantum programs, the difference is that our proposed optimization does not require an identical unitary matrix, thereby named 'relaxed' peephole optimization. We also extend our approach to optimize the quantum gates when some input qubits are in known pure states. Both optimizations, namely the Quantum Basis-state Optimization (QBO) and the Quantum Pure-state Optimization (QPO), are implemented in the IBM's Qiskit transpiler. Our experimental results show that our proposed optimization pass is fast and effective. The circuits optimized with our compiler optimizations obtain up to 18.0% (11.7% on average) fewer CNOT gates and up to 8.2% (7.1% on average) lower transpilation time than that of the most aggressive optimization level in the Qiskit compiler. When running on real quantum computers, the success rates of 3-qubit quantum phase estimation algorithm improve by 2.30X due to the reduced gate counts.

Introduction

In the current Noisy Intermediate-Scale Quantum (NISQ) era, quantum computers are incredibly sensitive to noise. Every gate—especially two-qubit gates like CNOT—introduces errors and decoherence. To achieve meaningful results, compilers must minimize the total gate count. Traditional "peephole optimization" looks for small patterns of gates and replaces them with more efficient, mathematically identical sequences. However, the requirement for strict unitary identity is often too restrictive. Relaxed Peephole Optimization (RPO) addresses this by identifying functionally equivalent operations based on known qubit states at specific points in a circuit.

Methodology

The RPO framework consists of two main passes implemented in IBM’s Qiskit transpiler:

  1. Quantum Basis-state Optimization (QBO): This pass tracks qubits in one of the six cardinal basis states ($|0\rangle, |1\rangle, |+\rangle, |-\rangle, |L\rangle, |R\rangle$). If a gate's behavior is redundant or simplifies given these inputs, it is reduced. For instance, a CNOT whose control qubit is $|0\rangle$ can be deleted entirely.
  2. Quantum Pure-state Optimization (QPO): A generalized version that tracks any single-qubit pure state using Bloch sphere coordinates. This allows simplification even in arbitrary superpositions, provided the qubits are not entangled.
Figure 4: Simplification of a Toffoli gate based on specific input basis states.

Key Innovations

  • State Analysis: The compiler uses finite automata and parameter propagation to track qubit states through the circuit.
  • Functional Equivalence: Unlike standard optimizers requiring $U_1 = U_2$, RPO only requires $U_1|\psi\rangle = U_2|\psi\rangle$ for the known input state $|\psi\rangle$.
  • User Annotations: To bypass the NP-hard challenge of determining entanglement, programmers can annotate qubits (e.g., marking an ancilla as "clean"), enabling further optimization.

Key Insights: SWAP Optimization

SWAP gates are notoriously expensive, typically requiring three CNOT gates. RPO leverages state knowledge to significantly thin these operations. If one input to a SWAP is a known pure state, the operation can be reduced to a more efficient form or even single-qubit gates.

Figure 5: Reduction of a SWAP gate when one input is a known pure state.

Experimental Results

The authors evaluated RPO using standard algorithms like Bernstein-Vazirani, Quantum Phase Estimation (QPE), and Grover’s Search on IBM quantum simulators and real processors (ibmq_16_melbourne, ibmq_almaden, and ibmq_rochester).

  • Gate Reduction: RPO achieved up to 18.0% fewer CNOT gates (11.7% on average) compared to Qiskit’s Level 3 optimization.
  • Efficiency: Total transpilation time decreased by 7.1% on average because simplified circuits are easier for subsequent compiler passes to process.
  • Hardware Fidelity: On real hardware, the success rate of a 3-qubit QPE algorithm improved by 2.30x, demonstrating that RPO can be the difference between a clear signal and complete noise.

Conclusion

Relaxed Peephole Optimization provides a powerful method for reducing noise in NISQ devices by relaxing the constraints of traditional circuit optimization. While currently limited by the "entanglement barrier," where state analysis stops once qubits entangle, future work combining RPO with global circuit synthesis or dynamic mid-circuit measurements promises even greater gains in quantum computational efficiency.

Summary updated

BibTeX
@misc{liu2020relaxed,
  author = {Ji Liu and Luciano Bello and Huiyang Zhou},
  title = {{Relaxed Peephole Optimization: A Novel Compiler Optimization for Quantum Circuits}},
  year = {2020},
  eprint = {2012.07711},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.07711},
}
Figure