Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly throw TimeoutError when job times out #4514

Merged
merged 3 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion cirq-ionq/cirq_ionq/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ def results(
if 'failure' in self._job and 'error' in self._job['failure']:
error = self._job['failure']['error']
raise RuntimeError(f'Job failed. Error message: {error}')
if time_waited_seconds >= timeout_seconds:
raise TimeoutError(f'Job timed out after waiting {time_waited_seconds} seconds.')
raise RuntimeError(
f'Job was not completed successful. Instead had status: {self.status()}'
f'Job was not completed successfully. Instead had status: {self.status()}'
)
# IonQ returns results in little endian, Cirq prefers to use big endian, so we convert.
if self.target() == 'qpu':
Expand Down
10 changes: 9 additions & 1 deletion cirq-ionq/cirq_ionq/job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def test_job_results_failed():
assert job.status() == 'failed'


def test_job_results_failed_no_error_message():
job_dict = {'id': 'my_id', 'status': 'failed', 'failure': {}}
job = ionq.Job(None, job_dict)
with pytest.raises(RuntimeError, match='failed'):
_ = job.results()
assert job.status() == 'failed'


def test_job_results_qpu_endianness():
job_dict = {
'id': 'my_id',
Expand Down Expand Up @@ -124,7 +132,7 @@ def test_job_results_poll_timeout(mock_sleep):
mock_client = mock.MagicMock()
mock_client.get_job.return_value = ready_job
job = ionq.Job(mock_client, ready_job)
with pytest.raises(RuntimeError, match='ready'):
with pytest.raises(TimeoutError, match='seconds'):
_ = job.results(timeout_seconds=1, polling_seconds=0.1)
assert mock_sleep.call_count == 11

Expand Down