From 2f46385768545a4886295f26d54ade1b8a0045b8 Mon Sep 17 00:00:00 2001 From: Caleb Johnson Date: Mon, 6 Nov 2023 12:57:20 -0600 Subject: [PATCH] Revert "Translate all job statuses to Qiskit terminology in client (#1062)" This reverts commit 7a62247107eb6c5d5370e85933c345646015b934. --- README.md | 2 +- client/README.md | 2 +- client/quantum_serverless/core/job.py | 27 +++++---------------------- client/tests/core/test_pattern.py | 9 +++++---- client/tests/utils.py | 2 +- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 9dea52165..65f6dfb26 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ For user convenience, this section assumes that users will deploy the infrastruc ``` job.status() - # 'DONE' + # job.logs() # 2023-09-21 03:48:40,286\tINFO worker.py:1329 -- Using address 172.18.0.4:6379 set in the environment variable RAY_ADDRESS\n2023-09-21 03:48:40,286\tINFO worker.py:1458 -- Connecting to existing Ray cluster at address: 172.18.0.4:6379...\n2023-09-21 03:48:40,295\tINFO worker.py:1633 -- Connected to Ray cluster. View the dashboard at \x1b[1m\x1b[32m172.18.0.4:8265 \x1b[39m\x1b[22m\n diff --git a/client/README.md b/client/README.md index 505d1a491..1250597a1 100644 --- a/client/README.md +++ b/client/README.md @@ -106,7 +106,7 @@ Full docs can be found at https://qiskit-extensions.github.io/quantum-serverless ```python job.status() - # 'DONE' + # # or get logs job.logs() diff --git a/client/quantum_serverless/core/job.py b/client/quantum_serverless/core/job.py index b6a387caa..16d4c93cb 100644 --- a/client/quantum_serverless/core/job.py +++ b/client/quantum_serverless/core/job.py @@ -132,7 +132,7 @@ def __init__(self, client: JobSubmissionClient): self._job_client = client def status(self, job_id: str): - return self._job_client.get_job_status(job_id).value + return self._job_client.get_job_status(job_id) def stop(self, job_id: str): return self._job_client.stop_job(job_id) @@ -611,7 +611,7 @@ def __init__( def status(self): """Returns status of the job.""" - return _map_status_to_serverless(self._job_client.status(self.job_id)) + return self._job_client.status(self.job_id) def stop(self): """Stops the job from running.""" @@ -634,7 +634,7 @@ def result(self, wait=True, cadence=5, verbose=False): if wait: if verbose: logging.info("Waiting for job result.") - while not self.in_terminal_state(): + while not self._in_terminal_state(): time.sleep(cadence) if verbose: logging.info(".") @@ -649,9 +649,9 @@ def result(self, wait=True, cadence=5, verbose=False): return results - def in_terminal_state(self) -> bool: + def _in_terminal_state(self) -> bool: """Checks if job is in terminal state""" - terminal_states = ["CANCELED", "DONE", "ERROR"] + terminal_states = ["STOPPED", "SUCCEEDED", "FAILED"] return self.status() in terminal_states def __repr__(self): @@ -723,20 +723,3 @@ def save_result(result: Dict[str, Any]): logging.warning("Something went wrong: %s", response.text) return response.ok - - -def _map_status_to_serverless(status: str) -> str: - """Map a status string from job client to the Qiskit terminology.""" - status_map = { - "PENDING": "INITIALIZING", - "RUNNING": "RUNNING", - "STOPPED": "CANCELED", - "SUCCEEDED": "DONE", - "FAILED": "ERROR", - "QUEUED": "QUEUED", - } - - try: - return status_map[status] - except KeyError: - return status diff --git a/client/tests/core/test_pattern.py b/client/tests/core/test_pattern.py index 65111d9b6..68f3e9034 100644 --- a/client/tests/core/test_pattern.py +++ b/client/tests/core/test_pattern.py @@ -1,6 +1,7 @@ """Tests jobs.""" import os +from ray.dashboard.modules.job.common import JobStatus from testcontainers.compose import DockerCompose from quantum_serverless import QuantumServerless, BaseProvider @@ -48,12 +49,12 @@ def test_program(): wait_for_job_completion(job) assert "42" in job.logs() - assert job.in_terminal_state() - assert job.status() == "DONE" + assert job.status().is_terminal() + assert job.status() == JobStatus.SUCCEEDED recovered_job = serverless.get_job_by_id(job.job_id) assert recovered_job.job_id == job.job_id assert "42" in recovered_job.logs() - assert recovered_job.in_terminal_state() - assert recovered_job.status() == "DONE" + assert recovered_job.status().is_terminal() + assert recovered_job.status() == JobStatus.SUCCEEDED assert isinstance(job.stop(), bool) diff --git a/client/tests/utils.py b/client/tests/utils.py index 16da554ff..609f639ad 100644 --- a/client/tests/utils.py +++ b/client/tests/utils.py @@ -18,6 +18,6 @@ def wait_for_job_completion(job: Job, timeout: int = 60): """Utility function that waits for job completion.""" must_finish = time.time() + timeout while time.time() < must_finish: - if job.in_terminal_state(): + if job.status().is_terminal(): break time.sleep(1)