NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Quantum compiling by deep reinforcement learning

Lorenzo Del Moro, Matteo G. A. Paris, Marcello Restelli, Enrico PratiCommunications 2021

Abstract

The general problem of quantum compiling is to approximate any unitary transformation that describes the quantum computation as a sequence of elements selected from a finite base of universal quantum gates. The Solovay-Kitaev theorem guarantees the existence of such an approximating sequence. Though, the solutions to the quantum compiling problem suffer from a tradeoff between the length of the sequences, the precompilation time, and the execution time. Traditional approaches are time-consuming, unsuitable to be employed during computation. Here, we propose a deep reinforcement learning method as an alternative strategy, which requires a single precompilation procedure to learn a general strategy to approximate single-qubit unitaries. We show that this approach reduces the overall execution time, improving the tradeoff between the length of the sequence and execution time, potentially allowing real-time operations.

Introduction

At the hardware level, quantum computers can only execute a limited, "native" set of quantum gates. However, quantum algorithms are often written using arbitrary unitary transformations. The "quantum compiling" problem involves finding a sequence of these native gates that approximates a target unitary within a specific error tolerance ($\epsilon$).

While the Solovay-Kitaev theorem proves such sequences always exist, finding them is difficult. Traditional compilers face a brutal three-way tradeoff between the length of the resulting gate sequence, the time spent searching for that sequence (precompilation), and the time the algorithm takes to return an answer (execution). Existing methods are often too slow to be used "on-the-fly" during a computation, which is a major hurdle for adaptive quantum algorithms.

Methodology: Compiling as Reinforcement Learning

This research frames quantum compiling as a reinforcement learning (RL) problem, shifting the heavy computational burden from the execution phase to a one-time training phase.

The deep reinforcement learning framework for quantum compiling, illustrating the interaction loop between the agent and the quantum environment alongside the neural network architecture.

In this framework, the Agent is a deep neural network that acts as a decision-maker. The Environment is a quantum circuit that starts as an identity matrix. At each step, the agent chooses a gate from a base set (the "actions") to add to the circuit. The agent receives an Observation consisting of the real and imaginary parts of the matrix representing the distance between the current circuit and the target unitary.

To ensure the compiler is general-purpose, the agents were trained and validated using a uniform distribution of single-qubit unitary matrices (Haar measure). This ensures the agent learns the underlying geometry of the space rather than memorizing specific rotations. The neural network architecture is lean, consisting of just two hidden layers with 128 neurons each, utilizing Scaled Exponential Linear Units (SELU) for stability.

Key Results and Performance

The DRL approach demonstrates significant improvements in both fidelity and execution speed. Once trained, the policy is "baked" into the neural network weights, allowing for near-instantaneous compilation of new, unseen unitaries.

Learning progress and results: (a) Bloch sphere trajectories of the quantum state approaching the target unitary over training episodes. (b) Percentage of solved episodes and the corresponding gate sequence length as training progresses.

Key performance metrics include:

  • High Fidelity: The agents achieved an average gate fidelity (AGF) of 0.9999 in the best cases for small rotations.
  • Efficiency: When using the Harrow-Recht-Chuang (HRC) gate set, the agent solved over 95% of random targets with an average sequence length of only 35 gates.
  • Speed: Execution time was clocked at approximately $5.4 \times 10^{-4}$ seconds per time step on a single CPU core, suggesting viability for real-time operations.
  • Generalization: After training on Haar unitaries, the agent could approximate 96.4% of any random single-qubit unitary within a 0.99 AGF tolerance.

Discussion and Future Directions

The primary advantage of this method is the "one-time cost" of training. While training is computationally expensive, it only happens once. The resulting agent's execution time scales as $O(\log^{1.25}(1/\delta))$, where $\delta$ is the precision, which is a significant improvement over traditional benchmarks.

The current study focuses on single-qubit unitaries. Scaling DRL to multi-qubit systems remains a challenge due to the exponential growth of the state space. Future work will explore more complex architectures like Graph Neural Networks and incorporate hardware-specific constraints, such as qubit connectivity and noise profiles, directly into the reward function to push the agent closer to theoretical limits of optimality.

Summary updated

BibTeX
@inproceedings{moro2021quantum,
  author = {Lorenzo Del Moro and Matteo G. A. Paris and Marcello Restelli and Enrico Prati},
  title = {{Quantum compiling by deep reinforcement learning}},
  booktitle = {Communications},
  year = {2021},
  doi = {10.1038/s42005-021-00684-3},
}
Figure