Table of Contents
Fetching ...

Transpiling quantum circuits by a transformers-based algorithm

Michele Banfi, Paolo Zentilini, Sebastiano Corli, Enrico Prati

TL;DR

This work treats quantum circuit transpilation as a seq2seq translation task by employing an encoder–decoder transformer operating on OpenQASM representations. A RegEx-driven tokenizer discretizes continuous rotation angles into symbolic tokens, enabling robust mapping between IBM and IonQ gate sets with cross-attention guiding output generation. The model attains fidelity exceeding $99.98\%$ for up to five-qubit circuits and demonstrates scaling considerations for continuous versus Solovay-Kitaev–decomposed gates, highlighting the need for larger context windows for long sequences. The approach offers a scalable, automated route for cross-platform quantum compilation, with implications for hardware-aware optimization on HPC infrastructures.

Abstract

Transformers have gained popularity in machine learning due to their application in the field of natural language processing. They manipulate and process text efficiently, capturing long-range dependencies among data and performing the next word prediction. On the other hand, gate-based quantum computing is based on controlling the register of qubits in the quantum hardware by applying a sequence of gates, a process which can be interpreted as a low level text programming language. We develop a transformer model capable of transpiling quantum circuits from the qasm standard to other sets of gates native suited for a specific target quantum hardware, in our case the set for the trapped-ion quantum computers of IonQ. The feasibility of a translation up to five qubits is demonstrated with a percentage of correctly transpiled target circuits equal or superior to 99.98%. Regardless the depth of the register and the number of gates applied, we prove that the complexity of the transformer model scales, in the worst case scenario, with a polynomial trend by increasing the depth of the register and the length of the circuit, allowing models with a higher number of parameters to be efficiently trained on HPC infrastructures.

Transpiling quantum circuits by a transformers-based algorithm

TL;DR

This work treats quantum circuit transpilation as a seq2seq translation task by employing an encoder–decoder transformer operating on OpenQASM representations. A RegEx-driven tokenizer discretizes continuous rotation angles into symbolic tokens, enabling robust mapping between IBM and IonQ gate sets with cross-attention guiding output generation. The model attains fidelity exceeding for up to five-qubit circuits and demonstrates scaling considerations for continuous versus Solovay-Kitaev–decomposed gates, highlighting the need for larger context windows for long sequences. The approach offers a scalable, automated route for cross-platform quantum compilation, with implications for hardware-aware optimization on HPC infrastructures.

Abstract

Transformers have gained popularity in machine learning due to their application in the field of natural language processing. They manipulate and process text efficiently, capturing long-range dependencies among data and performing the next word prediction. On the other hand, gate-based quantum computing is based on controlling the register of qubits in the quantum hardware by applying a sequence of gates, a process which can be interpreted as a low level text programming language. We develop a transformer model capable of transpiling quantum circuits from the qasm standard to other sets of gates native suited for a specific target quantum hardware, in our case the set for the trapped-ion quantum computers of IonQ. The feasibility of a translation up to five qubits is demonstrated with a percentage of correctly transpiled target circuits equal or superior to 99.98%. Regardless the depth of the register and the number of gates applied, we prove that the complexity of the transformer model scales, in the worst case scenario, with a polynomial trend by increasing the depth of the register and the length of the circuit, allowing models with a higher number of parameters to be efficiently trained on HPC infrastructures.

Paper Structure

This paper contains 24 sections, 27 equations, 9 figures, 1 table.

Figures (9)

  • Figure 1: The input feeding the transformer is provided as a circuit composed by IBM native gates (in the picture, the violet circuit on the top-left). The same circuit is then transpiled by the transformers $\mathcal{T}$ into its IonQ counterpart (orange circuit) engaging the native gates from the trapped ions platform. The same original IBM circuit is thus decomposed through the Solovay-Kitaev algorithm into the universal set of native gates employed by IBM backends, $\{\hat{T}, \hat{T}^\dagger, \hat{H} \}$, then transpiled by the transformers $\mathcal{T}$ into a universal native set of gates suitable for IonQ, i.e. $\{\sqrt{\hat{X}}, \sqrt{\hat{X}}^\dagger, \hat{H} \}$.
  • Figure 2: Pipeline of the proposed architecture. The process refers to the steps composing the $\mathcal{T}$ transformation depicted in Figure \ref{['fig:overallView']}. Starting from the QASM source code (here based on the IBM Eagle backend), the tokenization projects into the embedding latent Euclidean space. Thereafter, the input (i.e. the tokens) is processed throughout the transformer model and eventually decoded into the target QASM (in the following, IonQ).
  • Figure 3: Scheduling with dynamical loss combination, which prioritize the grammar aspect of the learning first and thereafer the physical meaning of the produced QASM. Due to the label smoothing techniques, the cross-entropy loss $\mathcal{L}_{CE}$ never decreases to zero, but converges to a small value $\epsilon>0$.
  • Figure 4: Count of the tokens as the depth of the circuit and as the number of qubits increase. In both cases, the corresponding quantity is kept fixed. In both cases, we observe a linear scaling, just as predicted in Equation \ref{['eq:circuitTokenLength']}.
  • Figure 5: Training metrics overview. (a) Loss evolution throughout the training steps. (b) Grammar accuracy throughout the epochs of training. (c) Circuit fidelity evolution during the training steps. (d) Perplexity evolution during the training epochs.
  • ...and 4 more figures