diff --git a/qiskit_ibm_runtime/runtime_job.py b/qiskit_ibm_runtime/runtime_job.py index 66f1b3551..84ee9ac25 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 @@ -319,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. @@ -332,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 @@ -368,6 +360,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 +391,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..b08c1b5ed 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 @@ -236,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. @@ -249,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 @@ -285,6 +277,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 +308,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