Compare transpiler settings
Estimated QPU usage: 10 seconds (tested on IBM Nazca)
Background
To ensure faster and more efficient results, as of 1 March 2024, circuits and observables need to be transformed to only use instructions supported by the QPU (quantum processing unit) before being submitted to the Qiskit Runtime primitives. We call these instruction set architecture (ISA) circuits and observables. One common way to do this is to use the transpiler's
For example, you might want to target a specific subset of qubits on a specific device. This tutorial tests the performance of different transpiler settings by completing the full process of creating, transpiling, and submitting circuits.
Requirements
Before starting this tutorial, ensure that you have the following installed:
- Qiskit SDK 1.2 or later, with visualization support (
pip install 'qiskit[visualization]' ) - Qiskit Runtime 0.28 or later (
pip install qiskit-ibm-runtime ) 0.22 or later
Step 1. Map classical inputs to a quantum problem
Create a small circuit for the transpiler to try to optimize. This example creates a circuit that carries out Grover's algorithm with an oracle that marks the state
Setup
No output produced
Output:
'ibm_kyoto'
Output:
Output:
Step 2. Optimize problem for quantum execution
Next, transpile the circuits for the QPU. You will compare the performance of the transpiler with
The following cell transpiles
Output:
Two-qubit gates (optimization_level=0): 21
Two-qubit gates (optimization_level=3): 14
Since CNOTs usually have a high error rate, the circuit transpiled with
Another way you can improve performance is through dynamic decoupling, by applying a sequence of gates to idling qubits. This cancels out some unwanted interactions with the environment. The following cell adds dynamic decoupling to the circuit transpiled with
No output produced
Output:
Step 3. Execute using Qiskit Primitives
At this point, you have a list of circuits transpiled for the specified QPU. Next, create an instance of the sampler primitive and start a batched job using the context manager (
Within the context manager, sample the circuits and store the results to
No output produced
Step 4. Post-process, return result in classical format
Finally, plot the results from the device runs against the ideal distribution. You can see the results with
Output:
You can confirm this by computing the Hellinger fidelity between each set of results and the ideal distribution (higher is better, and 1 is perfect fidelity).
Output:
0.848
0.945
0.990
Tutorial Survey
Tutorial Survey Please take one minute to provide feedback on this tutorial. Your insights will help us improve our content offerings and user experience. |
Was this page helpful?