Skip to main contentIBM Quantum Documentation Preview
This is a preview build of IBM Quantum™ documentation. Refer to docs.quantum.ibm.com for the official documentation.

Migrate from backend.run to Qiskit Runtime primitives

This guide describes key patterns of behavior and use cases with code examples to help you migrate code from the legacy backend.run interface to use the Qiskit Runtime primitives interface (qiskit-ibm-runtime package).

Notes
  • Because backend.run only returned counts, the direct replacement is Qiskit Runtime SamplerV2. However, if you used manual processing with backend.run to return expectation values, you can now use Qiskit Runtime EstimatorV2 instead.
  • Because both backend.run and the "version 1" primitives are being deprecated, this guide uses only the V2 primitives.

The qiskit-ibm-runtime package provides cloud access to the IBM® QPUs (quantum processing units) through the primitives interface. The backend.run interface coexisted with the original (V1) primitives model as the dedicated “direct hardware access” entry point. With the introduction of the V2 primitives interface, the new SamplerV2 class now fulfills that role. Consequentially, backend.run and qiskit-ibm-provider, which only exposed the backend.run interface, are no longer supported.

The Qiskit Runtime primitives implement the reference Sampler V2 and Estimator V2 interfaces found in qiskit.primitives, and enable capabilities not available with the legacy backend.run interface. These capabilities include application of advanced processing techniques for error suppression and mitigation in Estimator, the ability to efficiently sweep between arrays of parameter value sets or observables in both Sampler and Estimator, and access to the new local testing mode. Additionally, Qiskit Runtime lets users run iterative algorithm circuits back to back (session mode) or in collections of circuits without having to re-queue each job (batch mode). This results in more efficient quantum processor use and reduces the time spent running complex computations.


Why migrate to Qiskit Runtime primitives?

Similar to the early days of classical computers, when developers had to manipulate CPU registers directly, the early interface to QPUs simply returned the raw data coming out of the control electronics. This was not a huge issue when QPUs lived in labs and only allowed direct access by researchers. Acknowledging that most developers would not and should not be familiar with distilling such raw data into 0s and 1s, IBM introduced backend.run, a first abstraction for accessing QPUs in the cloud. This allowed developers to operate on a familiar data format and focus on the bigger picture.

As access to QPUs became more widespread, and with more quantum algorithms being developed, again the need for a higher-level abstraction emerged. In response, IBM introduced the Qiskit primitives interface, which are optimized for two core tasks in quantum algorithm development: expectation value estimation (Estimator) and circuit sampling (Sampler). The goal is once again to help developers to focus more on innovation and less on data conversion.

For backward compatibility, the backend.run interface continues to exist in Qiskit. However, it is no longer supported in Qiskit Runtime after the deprecation period, as most IBM Quantum® users have migrated to V2 primitives due to their improved usability and efficiency.


Basic steps to migrate to primitives

Step 1: Determine which primitive to use

When migrating, the key to writing an equivalent algorithm using primitives is to first identify what minimal unit of information your algorithm is based on:

  • If it uses an expectation value of a certain observable with respect to a quantum state (a real number), you will now use Estimator.

    An expectation value of an observable could be the target quantity in scenarios where knowing a quantum state is not relevant. This often occurs in optimization problems or chemistry applications. For example, when trying to discover the extremal energy of a system.

  • If it uses a probability distribution from sampling the device, you will now use Sampler.

    A probability distribution is often of interest in optimization problems that return a classical bit string, encoding a certain solution to a problem at hand. In these cases, you might be interested in finding a bit string that corresponds to a ket value with the largest probability of being measured from a quantum state, for example.

Step 2: Change imports as necessary

Follow the steps in the appropriate topic to change your import options and other setup information:

Step 3: Replace the call to backend.run with a call to primitives

See these topics for instructions if you are using qiskit-ibm-runtime:

See the following topic for instructions if you are using a third-party provider that only exposes backend.run:


Information to share with your users

The following migration guides can help users with the following tasks:


Next steps