Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning if no backend provided on cloud channel #1425

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading