Skip to content

Commit

Permalink
Add warning if no backend provided on cloud channel (#1425)
Browse files Browse the repository at this point in the history
* add warning if no backend provided

* add test and reno

* Update msg & add to base_primitive

* Update reno

* Update releasenotes/notes/require-cloud-backend-38a74144347c735d.yaml

Co-authored-by: Jessie Yu <[email protected]>

---------

Co-authored-by: Jessie Yu <[email protected]>
  • Loading branch information
kt474 and jyu00 authored Feb 27, 2024
1 parent 08e95b6 commit 53db91e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions qiskit_ibm_runtime/base_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .runtime_job import RuntimeJob
from .ibm_backend import IBMBackend
from .utils.default_session import get_cm_session
from .utils.deprecation import issue_deprecation_msg
from .utils.utils import validate_isa_circuits
from .constants import DEFAULT_DECODERS
from .qiskit_runtime_service import QiskitRuntimeService
Expand Down Expand Up @@ -122,6 +123,12 @@ def __init__(
raise ValueError(
"A backend or session must be specified when not using ibm_cloud channel."
)
issue_deprecation_msg(
"Not providing a backend is deprecated",
"0.21.0",
"Passing in a backend will be required, please provide a backend.",
3,
)
# Check if initialized within a IBMBackend session. If so, issue a warning.
if get_cm_provider_session():
warnings.warn(
Expand Down
12 changes: 9 additions & 3 deletions qiskit_ibm_runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .utils.result_decoder import ResultDecoder
from .ibm_backend import IBMBackend
from .utils.default_session import set_cm_session
from .utils.deprecation import deprecate_arguments
from .utils.deprecation import deprecate_arguments, issue_deprecation_msg
from .utils.converters import hms_to_seconds


Expand Down Expand Up @@ -112,8 +112,14 @@ def __init__(
else:
self._service = service

if self._service.channel == "ibm_quantum" and not backend:
raise ValueError('"backend" is required for ``ibm_quantum`` channel.')
if not backend:
if self._service.channel == "ibm_quantum":
raise ValueError('"backend" is required for ``ibm_quantum`` channel.')
issue_deprecation_msg(
"Not providing a backend is deprecated",
"0.21.0",
"Passing in a backend will be required, please provide a backend.",
)

self._instance = None

Expand Down
10 changes: 10 additions & 0 deletions releasenotes/notes/require-cloud-backend-38a74144347c735d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
deprecations:
- |
In a future release, ``backend`` will be a required parameter for :class:`qiskit_ibm_runtime.Sampler`, and
:class:`qiskit_ibm_runtime.Estimator` if ``session`` is not specified,
even when using the ``ibm_cloud`` channel.
It will also be a required parameter for
:class:`qiskit_ibm_runtime.Session` and
:class:`qiskit_ibm_runtime.Batch`.
7 changes: 7 additions & 0 deletions test/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_missing_backend(self):
with self.assertRaises(ValueError):
Session(service=service)

def test_missing_backend_cloud_warning(self):
"""Test warning if no backend provided on cloud channel."""
service = MagicMock()
service.channel = "ibm_cloud"
with self.assertWarns(DeprecationWarning):
Session(service=service)

def test_passing_ibm_backend(self):
"""Test passing in IBMBackend instance."""
backend = MagicMock(spec=IBMBackend)
Expand Down

0 comments on commit 53db91e

Please sign in to comment.