From b6865b4a3e360f142506b6344a23d9e70d9b419a Mon Sep 17 00:00:00 2001 From: Kevin Tian Date: Mon, 1 Jul 2024 14:35:58 -0400 Subject: [PATCH 1/2] Deprecate interim results (#1776) * Deprecate interim results * Add release note --- qiskit_ibm_runtime/runtime_job.py | 3 +++ qiskit_ibm_runtime/runtime_job_v2.py | 3 +++ release-notes/unreleased/1776.deprecation.rst | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 release-notes/unreleased/1776.deprecation.rst diff --git a/qiskit_ibm_runtime/runtime_job.py b/qiskit_ibm_runtime/runtime_job.py index 66f1b3551..80b501298 100644 --- a/qiskit_ibm_runtime/runtime_job.py +++ b/qiskit_ibm_runtime/runtime_job.py @@ -34,6 +34,7 @@ ) from .utils.result_decoder import ResultDecoder from .utils.queueinfo import QueueInfo +from .utils.deprecation import deprecate_function from .api.clients import RuntimeClient from .api.exceptions import RequestsApiError from .api.client_parameters import ClientParameters @@ -368,6 +369,7 @@ def backend(self, timeout: Optional[float] = None) -> Optional[Backend]: raise IBMRuntimeError(f"Failed to get job backend: {err}") from None return self._backend + @deprecate_function("stream_results()", "0.25", "", stacklevel=1) def stream_results( self, callback: Callable, decoder: Optional[Type[ResultDecoder]] = None ) -> None: @@ -398,6 +400,7 @@ def stream_results( decoder=decoder, ) + @deprecate_function("interim_results()", "0.25", "", stacklevel=1) def interim_results(self, decoder: Optional[Type[ResultDecoder]] = None) -> Any: """Return the interim results of the job. diff --git a/qiskit_ibm_runtime/runtime_job_v2.py b/qiskit_ibm_runtime/runtime_job_v2.py index cbbbda651..5ac595f8b 100644 --- a/qiskit_ibm_runtime/runtime_job_v2.py +++ b/qiskit_ibm_runtime/runtime_job_v2.py @@ -32,6 +32,7 @@ RuntimeJobTimeoutError, ) from .utils.result_decoder import ResultDecoder +from .utils.deprecation import deprecate_function from .api.clients import RuntimeClient from .api.exceptions import RequestsApiError from .api.client_parameters import ClientParameters @@ -285,6 +286,7 @@ def backend(self, timeout: Optional[float] = None) -> Optional[Backend]: raise IBMRuntimeError(f"Failed to get job backend: {err}") from None return self._backend + @deprecate_function("stream_results()", "0.25", "", stacklevel=1) def stream_results( self, callback: Callable, decoder: Optional[Type[ResultDecoder]] = None ) -> None: @@ -315,6 +317,7 @@ def stream_results( decoder=decoder, ) + @deprecate_function("interim_results()", "0.25", "", stacklevel=1) def interim_results(self, decoder: Optional[Type[ResultDecoder]] = None) -> Any: """Return the interim results of the job. diff --git a/release-notes/unreleased/1776.deprecation.rst b/release-notes/unreleased/1776.deprecation.rst new file mode 100644 index 000000000..6606c7f04 --- /dev/null +++ b/release-notes/unreleased/1776.deprecation.rst @@ -0,0 +1,2 @@ +:meth:`qiskit_ibm_runtime.RuntimeJobV2.interim_results` and :meth:`qiskit_ibm_runtime.RuntimeJobV2.stream_results` +are now both deprecated. \ No newline at end of file From c607150241c302c329016e858da2438a888cdc1f Mon Sep 17 00:00:00 2001 From: Kevin Tian Date: Mon, 1 Jul 2024 15:04:25 -0400 Subject: [PATCH 2/2] Use polling for job status instead of websockets (#1778) --- qiskit_ibm_runtime/runtime_job.py | 11 +---------- qiskit_ibm_runtime/runtime_job_v2.py | 11 +---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/qiskit_ibm_runtime/runtime_job.py b/qiskit_ibm_runtime/runtime_job.py index 80b501298..84ee9ac25 100644 --- a/qiskit_ibm_runtime/runtime_job.py +++ b/qiskit_ibm_runtime/runtime_job.py @@ -320,10 +320,7 @@ def wait_for_final_state( # pylint: disable=arguments-differ self, timeout: Optional[float] = None, ) -> None: - """Use the websocket server to wait for the final the state of a job. - - The server will remain open if the job is still running and the connection will - be terminated once the job completes. Then update and return the status of the job. + """Poll for the job status from the API until the status is in a final state. Args: timeout: Seconds to wait for the job. If ``None``, wait indefinitely. @@ -333,12 +330,6 @@ def wait_for_final_state( # pylint: disable=arguments-differ """ try: start_time = time.time() - if self._status not in self.JOB_FINAL_STATES and not self._is_streaming(): - self._ws_client_future = self._executor.submit(self._start_websocket_client) - if self._is_streaming(): - self._ws_client_future.result(timeout) - # poll for status after stream has closed until status is final - # because status doesn't become final as soon as stream closes status = self.status() while status not in self.JOB_FINAL_STATES: elapsed_time = time.time() - start_time diff --git a/qiskit_ibm_runtime/runtime_job_v2.py b/qiskit_ibm_runtime/runtime_job_v2.py index 5ac595f8b..b08c1b5ed 100644 --- a/qiskit_ibm_runtime/runtime_job_v2.py +++ b/qiskit_ibm_runtime/runtime_job_v2.py @@ -237,10 +237,7 @@ def wait_for_final_state( # pylint: disable=arguments-differ self, timeout: Optional[float] = None, ) -> None: - """Use the websocket server to wait for the final the state of a job. - - The server will remain open if the job is still running and the connection will - be terminated once the job completes. Then update and return the status of the job. + """Poll for the job status from the API until the status is in a final state. Args: timeout: Seconds to wait for the job. If ``None``, wait indefinitely. @@ -250,12 +247,6 @@ def wait_for_final_state( # pylint: disable=arguments-differ """ try: start_time = time.time() - if self._status not in self.JOB_FINAL_STATES and not self._is_streaming(): - self._ws_client_future = self._executor.submit(self._start_websocket_client) - if self._is_streaming(): - self._ws_client_future.result(timeout) - # poll for status after stream has closed until status is final - # because status doesn't become final as soon as stream closes status = self.status() while status not in self.JOB_FINAL_STATES: elapsed_time = time.time() - start_time