Learning Home Catalog Composer
Learning
Home Catalog Composer
Tutorials

Building workflows with the IBM Circuit function

Building workflows with the IBM Circuit function

Estimated QPU usage: 26 minutes (tested on IBM Brisbane)

In this notebook, we will walk through an example of building and running a workflow using the IBM Circuit function. This function takes Primitive Unified Blocs (PUBs) as inputs and returns error-mitigated expectation values as outputs. It provides an automated and customized pipeline to optimize circuits and execute on quantum hardware so that researchers can focus on algorithm and application discovery.

Visit the documentation for an introduction to Qiskit Functions and learn how to get started with the IBM Circuit function.

Requirements

Before starting this tutorial, be sure you have the following installed:

  • Qiskit SDK 1.2 or later (pip install qiskit)
  • Qiskit Runtime 0.28 or later (pip install qiskit-ibm-runtime)
  • IBM Qiskit Functions Catalog client 0.0.0 or later (pip install qiskit-ibm-catalog)
  • Qiskit Aer 0.15.0 or later (pip install qiskit-aer)

Build the Qiskit pattern

We implement the example workflow using the Qiskit pattern as a guide. For this tutorial, we consider a general hardware-efficient Trotterized time evolution circuit for the 2D tranverse-field Ising model and compute the global magnetization. Such a circuit is useful in different application domains such as condensed matter physics, chemistry, machine learning etc. For more information on the structure of this model, refer to Nature 618, 500–505 (2023).

The IBM Circuit function combines capabilities from the Qiskit transpiler service and Qiskit Runtime Estimator to provide a simplified interface for running circuits. The function performs transpilation, error suppresion, error mitigation, and circuit execution within a single managed service so that we can focus on mapping the problem to circuits rather than building out each step of the pattern ourselves.

Step 1. Map classical inputs to a quantum problem

  • Input: Parameters to create the quantum circuit
  • Output: Abstract circuit and observables

Construct the circuit

The circuit we will create is a hardware-efficient, Trotterized time evolution circuit for the 2D transverse-field Ising model. We start with selecting a backend. Properties of this backend (i.e., its coupling map) will be used to define the quantum problem and ensure it is hardware-efficient.

Copy to clipboard

No output produced

Next, we get the coupling map from the backend.

Copy to clipboard

No output produced

We want to be careful in how we design the layers of our circuit. We will do this by coloring the edges of the coupling map (i.e., grouping the disjoint edges) and use that coloring to more efficiently place gates in the circuit. This will lead to a shallower circuit with layers of gates that can be executed simultaneously on the hardware.

Copy to clipboard

No output produced

Next, we write a simple helper function that implements the hardware-efficient, Trotterized time evolution circuit for the 2D transverse-field Ising model using the edge coloring obtained above.

Copy to clipboard

No output produced

We will choose the number of qubits and trotter steps and then construct the circuit.

Copy to clipboard

Output:

In order to benchmark the quality of the execution, we need to compare it with the ideal outcome. The circuit of choice is beyond brute force classical simulation. So, we fix the parameters of all the Rx gates in the circuit to 00, and that of all Rzz gates to π\pi. This makes the circuit Clifford, which makes it possible to perform the ideal simulation and obtain the ideal outcome for comparison. In this case, we know that outcome will be 1.0.

Copy to clipboard

No output produced

Construct the observable

In this tutorial, we will compute the global magnetization along z^\hat{z} for our NN-qubit problem: Mz=i=1NZi/NM_z = \sum_{i=1}^N \langle Z_i \rangle / N. This requires first computing the single-site magnetization Zi\langle Z_i \rangle for each qubit ii, which we define below.

Copy to clipboard

Output:

SparsePauliOp(['ZIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'],
              coeffs=[1.+0.j])

Steps 2 and 3: Optimize problem and execute with the IBM Circuit function

  • Input: Abstract circuit and observables
  • Output: Mitigated expectation values

Now, we can pass the abstract circuit and observables to the IBM Circuit function. It will handle transpilation and execution on quantum hardware for us and return mitigated expectation values. First, we load the function from the IBM Qiskit Functions Catalog.

Copy to clipboard

No output produced

The IBM Circuit function takes pubs, backend_name, as well as optional inputs for configuring transpilation, error mitigation, etc. We create the pub from the abstract circuit, observables, and circuit paramters. The name of the backend should be specified as a string.

Copy to clipboard

No output produced

We can also configure the options for transpilation, error suppression, and error mitigation. Default settings will be used if we don't wish to specify these. The IBM Circuit function comes with commonly used options for optimization_level, which controls how much circuit optimization to perform, and mitigation_level, which specifies how much error suppression and mitigation to apply. Note that the mitigation_level of the IBM Circuit function is distinct from the resilience_level used in the Qiskit Runtime Estimator. For a detailed description of these commonly used options as well as other advanced options, visit the documentation for the IBM Circuit function.

In this tutorial, we will set the default_precision, optimization_level: 3 and mitigation_level: 3, which will turn on gate twirling and Zero Noise Extrapolation (ZNE) via Probabilistic Error Amplification (PEA) on top of the default level 1 settings.

Copy to clipboard

No output produced

With the inputs specified, we submit the job to the IBM Circuit function for optimization and execution.

Copy to clipboard

No output produced

Step 4: Post-process results

  • Input: Results from the IBM Circuit function
  • Output: Global magnetization

Compute the global magnetization

The result from running the function has the same format as the Estimator.

Copy to clipboard

No output produced

We obtain the mitigated and non-mitigated expectation values from this result. These expectation values represent the single-site magnetization along the z^\hat{z} direction. We average these to arrive at the global magnetization and compare against the ideal value of 1.0 for this problem instance.

Copy to clipboard

Output:

mitigated: 0.9749883476088692
unmitigated: 0.7832977198447583

Tutorial Survey

SurveyTutorial 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?