diff --git a/qiskit_ibm_runtime/batch.py b/qiskit_ibm_runtime/batch.py index 03d0459cf..8f1fc5ae6 100644 --- a/qiskit_ibm_runtime/batch.py +++ b/qiskit_ibm_runtime/batch.py @@ -18,6 +18,7 @@ from qiskit_ibm_runtime import QiskitRuntimeService from .session import Session +from .utils.deprecation import issue_deprecation_msg class Batch(Session): @@ -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]: diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index 6374107a8..3afd851de 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -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) diff --git a/qiskit_ibm_runtime/sampler.py b/qiskit_ibm_runtime/sampler.py index aac3d5e40..5c7116b1c 100644 --- a/qiskit_ibm_runtime/sampler.py +++ b/qiskit_ibm_runtime/sampler.py @@ -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) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index fdc125183..bbcd53a5e 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -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') diff --git a/release-notes/unreleased/1804.deprecation.rst b/release-notes/unreleased/1804.deprecation.rst new file mode 100644 index 000000000..e2b93635b --- /dev/null +++ b/release-notes/unreleased/1804.deprecation.rst @@ -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. \ No newline at end of file