Skip to main contentIBM 

Optimize quantum circuits with AI-powered transpiler passes

The Qiskit Transpiler Service beta release is now available on the IBM Quantum Premium Plan, providing users with AI and IBM cloud resources to speed up transpilation tasks.


28 May 2024

David Kremer

Juan Cruz-Benito

Ismael Faro

Robert Davis

We’re thrilled to announce that the beta release of the Qiskit Transpiler Service is now available to all IBM Quantum Premium Plan users.

The Qiskit Transpiler Service leverages the resources of the IBM Cloud to provide users with the latest transpilation capabilities from the Qiskit SDK. It offers a Python library that helps users seamlessly integrate the service into their current Qiskit patterns and workflows. And with the new beta release, the service invites users to experiment with new and improved AI-powered transpiler passes, cutting-edge tools which may be faster and produce better results than traditional transpilation methods.

Transpilation is both an essential process in quantum computing and a challenging optimization problem, where the goal is to take an abstract quantum circuit and rewrite it to match the constraints and characteristics of a specific quantum device. Today, most Qiskit users perform transpilation tasks by running heuristic transpiling algorithms on their local machines, after which they submit their transpiled circuits for remote execution on quantum hardware. Heuristic algorithms are designed to find reasonably good solutions to optimization problems relatively quickly, and are useful for transpiling tasks, where finding a truly optimal solution may require excessive amounts of data storage or computation time.

At IBM Quantum Summit 2023, we introduced our AI-powered transpiler passes for circuit routing and circuit synthesis, foundational tasks in quantum circuit transpilation. We demonstrated how AI methods can produce shorter and shallower circuits than the standard heuristic methods currently available in Qiskit, and we showed that AI-powered transpilation can be much faster than Boolean satisfiability (SAT) solvers and other optimization methods. These capabilities were made available to Premium Plan users as part of the experimental Qiskit Transpiler Service alpha release. With this week’s beta release, we’re making them even better.

Since announcing the transpiler service last year, we’ve been laser-focused on stabilizing the system, enhancing reliability, expanding features to allow for a better fit within the current IBM Quantum stack, and boosting performance. We’ve also been working with our colleagues across the IBM Quantum organization to start enabling the first integrations with the service.

Along the way, we wrote and published a new paper on Arxiv detailing the circuit routing and circuit synthesis tools that make up the AI-powered transpiler passes. Below, we’ll look at those AI-powered passes in more detail, and review key takeaways from the new Arxiv paper. But first, let’s go over some simple examples of how to get started performing full circuit transpilation with the new beta release.

Getting started with the Qiskit Transpiler Service

Let’s say you have an ongoing experiment in Qiskit, and want to begin using the Qiskit Transpiler Service to take advantage of IBM Cloud resources. However, you don’t want to use the new AI-powered transpiler passes because you’d prefer to keep your experiment consistent with the heuristic methods you’ve used in your experiment so far.

Using the transpiler service without AI

In the example below, we’ll create a circuit and call the transpiler service to transpile said circuit with ibm_sherbrooke as the backend_name. We’ll set the optimization_level to 3, and we’ll skip the use of AI for now by setting our ai parameter to ai=False. Choosing this setting for the ai parameter gives us the standard Qiskit SDK transpiler pipelines — levels 1, 2, and 3 — but via the cloud.

Keep in mind that you can only use the backend_name devices your IBM Quantum account allows you to access. The TranspilerService also accepts coupling_map as an optional parameter, but we’ll leave that out of this example for the sake of simplicity. (For more details on the coupling_map parameter, be sure to check our documentation.)

Using the transpiler service with AI

Now let’s give those AI-powered passes a try. To activate the AI-powered transpiler passes, set the ai parameter to ai=True. This gives us transpilation that is built upon the standard Qiskit SDK transpiler pipelines, but integrates the AI-powered passes for improved results. The following example produces and transpiles a circuit much like the example above, but incorporates the AI capabilities:

The best of both worlds

In general, we’ve found that our AI-powered transpiler passes perform at least as well as standard heuristic methods, and in many cases, are much more powerful. However, performance improvements are not guaranteed. Results may vary, and we encourage you to think of the AI-powered passes as being just another method in your toolbox.

Since there may be cases where it’s better to forego the use of AI-powered passes, we’ve developed a third option for the ai parameter that gives users the best of both worlds. Set the ai parameter to ai=auto, and this will enable the system to decide automatically whether to apply the standard Qiskit heuristic passes or the new AI-powered passes based on the particulars of your circuit.

AI routing and circuit synthesis passes

