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-provider | Class in qiskit-ibm-runtime | Notes |
|---|---|---|
| qiskit.providers.ibmq.runtime.IBMRuntimeService | qiskit_ibm_runtime.QiskitRuntimeService | IBMRuntimeService class was removed from qiskit-ibm-runtime 0.6 and replaced by the new class in qiskit-ibm-runtime. |
| qiskit.providers.ibmq.runtime.RuntimeEncoder | qiskit_ibm_runtime.RuntimeEncoder | |
| qiskit.providers.ibmq.runtime.RuntimeDecoder | qiskit_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 QiskitRuntimeServicefrom qiskit import IBMQSave accounts
Use the updated code to work save accounts.
For information about retrieving account credentials, see Set up your IBM Cloud account.
QiskitRuntimeService.save_account(channel="ibm_quantum_platform", token="<API_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_platform", token="<API_TOKEN>", instance="<CRN for premium>", name="premium")
QiskitRuntimeService.save_account(channel="ibm_quantum_platform", token="<API_TOKEN>", instance="<CRN for open>", name="open")
# Load the "open" credentials
service = QiskitRuntimeService(name="open")IBMQ.save_account("<IQX_TOKEN>", overwrite=True)Instance selection (get a provider)
Use the updated code to select an instance.
The new syntax combines the functionality from load_account() and
get_provider() in one statement. Use the instance keyword to specify your Cloud Resource Name (CRN).
# To access saved credentials for the IBM quantum channel and select an instance
service = QiskitRuntimeService(channel="ibm_quantum_platform", instance="<CRN>")Get a backend
Use the updated code to specify a backend.
service = QiskitRuntimeService(instance="<CRN>")
backend = service.backend("<QPU-name>")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()provider = IBMQ.get_provider(hub="h1", group="g1", project="p1")
backend = provider.get_backend("ibm_backend")