Migrate setup from qiskit-ibmq-provider
¶
This guide describes how to migrate code from the legacy IBMQ provider (qiskit-ibmq-provider) package to use Qiskit Runtime (qiskit-ibm-runtime). This guide includes instructions to migrate legacy runtime programs to the new syntax. However, the ability to use custom uploaded programs is pending deprecation, so these should be migrated to use primitives instead.
Changes in Class name and location¶
The classes related to Qiskit Runtime that used to be included in qiskit-ibmq-provider
are now part of qiskit-ibm-runtime
. Before, the provider used to populate the qiskit.providers.ibmq.runtime
namespace with objects for Qiskit Runtime. These now live in the qiskit_ibm_runtime
module.
The module from which the classes are imported has changed. The following table contains example access patterns in qiskit.providers.ibmq.runtime
and their new form in qiskit_ibm_runtime
:
class in |
class in |
Notes |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Notice the new location, in |
|
|
Notice the new location, in |
|
|
Notice the new location, in |
|
|
|
|
|
|
|
|
|
|
|
Import path¶
The import path has changed as follows:
Legacy
from qiskit import IBMQ
Updated
from qiskit_ibm_runtime import QiskitRuntimeService
Save and load accounts¶
Use the updated code to work with accounts.
Legacy - Save accounts
IBMQ.save_account("<IQX_TOKEN>", overwrite=True)
Updated - Save accounts The new syntax accepts credentials for Qiskit Runtime on IBM Cloud or IBM Quantum Platform. For more information about retrieving account credentials, see the getting started guide.
# IBM cloud channel
QiskitRuntimeService.save_account(channel="ibm_cloud", token="<IBM Cloud API key>", instance="<IBM Cloud CRN>", overwrite=True)
# IBM quantum channel
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<IQP_TOKEN>", overwrite=True)
Updated - Name saved credentials You can now name your saved credentials and load the credentials by name.
Example:
# 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")
Legacy - Load accounts
IBMQ.load_account()
Updated - Load accounts
The new syntax combines the functionality from load_account()
and get_provider()
in one statement. 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")
Channel selection (get a provider)¶
Use the updated code to select a channel.
Legacy
provider = IBMQ.get_provider(project="my_project", group="my_group", hub="my_hub")
Updated
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 cloud channel
service = QiskitRuntimeService(channel="ibm_cloud")
# 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 the backend¶
Use the updated code to view backends.
Legacy
provider = IBMQ.get_provider(hub="h1", group="g1", project="p1")
backend = provider.get_backend("ibm_backend")
Updated
# You can specify the instance in service.backend() instead of initializing a new service
backend = service.backend("ibm_backend", instance="h1/g1/p1")