Learning Home Catalog Composer
Learning
Home Catalog Composer Return to tutorial
Learning
Combine error mitigation options with the estimator primitive
RequirementsQiskit Pattern workflowStep 1: Map classical inputs to a quantum problemStep 2: Optimize circuits for quantum hardware executionStep 3: Execute circuits using the Estimator primitiveStep 4: Post-process and return results in classical formatScale the experiment upConclusion

Combine error mitigation options with the estimator primitive

Category

Workflow example

Topics

Error mitigationQiskit Patterns
Download notebook Download notebook

Estimated QPU usage: 8 minutes (tested on IBM Sherbrooke)

In this tutorial, you'll explore the error suppression and error mitigation options available with the Estimator primitive from Qiskit Runtime. You will construct a circuit and observable and submit jobs using the Estimator primitive using different combinations of error mitigation settings. Then, you will plot the results to observe the effects of the various settings. Most of the tutorial uses a 10-qubit circuit to make visualizations easier, and at the end, you can scale up the workflow to 50 qubits.

These are the error suppression and mitigation options you will use:

  • Dynamical decoupling
  • Measurement error mitigation
  • Gate twirling
  • Zero-noise extrapolation (ZNE)

Requirements

Before starting this tutorial, ensure that you have the following installed:

  • Qiskit SDK 1.0 or later with visualization support (pip install 'qiskit[visualization]')
  • Qiskit Runtime 0.22 or later (pip install qiskit-ibm-runtime)

Qiskit Pattern workflow

The four steps of a Qiskit Pattern provide a framework for the workflow in this tutorial.

Step 1: Map classical inputs to a quantum problem

This tutorial assumes that the classical problem has already been mapped to quantum. Begin by constructing a circuit and observable to measure. While the techniques used in this tutorial apply to many different kinds of circuits, for simplicity this tutorial uses the EfficientSU2 circuit included in Qiskit's circuit library.

EfficientSU2 is a parameterized quantum circuit designed to be efficiently executable on quantum hardware with limited qubit connectivity, while still being expressive enough to solve problems in application domains like optimization and chemistry. It's built by alternating layers of parameterized single-qubit gates with a layer containing a fixed pattern of two-qubit gates, for a chosen number of repetitions. The pattern of two-qubit gates can be specified by the user. Here you can use the built-in pairwise pattern because it minimizes the circuit depth by packing the two-qubit gates as densely as possible. This pattern can be executed using only linear qubit connectivity.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

For our observable, let's take the Pauli ZZ operator acting on the last qubit, ZIIZ I \cdots I.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

No output produced

At this point, you could proceed to run your circuit and measure the observable. However, you also want to compare the output of the quantum device with the correct answer - that is, the theoretical value of the observable, if the circuit had been executed without error. For small quantum circuits you can calculate this value by simulating the circuit on a classical computer, but this is not possible for larger, utility-scale circuits. You can work around this issue with the "mirror circuit" technique (also known as "compute-uncompute"), which is useful for benchmarking the performance of quantum devices.

Mirror circuit

In the mirror circuit technique, you concatenate the circuit with its inverse circuit, which is formed by inverting each gate of the circuit in reverse order. The resulting circuit implements the identity operator, which can trivially be simulated. Because the structure of the original circuit is preserved in the mirror circuit, executing the mirror circuit still gives an idea of how the quantum device would perform on the original circuit.

The following code cell assigns random parameters to your circuit, and then constructs the mirror circuit using the UnitaryOverlap class. Before mirroring the circuit, append a barrier instruction to it to prevent the transpiler from merging the two parts of the circuit on either side of the barrier. Without the barrier, the transpiler would merge the original circuit with its inverse, resulting in a transpiled circuit without any gates.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

Step 2: Optimize circuits for quantum hardware execution

