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

Deprecate backend.run #1579

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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 @@ -675,6 +676,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 @@ -829,6 +837,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 @@ -841,10 +856,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 @@ -856,6 +885,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
1 change: 1 addition & 0 deletions release-notes/unreleased/1561.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`backend.run` has been deprecated. Please use the primitives instead.
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