Skip to main contentIBM Quantum Documentation Preview

AI transpiler passes

​ The AI-powered transpiler passes are experimental passes that work as a drop-in replacement of "traditional" Qiskit passes for some transpiling tasks. They often produce better results than existing heuristic algorithms (such as lower depth and CNOT count), but are also much faster than optimization algorithms such as Boolean satisfiability solvers. The AI transpiler passes run on the cloud and are available to IBM Quantum™ Premium Plan users.

Note

This is an experimental feature available only to the IBM Quantum Premium Plan. The AI-powered transpiler passes are in beta release status, subject to change. If you have feedback or want to contact the developer team, please use this Qiskit Slack Workspace channel(opens in a new tab).

The following passes are currently available:

Routing passes

  • AIRouting: Layout selection and circuit routing

Circuit synthesis passes

  • AICliffordSynthesis: Clifford circuit synthesis
  • AILinearFunctionSynthesis: Linear function circuit synthesis
  • AIPermutationSynthesis: Permutation circuit synthesis

To use the AI transpiler passes through our cloud services, install the qiskit-transpiler-service package (see instructions here).


AI routing pass

The AIRouting pass acts both as a layout stage and a routing stage. It can be used within a PassManager as follows:

from qiskit.transpiler import PassManager
from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit.circuit.library import EfficientSU2
 
ai_passmanager = PassManager([
  AIRouting(backend_name="ibm_sherbrooke", optimization_level=2, layout_mode="optimize")
])
 
circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()
 
transpiled_circuit = ai_passmanager.run(circuit)

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. The layout_mode includes the following options:

  • keep: This respects the layout set by the previous transpiler passes (or uses the trivial layout if not set). It is typically only used when the circuit must be run on specific qubits of the device. It often produces worse results because it has less room for optimization.
  • improve: This uses the layout set by the previous transpiler passes as a starting point. It is useful when you have a good initial guess for the layout; for example, for circuits that are built in a way that approximately follows the device's coupling map. It is also useful if you want to try other specific layout passes combined with the AIRouting pass.
  • optimize: This is the default mode. It works best for general circuits where you might not have good layout guesses. This mode ignores previous layout selections.

AI circuit synthesis passes

The AI circuit synthesis passes allow you to optimize pieces of different circuit types (Clifford, Linear Function, Permutation) by re-synthesizing them. A typical way to use the synthesis pass is as follows:

from qiskit.transpiler import PassManager
 
from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit_transpiler_service.ai.synthesis import AILinearFunctionSynthesis
from qiskit_transpiler_service.ai.collection import CollectLinearFunctions
from qiskit.circuit.library import EfficientSU2
 
ai_passmanager = PassManager([
  AIRouting(backend_name="ibm_cairo", optimization_level=3, layout_mode="optimize"),  # Route circuit
  CollectLinearFunctions(),  # Collect Linear Function blocks
  AILinearFunctionSynthesis(backend_name="ibm_cairo")  # Re-synthesize Linear Function blocks
])
 
circuit = EfficientSU2(10, entanglement="full", reps=1).decompose()
 
transpiled_circuit = ai_passmanager.run(circuit)

The synthesis respects the coupling map of the device: it can be run safely 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), but this can be forced 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 nine qubit blocks.
  • AIPermutationSynthesis: Synthesis for Permutation circuits (blocks of SWAP gates). Currently available for 65, 33, and 27 qubit blocks.

We expect to gradually increase the size of the supported blocks.

All passes use a thread pool to send several requests in parallel. By default, the number for max threads is the number of cores plus four (default values for the ThreadPoolExecutor Python object). However, you can set your own value with the max_threads argument at pass instantiation. For example, the following line instantiates the AILinearFunctionSynthesis pass, which allows it to use a maximum of 20 threads.

AILinearFunctionSynthesis(backend_name="ibm_cairo", max_threads=20)  # Re-synthesize Linear Function blocks using 20 threads max

You can also set the environment variable AI_TRANSPILER_MAX_THREADS to the desired number of maximum threads, and all synthesis passes instantiated after that will use that value.

For the AI synthesis passes to synthesize a sub-circuit, it must lay on a connected subgraph of the coupling map (one way to do this is with a routing pass before collecting the blocks, but this is not the only way to do it). The synthesis passes will automatically check that the specific subgraph is supported, and if not, it will raise a warning and leave the original sub-circuit unchanged.

The following custom collection passes for Cliffords, Linear Functions and Permutations that can be imported from qiskit_transpiler_service.ai.collection also complement the synthesis passes:

  • CollectCliffords: Collects Clifford blocks as Instruction objects and stores the original sub-circuit to compare against it after synthesis.
  • CollectLinearFunctions: Collects blocks of SWAP and CX as LinearFunction objects and stores the original sub-circuit to compare against it after synthesis.
  • CollectPermutations: Collects blocks of SWAP circuits as Permutations.

These custom collection passes limit the sizes of the collected sub-circuits so they are supported by the AI-powered synthesis passes. Therefore, it is recommended to use them after the routing passes and before the synthesis passes for a better overall optimization.


Citation

If you use any AI-powered feature from the Qiskit transpiler service in your research, use the recommended citation.