You must optimize your circuit before running it on hardware. This process involves a few steps:

  • Pick a qubit layout that maps the virtual qubits of your circuit to physical qubits on the hardware.
  • Insert swap gates as needed to route interactions between qubits that are not connected.
  • Translate the gates in your circuit to Instruction Set Architecture (ISA) instructions that can directly be executed on the hardware.
  • Perform circuit optimizations to minimize the circuit depth and gate count.

The transpiler built into Qiskit can perform all of these steps for you. Because this tutorial uses a hardware-efficient circuit, the transpiler should be able to pick a qubit layout that does not require any swap gates to be inserted for routing interactions.

You need to choose the hardware device to use before you optimize your circuit. The following code cell requests the least busy device with at least 127 qubits.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

No output produced

You can transpile your circuit for your chosen backend by creating a pass manager and then running the pass manager on the circuit. An easy way to create a pass manager is to use the generate_preset_pass_manager function. See Transpile with pass managers for a more detailed explanation of transpiling with pass managers.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

The transpiled circuit now contains only ISA instructions. The single-qubit gates have been decomposed in terms of X\sqrt{X} gates and RzR_z rotations, and the CX gates have been decomposed into ECR gates and single-qubit rotations.

The transpilation process has mapped the virtual qubits of the circuit to physical qubits on the hardware. The information about the qubit layout is stored in the layout attribute of the transpiled circuit. The observable was also defined in terms of the virtual qubits, so you need to apply this layout to the observable, which you can do with the apply_layout method of SparsePauliOp.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

Original observable:
SparsePauliOp(['ZIIIIIIIII'],
              coeffs=[1.+0.j])

Observable with layout applied:
SparsePauliOp(['IIZIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'],
              coeffs=[1.+0.j])

Step 3: Execute circuits using the Estimator primitive

You are now ready to run your circuit using the Estimator primitive.

Here you will submit five separate jobs, starting with no error suppression or mitigation, and successively enabling various error suppression and mitigation options available in Qiskit Runtime. For information about the options, refer to the following pages:

Because these jobs can run independently of each other, you can use batch mode to allow Qiskit Runtime to optimize the timing of their execution.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

No output produced

Step 4: Post-process and return results in classical format

Finally, you can analyze the data. Here you will retrieve the job results, extract the measured expectation values from them, and plot the values, including error bars of one standard deviation.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

At this small scale, it is difficult to see the effect of most of the error mitigation techniques, but zero-noise extrapolation does give a noticeable improvement. However, note that this improvement does not come for free, because the ZNE result also has a larger error bar.

Scale the experiment up

When developing an experiment, it's useful to start with a small circuit to make visualizations and simulations easier. Now that you've developed and tested our workflow on a 10-qubit circuit, you can scale it up to 50 qubits. The following code cell repeats all of the steps in this tutorial, but now applies them to a 50-qubit circuit.

Run
The ability to run code cells is currently disabled.
Copy to clipboard

Output:

When you compare the 50-qubit results with the 10-qubit results from earlier, you might note the following (your results might differ across runs):

  • The results without error mitigation are worse. Running the larger circuit involves executing more gates, so there are more opportunities for errors to accumulate.
  • The addition of dynamical decoupling might have worsened performance. This is not surprising, because the circuit is very dense. Dynamical decoupling is primarily useful when there are large gaps in the circuit during which qubits sit idle without gates being applied to them. When these gaps are not present, dynamical decoupling is not effective, and can actually worsen performance due to errors in the dynamical decoupling pulses themselves. The 10-qubit circuit may have been too small for us to observe this effect.
  • With zero-noise extrapolation, the result is as good, or nearly as good, as the 10-qubit result, though the error bar is much larger. This demonstrates the power of the ZNE technique!

Conclusion

In this tutorial, you investigated different error mitigation options available for the Qiskit Runtime Estimator primitive. You developed a workflow using a 10-qubit circuit, and then scaled it up to 50 qubits. You might have observed that enabling more error suppression and mitigation options doesn't always improve performance (specifically, enabling dynamical decoupling in this case). Most of the options accept additional configuration, which you can test out in your own work!