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 2 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
12 changes: 10 additions & 2 deletions qiskit_ibm_runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

"""Qiskit Runtime flexible session."""

import warnings
from typing import Dict, Optional, Type, Union, Callable, Any
from types import TracebackType
from functools import wraps
Expand Down Expand Up @@ -112,8 +113,15 @@ 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.')
warnings.warn(
"In a future release no sooner than 3 months after the release date of "
"qiskit-ibm-runtime version 0.21.0, "
"``backend`` will no longer be optional when using primitives. "
"Please provide a backend."
)
kt474 marked this conversation as resolved.
Show resolved Hide resolved

self._instance = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
deprecations:
- |
In a future release, ``backend`` will be a required argument to :class:`qiskit_ibm_runtime.Session`
and :class:`qiskit_ibm_runtime.Batch` when using the ``ibm_cloud`` channel.
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(UserWarning):
Session(service=service)

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