Users can also employ our AI-powered transpiler passes as building blocks in their transpiling routines. The AI-powered passes essentially work as drop-in replacements for traditional Qiskit passes in certain transpiling tasks, such as circuit routing and circuit synthesis. By combining AI-powered passes with heuristic passes, we've found that users of the Qiskit Transpiler Service can reduce two-qubit gate counts by an average of 42 percent.

Let’s take a look at a few examples of the standalone AI-powered passes:

Circuit routing

Circuit routing is an essential step in mapping a quantum circuit or algorithm to a physical device. With the new AI-powered transpiling passes, the AIRouting pass acts both as a layout stage, in which the system determines how qubits on your circuit map to the qubits on the device; and as a routing stage, where the system inserts SWAP gates to make the two-qubit gates in the circuit compatible with the device’s coupling map. You can use the AI-powered passes within a PassManager as follows:

Here, the backend_name determines which backend to route for, the optimization_level (1, 2, or 3) determines the computational effort to spend in the process — higher usually gives better results but takes longer — and the layout_mode specifies how to handle the layout selection.

Circuit synthesis

Circuit synthesis is the process of generating a quantum circuit based on a high-level description of a quantum operator. We can use this method to optimize critical pieces of a circuit. The AI circuit synthesis passes allow you to optimize pieces of different circuit types (Clifford, Linear Function, Permutation) by re-synthesizing them. Here’s an example of how one might typically make use of the synthesis pass:

The AI synthesis passes respect the coupling map of the device, and can be used as an optimization stage that runs after routing. You can safely run it after other routing passes without disturbing the circuit, so the overall circuit will still follow the device restrictions. By default, the synthesis will replace the original sub-circuit only if the synthesized sub-circuit improves the original (currently only checking CNOT count). However, you can force the system to always replace the circuit by setting replace_only_if_better=False.

The following synthesis passes are available from qiskit_transpiler_service.ai.synthesis:

  • AICliffordSynthesis: Synthesis for Clifford circuits (blocks of H, S, and CX gates). Currently up to nine qubit blocks.
  • AILinearFunctionSynthesis: Synthesis for Linear Function circuits (blocks of CX and SWAP gates). Currently up to ten qubit blocks.
  • AIPermutationSynthesis: Synthesis for Permutation circuits (blocks of SWAP gates). Currently available for 65, 33, and 27 qubit blocks.

AI-powered transpiler passes — under the hood

Our new Arxiv paper offers a closer look at the reinforcement learning (RL) methods that enable the AI-powered transpiler passes.

Reinforcement learning is a machine learning paradigm in which algorithms are given the objective of learning some optimal “policy” (i.e., the best course of action) by interacting with an environment. We provide the model with a reward function that rewards or penalizes actions based on their outcomes, and the model chooses the best actions to apply based on the reward and penalty signals it receives from the environment we’ve created. The model’s goal is to maximize the cumulative reward by finding the right action to take each time it interacts with the environment.

RL models are a particularly good fit for transpilation tasks because they are trained by trial and error against a given problem. Other machine learning models are trained on data, which means they can learn to mimic a given dataset, but they don’t really have the ability to outperform the data-generation process. RL models learn from experience, meaning they have the potential to generate algorithms that outperform existing ones.

So, for example, if we want to train a reinforcement learning algorithm for Clifford circuit synthesis, we start by providing the algorithm with a target Clifford as an input. The algorithm selects gates step by step until the target Clifford is reached. During training time, the algorithm may be penalized with -10 points for every CX gate, penalized with -1 point for every 1-qubit gate, and rewarded +1,000 points if the target is reached.

This reward function teaches the algorithm to choose the gates that provide the shortest path to the target circuit. Then, when we actually want to use the algorithm for Clifford synthesis, all we need to do is provide the algorithm with a target circuit. The algorithm handles the rest using the knowledge acquired from the training process.

Get started with AI-powered transpiling today

To begin experimenting with the latest version of the Qiskit Transpiler Service, you’ll first need to make sure you’ve upgraded your dependency to Qiskit SDK version 1.0 or later. If you’re still using Qiskit v0.45 or earlier, be sure to refer to our recent blog on best practices for transitioning to Qiskit v1.0 before making the jump. Once you’ve done that, simply install the qiskit-transpiler-service package:

Keep in mind that, by default, the package will try to authenticate to IBM Quantum services, much like the authentication process that takes place when you submit quantum jobs to IBM Quantum services via the Qiskit SDK. To submit your quantum circuits to the Qiskit Transpiler Service, you’ll just need to make sure you’ve configured your IBM Quantum token for Qiskit.

We hope our Premium Plan users will begin experimenting with AI-powered transpiler passes to see how these new tools might help improve their experiments. For more details on the transpiling options introduced with the new Qiskit Transpiler Service beta release, and for more example code showing how to make use of the new AI-powered passes, explore our documentation, here and here.


View documentation