Skip to content

Commit

Permalink
Deprecate passing backend as a string (#1804)
Browse files Browse the repository at this point in the history
* Deprecate passing backend as a string

* add release note
  • Loading branch information
kt474 authored Jul 17, 2024
1 parent 08d053b commit 86a1560
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qiskit_ibm_runtime/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from qiskit_ibm_runtime import QiskitRuntimeService
from .session import Session
from .utils.deprecation import issue_deprecation_msg


class Batch(Session):
Expand Down Expand Up @@ -98,6 +99,14 @@ def __init__(
Raises:
ValueError: If an input value is invalid.
"""
if isinstance(backend, str):
issue_deprecation_msg(
msg="Passing a backend as a string is deprecated",
version="0.26.0",
remedy="Use the actual backend object instead.",
period="3 months",
)

super().__init__(service=service, backend=backend, max_time=max_time)

def _create_session(self) -> Optional[str]:
Expand Down
6 changes: 6 additions & 0 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def __init__(
" the service using `QiskitRuntimeService().backend('ibm_backend')`",
3,
)
issue_deprecation_msg(
msg="Passing a backend as a string is deprecated",
version="0.26.0",
remedy="Use the actual backend object instead.",
period="3 months",
)
if mode is None:
mode = session if backend and session else backend if backend else session
BasePrimitiveV2.__init__(self, mode=mode, options=options)
Expand Down
8 changes: 8 additions & 0 deletions qiskit_ibm_runtime/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def __init__(
" the service using `QiskitRuntimeService().backend('ibm_backend')`",
3,
)
issue_deprecation_msg(
msg="Passing a backend as a string is deprecated",
version="0.26.0",
remedy="Use the actual backend object instead.",
period="3 months",
stacklevel=2,
)

if mode is None:
mode = session if backend and session else backend if backend else session
BasePrimitiveV2.__init__(self, mode=mode, options=options)
Expand Down
6 changes: 6 additions & 0 deletions qiskit_ibm_runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def __init__(
else QiskitRuntimeService.global_service
)
if isinstance(backend, str):
issue_deprecation_msg(
msg="Passing a backend as a string is deprecated",
version="0.26.0",
remedy="Use the actual backend object instead.",
period="3 months",
)
self._backend = self._service.backend(backend)
elif backend is None:
raise ValueError('"backend" is required')
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/1804.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Passing in a backend as a string into ``Session``, ``Batch``, ``EstimatorV2``, and ``SamplerV2``
has been deprecated. Use the actual backend object instead.

0 comments on commit 86a1560

Please sign in to comment.