Skip to content

Commit

Permalink
Enable loading experiments using the runtime service (#1386)
Browse files Browse the repository at this point in the history
### Summary

Follow up to #1371 . `ExperimentData.load()` currently requires the
deprecated `qiskit-ibm-provider` provider to load an experiment. This PR
allows the provider parameter to take in the `QiskitRuntimeService`
service as well. Unfortunately, this is confusing since the experiment
service is another parameter for `load()`. We should probably drop the
experiment service parameter in a future release and only accept the
`QiskitRuntimeService` service.

---------

Co-authored-by: Will Shanks <[email protected]>
  • Loading branch information
coruscating and wshanks authored Feb 6, 2024
1 parent 36c06ea commit 777e2d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
5 changes: 2 additions & 3 deletions docs/howtos/cloud_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ experiment <https://quantum.ibm.com/experiments/9640736e-d797-4321-b063-d503f8e9

.. jupyter-input::

from qiskit_experiments.framework.experiment_data import ExperimentData
service = ExperimentData.get_service_from_backend(backend)
load_expdata = ExperimentData.load("9640736e-d797-4321-b063-d503f8e98571", service)
from qiskit_experiments.framework import ExperimentData
load_expdata = ExperimentData.load("9640736e-d797-4321-b063-d503f8e98571", provider=service)

Now we can display the figure from the loaded experiment data:

Expand Down
27 changes: 19 additions & 8 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,14 +1090,23 @@ def _retrieve_data(self):
jobs_to_retrieve.append(jid)

for jid in jobs_to_retrieve:
try:
LOG.debug("Retrieving job [Job ID: %s]", jid)
job = self.provider.retrieve_job(jid)
LOG.debug("Retrieving job [Job ID: %s]", jid)
try: # qiskit-ibm-runtime syntax
job = self.provider.job(jid)
retrieved_jobs[jid] = job
except AttributeError: # TODO: remove this path for qiskit-ibm-provider
try:
job = self.provider.retrieve_job(jid)
retrieved_jobs[jid] = job
except Exception: # pylint: disable=broad-except
LOG.warning(
"Unable to retrieve data from job [Job ID: %s]: %s",
jid,
traceback.format_exc(),
)
except Exception: # pylint: disable=broad-except
LOG.warning(
"Unable to retrieve data from job [Job ID: %s]",
jid,
"Unable to retrieve data from job [Job ID: %s]: %s", jid, traceback.format_exc()
)
# Add retrieved job objects to stored jobs and extract data
for jid, job in retrieved_jobs.items():
Expand Down Expand Up @@ -2246,7 +2255,9 @@ def load(
experiment_id: Experiment ID.
service: the database service.
provider: an IBMProvider required for loading job data and
can be used to initialize the service.
can be used to initialize the service. In ``qiskit-ibm-runtime``,
this is the ``QiskitRuntimeService`` and should not be confused with
the experiment database service.
Returns:
The loaded experiment data.
Expand All @@ -2256,7 +2267,7 @@ def load(
if service is None:
if provider is None:
raise ExperimentDataError(
"Loading an experiment requires a valid ibm provider or experiment service"
"Loading an experiment requires a valid Qiskit provider or experiment service."
)
service = cls.get_service_from_provider(provider)
data = service.experiment(experiment_id, json_decoder=cls._json_decoder)
Expand Down Expand Up @@ -2550,7 +2561,7 @@ def get_service_from_provider(provider):
if hasattr(provider, "_account"):
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.",
"for qiskit-ibm-provider backends will be removed in Qiskit Experiments 0.7.",
DeprecationWarning,
stacklevel=2,
)
Expand Down

0 comments on commit 777e2d5

Please sign in to comment.