Skip to content

Commit

Permalink
Deprecate backend.run (#1579)
Browse files Browse the repository at this point in the history
* Deprecate backend.run

* Update unit test

* Deprecate sessions related methods

* Add migration guide link

* Update release note

---------

Co-authored-by: Jessie Yu <[email protected]>
  • Loading branch information
kt474 and jyu00 authored Apr 15, 2024
1 parent a2a803e commit d456084
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
36 changes: 36 additions & 0 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
defaults_from_server_data,
properties_from_server_data,
)
from .utils.deprecation import issue_deprecation_msg
from .utils.options import QASM2Options, QASM3Options
from .api.exceptions import RequestsApiError
from .utils import local_to_utc, are_circuits_dynamic
Expand Down Expand Up @@ -676,6 +677,13 @@ def run(
- If ESP readout is used and the backend does not support this.
"""
# pylint: disable=arguments-differ
issue_deprecation_msg(
msg="backend.run() and related sessions methods are deprecated ",
version="0.23",
remedy="More details can be found in the primitives migration "
"guide https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime.",
period="6 months",
)
validate_job_tags(job_tags)
if not isinstance(circuits, List):
circuits = [circuits]
Expand Down Expand Up @@ -830,6 +838,13 @@ def _get_run_config(self, program_id: str, **kwargs: Any) -> Dict:

def open_session(self, max_time: Optional[Union[int, str]] = None) -> ProviderSession:
"""Open session"""
issue_deprecation_msg(
msg="backend.run() and related sessions methods are deprecated ",
version="0.23",
remedy="More details can be found in the primitives migration guide "
"https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime.",
period="6 months",
)
if not self._configuration.simulator:
new_session = self._service._api_client.create_session(
self.name, self._instance, max_time, self._service.channel
Expand All @@ -842,10 +857,24 @@ def open_session(self, max_time: Optional[Union[int, str]] = None) -> ProviderSe
@property
def session(self) -> ProviderSession:
"""Return session"""
issue_deprecation_msg(
msg="backend.run() and related sessions methods are deprecated ",
version="0.23",
remedy="More details can be found in the primitives migration "
"guide https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime.",
period="6 months",
)
return self._session

def cancel_session(self) -> None:
"""Cancel session. All pending jobs will be cancelled."""
issue_deprecation_msg(
msg="backend.run() and related sessions methods are deprecated ",
version="0.23",
remedy="More details can be found in the primitives migration "
"guide https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime.",
period="6 months",
)
if self._session:
self._session.cancel()
if self._session.session_id:
Expand All @@ -857,6 +886,13 @@ def close_session(self) -> None:
"""Close the session so new jobs will no longer be accepted, but existing
queued or running jobs will run to completion. The session will be terminated once there
are no more pending jobs."""
issue_deprecation_msg(
msg="backend.run() and related sessions methods are deprecated ",
version="0.23",
remedy="More details can be found in the primitives migration "
"guide https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime.",
period="6 months",
)
if self._session:
self._session.cancel()
if self._session.session_id:
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/1561.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`backend.run` has been deprecated. Please use the primitives instead. More details
can be found in the `migration guide <https://docs.quantum.ibm.com/api/migration-guides/qiskit-runtime>`__ .
4 changes: 2 additions & 2 deletions test/unit/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def test_dynamic_circuits_warning(self):
backend.run(circuits=circuit, dynamic=False)
self.assertIn(
"Parameter 'dynamic' is False, but the circuit contains dynamic constructs.",
str(warn[0].message),
str(warn[1].message),
)
self.assertIn(
f"The backend {backend.name} does not support dynamic circuits.",
str(warn[1].message),
str(warn[2].message),
)

@staticmethod
Expand Down

0 comments on commit d456084

Please sign in to comment.