Skip to content

Commit

Permalink
Revert "Translate all job statuses to Qiskit terminology in client (#…
Browse files Browse the repository at this point in the history
…1062)"

This reverts commit 7a62247.
  • Loading branch information
caleb-johnson committed Nov 6, 2023
1 parent 7a62247 commit 2f46385
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ For user convenience, this section assumes that users will deploy the infrastruc

```
job.status()
# 'DONE'
# <JobStatus.SUCCEEDED: 'SUCCEEDED'>

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
Expand Down
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Full docs can be found at https://qiskit-extensions.github.io/quantum-serverless

```python
job.status()
# 'DONE'
# <JobStatus.SUCCEEDED: 'SUCCEEDED'>

# or get logs
job.logs()
Expand Down
27 changes: 5 additions & 22 deletions client/quantum_serverless/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand All @@ -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(".")
Expand All @@ -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):
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions client/tests/core/test_pattern.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion client/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2f46385

Please sign in to comment.