Skip to content

Commit

Permalink
Deprecate qiskit-ibm-provider in favor of qiskit-ibm-runtime (qis…
Browse files Browse the repository at this point in the history
…kit-community#1371)

### Summary

Closes qiskit-community#1346 by adding logic to handle the HGP and service for a
`qiskit-ibm-runtime` backend object and replacing mentions of
`qiskit-ibm-provider` in docs with `qiskit-ibm-runtime` syntax.

### Details and comments

- Updates sessions howto with the new sessions syntax supported by
`qiskit-ibm-runtime` (requires >=15.0)
- Removes old code to handle `qiskit-ibmq-runtime` backends
- Replaces non-free/deprecated backends in docs with `ibm-osaka`

---------

Co-authored-by: Will Shanks <[email protected]>
  • Loading branch information
coruscating and wshanks authored Jan 25, 2024
1 parent e648bc5 commit 4ea9cf6
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 61 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
"matplotlib": ("https://matplotlib.org/stable/", None),
"qiskit": ("https://qiskit.org/documentation/", None),
"uncertainties": ("https://pythonhosted.org/uncertainties", None),
"qiskit_ibm_provider": ("https://qiskit.org/ecosystem/ibm-provider/", None),
"qiskit_aer": ("https://qiskit.org/ecosystem/aer", None),
"qiskit_dynamics": ("https://qiskit.org/documentation/dynamics", None),
"qiskit_ibm_runtime": ("https://qiskit.org/ecosystem/ibm-runtime/", None),
Expand Down
13 changes: 7 additions & 6 deletions docs/howtos/cloud_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ Saving
~~~~~~

.. note::
This guide requires :mod:`qiskit-ibm-provider`. For how to migrate from the deprecated :mod:`qiskit-ibmq-provider` to :mod:`qiskit-ibm-provider`,
consult the `migration guide <https://qiskit.org/ecosystem/ibm-provider/tutorials/Migration_Guide_from_qiskit-ibmq-provider.html>`_.\
This guide requires :mod:`qiskit-ibm-runtime` version 0.15 and up, which can be installed with ``python -m pip install qiskit-ibm-runtime``.
For how to migrate from the older :mod:`qiskit-ibm-provider` to :mod:`qiskit-ibm-runtime`,
consult the `migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime-from-provider>`_.\

You must run the experiment on a real IBM
backend and not a simulator to be able to save the experiment data. This is done by calling
:meth:`~.ExperimentData.save`:

.. jupyter-input::

from qiskit_ibm_provider import IBMProvider
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_experiments.library.characterization import T1
import numpy as np

provider = IBMProvider()
backend = provider.get_backend("ibmq_lima")
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibm_osaka")

t1_delays = np.arange(1e-6, 600e-6, 50e-6)

Expand Down Expand Up @@ -142,7 +143,7 @@ The :meth:`~.ExperimentData.auto_save` feature automatically saves changes to th
.. jupyter-output::

You can view the experiment online at https://quantum.ibm.com/experiments/cdaff3fa-f621-4915-a4d8-812d05d9a9ca
<ExperimentData[T1], backend: ibmq_lima, status: ExperimentStatus.DONE, experiment_id: cdaff3fa-f621-4915-a4d8-812d05d9a9ca>
<ExperimentData[T1], backend: ibm_osaka, status: ExperimentStatus.DONE, experiment_id: cdaff3fa-f621-4915-a4d8-812d05d9a9ca>

Setting ``auto_save = True`` works by triggering :meth:`.ExperimentData.save`.

Expand Down
6 changes: 3 additions & 3 deletions docs/howtos/rerun_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Solution
--------

.. note::
Some of this guide uses the :mod:`qiskit-ibm-provider` package. For how to migrate from
the deprecated ``qiskit-ibmq-provider`` to ``qiskit-ibm-provider``, consult the
`migration guide <https://qiskit.org/ecosystem/ibm-provider/tutorials/Migration_Guide_from_qiskit-ibmq-provider.html>`_.\
This guide requires :mod:`qiskit-ibm-runtime` version 0.15 and up, which can be installed with ``python -m pip install qiskit-ibm-runtime``.
For how to migrate from the older :mod:`qiskit-ibm-provider` to :mod:`qiskit-ibm-runtime`,
consult the `migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime-from-provider>`_.\

Once you recreate the exact experiment you ran and all of its parameters and options,
you can call the :meth:`.add_jobs` method with a list of :class:`Job
Expand Down
29 changes: 16 additions & 13 deletions docs/howtos/runtime_sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,35 @@ You want to run experiments in a `Runtime session
Solution
--------

Use the :class:`~qiskit_ibm_provider.IBMBackend` object in ``qiskit-ibm-provider``, which supports sessions.
.. note::
This guide requires :mod:`qiskit-ibm-runtime` version 0.15 and up, which can be installed with ``python -m pip install qiskit-ibm-runtime``.
For how to migrate from the older :mod:`qiskit-ibm-provider` to :mod:`qiskit-ibm-runtime`,
consult the `migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime-from-provider>`_.\

Use the :class:`~qiskit_ibm_runtime.IBMBackend` object in :mod:`qiskit-ibm-runtime`, which supports sessions.

In this example, we will set the ``max_circuits`` property to an artificially low value so that the experiment will be
split into multiple jobs that run sequentially in a single session. When running real experiments with a
large number of circuits that can't fit in a single job, it may be helpful to follow this usage pattern:

.. jupyter-input::

from qiskit_ibm_provider import IBMProvider
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_experiments.library.tomography import ProcessTomography
from qiskit import QuantumCircuit

provider = IBMProvider()
backend = provider.get_backend("ibm_nairobi")
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibm_osaka")
qc = QuantumCircuit(1)
qc.x(0)

with backend.open_session() as session:
exp = ProcessTomography(qc)
exp.set_experiment_options(max_circuits=3)
exp_data = exp.run(backend)
exp_data.block_for_results()
# Calling cancel because session.close() is not available for qiskit-ibm-provider<=0.7.2.
# It is safe to call cancel since block_for_results() ensures there are no outstanding jobs
# still running that would be canceled.
session.cancel()
backend.open_session()
exp = ProcessTomography(qc)
# Artificially lower circuits per job, adjust value for your own application
exp.set_experiment_options(max_circuits=3)
exp_data = exp.run(backend)
# This will prevent further jobs from being submitted without terminating current jobs
backend.close_session()

Note that runtime primitives are not currently supported natively in Qiskit Experiments, so
the ``backend.run()`` path is required to run experiments.
34 changes: 22 additions & 12 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import sys
import json
import traceback
import warnings
import numpy as np
import pandas as pd
from dateutil import tz
Expand Down Expand Up @@ -652,16 +653,15 @@ def _set_backend(self, new_backend: Backend, recursive: bool = True) -> None:
provider = self._backend_data.provider
if provider is not None:
self._set_hgp_from_provider(provider)
# qiskit-ibm-runtime style
elif hasattr(self._backend, "_instance"):
self.hgp = self._backend._instance
if recursive:
for data in self.child_data():
data._set_backend(new_backend)

def _set_hgp_from_provider(self, provider):
try:
# qiskit-ibmq-provider style
if hasattr(provider, "credentials"):
creds = provider.credentials
self.hgp = f"{creds.hub}/{creds.group}/{creds.project}"
# qiskit-ibm-provider style
if hasattr(provider, "_hgps"):
for hgp_string, hgp in provider._hgps.items():
Expand Down Expand Up @@ -2528,21 +2528,31 @@ def __getstate__(self):
@staticmethod
def get_service_from_backend(backend):
"""Initializes the service from the backend data"""
return ExperimentData.get_service_from_provider(backend.provider)
# qiskit-ibm-runtime style
try:
if hasattr(backend, "service"):
token = backend.service._account.token
return IBMExperimentService(token=token, url=backend.service._account.url)
return ExperimentData.get_service_from_provider(backend.provider)
except Exception: # pylint: disable=broad-except
return None

@staticmethod
def get_service_from_provider(provider):
"""Initializes the service from the provider data"""
db_url = "https://auth.quantum.ibm.com/api"
try:
# qiskit-ibmq-provider style
if hasattr(provider, "credentials"):
token = provider.credentials.token
# qiskit-ibm-provider style
if hasattr(provider, "_account"):
token = provider._account.token
service = IBMExperimentService(token=token, url=db_url)
return service
warnings.warn(
"qiskit-ibm-provider has been deprecated in favor of qiskit-ibm-runtime. Support"
"for qiskit-ibm-provider backends will be removed in Qiskit Experiments 0.6.",
DeprecationWarning,
stacklevel=2,
)
return IBMExperimentService(
token=provider._account.token, url=provider._account.url
)
return None
except Exception: # pylint: disable=broad-except
return None

Expand Down
11 changes: 11 additions & 0 deletions releasenotes/notes/runtime-provider-support-5358b72ec0035419.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
features:
- |
Experiments run via the ``qiskit-ibm-runtime`` provider can now be saved
to the cloud service.
upgrade:
- |
With the impending deprecation of the ``qiskit-ibm-provider`` package, support for
``qiskit-ibm-provider`` is now deprecated and will be removed
in the next release. Users should migrate to ``qiskit-ibm-runtime`` following the
`migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime-from-provider>`.
1 change: 0 additions & 1 deletion requirements-extras.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
qiskit-ibm-provider>=0.6.1 # for submitting experiments to backends through the IBM provider
cvxpy>=1.3.2 # for tomography
scikit-learn # for discriminators
qiskit-aer>=0.13.2
Expand Down
Loading

0 comments on commit 4ea9cf6

Please sign in to comment.