From 6498b0b9f276ecc99a0245f672aac60ea8d7d75a Mon Sep 17 00:00:00 2001 From: Ryan Cocuzzo Date: Fri, 21 Jun 2024 12:02:25 -0400 Subject: [PATCH 1/4] add support for local websockets and local ibm quantum api instance --- qiskit_ibm_runtime/base_runtime_job.py | 8 +++++++- test/decorators.py | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/base_runtime_job.py b/qiskit_ibm_runtime/base_runtime_job.py index 9b24b6f84..05fac635a 100644 --- a/qiskit_ibm_runtime/base_runtime_job.py +++ b/qiskit_ibm_runtime/base_runtime_job.py @@ -123,7 +123,7 @@ def __init__( self._ws_client_future = None # type: Optional[futures.Future] self._result_queue = queue.Queue() # type: queue.Queue self._ws_client = RuntimeWebsocketClient( - websocket_url=client_params.get_runtime_api_base_url().replace("https", "wss"), + websocket_url=client_params.get_runtime_api_base_url().replace("https", "wss").replace("http", "ws"), client_params=client_params, job_id=job_id, message_queue=self._result_queue, @@ -141,8 +141,10 @@ def _download_external_result(self, response: Any) -> Any: """ try: result_url_json = json.loads(response) + print('downloading result', result_url_json) if "url" in result_url_json: url = result_url_json["url"] + print('getting result json', url, result_url_json) result_response = requests.get(url, timeout=10) return result_response.text return response @@ -225,6 +227,7 @@ def _set_status_and_error_message(self) -> None: """Fetch and set status and error message.""" if self._status not in self.JOB_FINAL_STATES: response = self._api_client.job_get(job_id=self.job_id()) + print('\ngetting job status!', response, '\n\n') self._set_status(response) self._set_error_message(response) @@ -338,7 +341,10 @@ def _stream_results( _decoder = decoder or self._interim_result_decoder while True: try: + # logger.debug("\n\nFetching Queue response...") response = result_queue.get() + # print('\n\nxx queue response:', response, '\n\n') + # logger.debug("\n\nQueue response: %s", response) if response == self._POISON_PILL: self._empty_result_queue(result_queue) return diff --git a/test/decorators.py b/test/decorators.py index dfef9f8e0..1315b450d 100644 --- a/test/decorators.py +++ b/test/decorators.py @@ -75,7 +75,14 @@ def _get_integration_test_config(): os.getenv("QISKIT_IBM_INSTANCE"), os.getenv("CHANNEL_STRATEGY"), ) - channel: Any = "ibm_quantum" if url.find("quantum-computing.ibm.com") >= 0 else "ibm_cloud" + channel = "ibm_cloud" + if url is None: + return channel, token, url, instance, channel_strategy + + url_is_localhost = url.find("localhost") >= 0 or url.find("127.0.0.1") >= 0 + url_is_ibm_quantum = url.find("quantum-computing.ibm.com") >= 0 + if url_is_ibm_quantum or url_is_localhost: + channel = "ibm_quantum" return channel, token, url, instance, channel_strategy From 0b7f785aa2d33475371eafbc15cdbf1a11c5da20 Mon Sep 17 00:00:00 2001 From: Ryan Cocuzzo Date: Fri, 21 Jun 2024 12:04:28 -0400 Subject: [PATCH 2/4] remove print --- qiskit_ibm_runtime/base_runtime_job.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/qiskit_ibm_runtime/base_runtime_job.py b/qiskit_ibm_runtime/base_runtime_job.py index 05fac635a..8bdf199af 100644 --- a/qiskit_ibm_runtime/base_runtime_job.py +++ b/qiskit_ibm_runtime/base_runtime_job.py @@ -141,10 +141,8 @@ def _download_external_result(self, response: Any) -> Any: """ try: result_url_json = json.loads(response) - print('downloading result', result_url_json) if "url" in result_url_json: url = result_url_json["url"] - print('getting result json', url, result_url_json) result_response = requests.get(url, timeout=10) return result_response.text return response @@ -227,7 +225,6 @@ def _set_status_and_error_message(self) -> None: """Fetch and set status and error message.""" if self._status not in self.JOB_FINAL_STATES: response = self._api_client.job_get(job_id=self.job_id()) - print('\ngetting job status!', response, '\n\n') self._set_status(response) self._set_error_message(response) @@ -341,10 +338,7 @@ def _stream_results( _decoder = decoder or self._interim_result_decoder while True: try: - # logger.debug("\n\nFetching Queue response...") response = result_queue.get() - # print('\n\nxx queue response:', response, '\n\n') - # logger.debug("\n\nQueue response: %s", response) if response == self._POISON_PILL: self._empty_result_queue(result_queue) return From f156f178b6fbb02c72c370bfd656863427aaf25c Mon Sep 17 00:00:00 2001 From: Ryan Cocuzzo Date: Fri, 21 Jun 2024 12:09:34 -0400 Subject: [PATCH 3/4] add quantum.ibm.com as a possible url domain for ibm quantum --- test/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/decorators.py b/test/decorators.py index 1315b450d..48d815035 100644 --- a/test/decorators.py +++ b/test/decorators.py @@ -80,7 +80,7 @@ def _get_integration_test_config(): return channel, token, url, instance, channel_strategy url_is_localhost = url.find("localhost") >= 0 or url.find("127.0.0.1") >= 0 - url_is_ibm_quantum = url.find("quantum-computing.ibm.com") >= 0 + url_is_ibm_quantum = url.find("quantum-computing.ibm.com") >= 0 or url.find("quantum.ibm.com") >= 0 if url_is_ibm_quantum or url_is_localhost: channel = "ibm_quantum" return channel, token, url, instance, channel_strategy From 93663bfeafc3fd1a78dbb1f52ad42f0769ffb30a Mon Sep 17 00:00:00 2001 From: Ryan Cocuzzo Date: Fri, 21 Jun 2024 14:05:29 -0400 Subject: [PATCH 4/4] lint --- qiskit_ibm_runtime/base_runtime_job.py | 4 +++- test/decorators.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/base_runtime_job.py b/qiskit_ibm_runtime/base_runtime_job.py index 8bdf199af..3ab49816c 100644 --- a/qiskit_ibm_runtime/base_runtime_job.py +++ b/qiskit_ibm_runtime/base_runtime_job.py @@ -123,7 +123,9 @@ def __init__( self._ws_client_future = None # type: Optional[futures.Future] self._result_queue = queue.Queue() # type: queue.Queue self._ws_client = RuntimeWebsocketClient( - websocket_url=client_params.get_runtime_api_base_url().replace("https", "wss").replace("http", "ws"), + websocket_url=client_params.get_runtime_api_base_url() + .replace("https", "wss") + .replace("http", "ws"), client_params=client_params, job_id=job_id, message_queue=self._result_queue, diff --git a/test/decorators.py b/test/decorators.py index 48d815035..03e591918 100644 --- a/test/decorators.py +++ b/test/decorators.py @@ -80,7 +80,9 @@ def _get_integration_test_config(): return channel, token, url, instance, channel_strategy url_is_localhost = url.find("localhost") >= 0 or url.find("127.0.0.1") >= 0 - url_is_ibm_quantum = url.find("quantum-computing.ibm.com") >= 0 or url.find("quantum.ibm.com") >= 0 + url_is_ibm_quantum = ( + url.find("quantum-computing.ibm.com") >= 0 or url.find("quantum.ibm.com") >= 0 + ) if url_is_ibm_quantum or url_is_localhost: channel = "ibm_quantum" return channel, token, url, instance, channel_strategy