Skip to content

Allow server-side warnings from IonQ #5222

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

Merged
merged 4 commits into from
Apr 8, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cirq-ionq/cirq_ionq/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Represents a job created via the IonQ API."""

import time
import warnings
from typing import Dict, Sequence, Union, TYPE_CHECKING

from cirq_ionq import ionq_exceptions, results
Expand Down Expand Up @@ -196,6 +197,10 @@ def results(
break
time.sleep(polling_seconds)
time_waited_seconds += polling_seconds
if 'warning' in self._job and 'messages' in self._job['warning']:
for warning in self._job['warning']['messages']:
warnings.warn(warning)

if self.status() != 'completed':
if 'failure' in self._job and 'error' in self._job['failure']:
error = self._job['failure']['error']
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 @@ -14,6 +14,7 @@

from unittest import mock

import warnings
import pytest

import cirq_ionq as ionq
Expand Down Expand Up @@ -64,9 +65,16 @@ def test_job_results_qpu():
'target': 'qpu',
'metadata': {'shots': 1000, 'measurement0': f'a{chr(31)}0,1'},
'data': {'histogram': {'0': '0.6', '2': '0.4'}},
'warning': {
'messages': ['foo', 'bar'],
},
}
job = ionq.Job(None, job_dict)
results = job.results()
with warnings.catch_warnings(record=True) as w:
results = job.results()
assert len(w) == 2
assert "foo" in str(w[0].message)
assert "bar" in str(w[1].message)
expected = ionq.QPUResult({0: 600, 1: 400}, 2, {'a': [0, 1]})
assert results == expected

Expand Down