Skip to main contentIBM Quantum Documentation

Migrate from qiskit_ibmq_provider

This topic describes how to migrate code from the legacy IBMQ provider qiskit-ibmq-provider package to use Qiskit Runtime qiskit-ibm-runtime.


Changes in Class name and location

The classes related to Qiskit Runtime that were included in qiskit-ibmq-provider are now part of qiskit-ibm-runtime. Previously, the provider populated the qiskit.providers.ibmq.runtime namespace with objects for Qiskit Runtime. These now live in the qiskit_ibm_runtime module.

The following table contains example access patterns in qiskit.providers.ibmq.runtime and their new form in qiskit_ibm_runtime:

Class in qiskit-ibmq-providerClass in qiskit-ibm-runtimeNotes
qiskit.providers.ibmq.runtime.IBMRuntimeServiceqiskit_ibm_runtime.QiskitRuntimeServiceIBMRuntimeService class was removed from qiskit-ibm-runtime 0.6 and replaced by the new class in qiskit-ibm-runtime.
qiskit.providers.ibmq.runtime.RuntimeEncoderqiskit_ibm_runtime.RuntimeEncoder
qiskit.providers.ibmq.runtime.RuntimeDecoderqiskit_ibm_runtime.RuntimeDecoder

The following classes were used for custom programs, which are no longer supported. Therefore, the classes are no longer supported:

  • qiskit.providers.ibmq.runtime.RuntimeProgram
  • qiskit.providers.ibmq.runtime.UserMessenger
  • qiskit.providers.ibmq.runtime.ProgramBackend
  • qiskit.providers.ibmq.runtime.ResultDecoder
  • qiskit.providers.ibmq.runtime.ParameterNamespace

Import path

The import path has changed as follows:

from qiskit_ibm_runtime import QiskitRuntimeService

Save accounts

Use the updated code to work save accounts.

The new syntax accepts credentials for Qiskit Runtime on IBM Cloud or IBM Quantum Platform. For more information on retrieving account credentials, see Select and set up an IBM Quantum channel.

# IBM Quantum channel; set to default 
 
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<IQP_TOKEN>", overwrite=True, set_as_default=True)

Additionally, you can now name your saved credentials and load the credentials by name.

# Save different accounts for open and premium access
 
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<IQX_TOKEN>", instance="h1/g1/p1", name="premium")
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<IQX_TOKEN>", instance="h2/g2/p2", name="open")
 
# Load the "open" credentials
 
service = QiskitRuntimeService(name="open")

Load accounts

Use the updated code to load accounts.

The channel input parameter is optional. If multiple accounts have been saved in one device and no channel is provided, the default is "ibm_cloud".

# To access saved credentials for the IBM cloud channel
service = QiskitRuntimeService(channel="ibm_cloud")
 
# To access saved credentials for the IBM quantum channel
service = QiskitRuntimeService(channel="ibm_quantum")

Instance selection (get a provider)

Use the updated code to select a hub, group, and project.

The new syntax combines the functionality from load_account() and get_provider() in one statement. When using the ibm_quantum channel, the hub, group, and project are specified through the new instance keyword.

# To access saved credentials for the IBM quantum channel and select an instance
service = QiskitRuntimeService(channel="ibm_quantum", instance="my_hub/my_group/my_project")

Get a backend

Use the updated code to specify a backend.

# You can specify the instance in service.backend() instead of initializing a new service
backend = service.backend("ibm_backend", instance="h1/g1/p1")

If you don't know what backend you want to use, you can instead use code such as the following:

from qiskit_ibm_runtime import QiskitRuntimeService
 
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=<num_qubits>)

With Qiskit Runtime, you can also run in local testing mode.

# Define a local backend
from qiskit_ibm_runtime.fake_provider import FakeManilaV2
backend = FakeManilaV2()
 
# You could use an Aer simulator instead by using the following code:
# from qiskit_aer import AerSimulator
# backend = AerSimulator()
Was this page helpful?
Report a bug or request content on GitHub.