Skip to content

Commit 41e608d

Browse files
authored
IonQ API: Move to v0.2, and fixup backends path (#433)
* Move to v0.2, and fixup backends path The previous path was mistakenly incorrect, could we release this as a patch release of project-Q? Happy to help how I can. * changelog * fix * One more fixup * remove urljoin * fmt
1 parent cef343d commit 41e608d

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Fixed IonQ dynamic backends fetch, which relied on an incorrect path.
11+
1012
## [v0.7.2] - 2022-04-11
1113

1214
### Changed

projectq/backends/_ionq/_ionq_http_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
RequestTimeoutError,
3232
)
3333

34-
_API_URL = 'https://api.ionq.co/v0.1/jobs/'
34+
_API_URL = 'https://api.ionq.co/v0.2/'
35+
_JOB_API_URL = urljoin(_API_URL, 'jobs/')
3536

3637

3738
class IonQ(Session):
@@ -148,7 +149,7 @@ def run(self, info, device):
148149

149150
# _API_URL[:-1] strips the trailing slash.
150151
# TODO: Add comprehensive error parsing for non-200 responses.
151-
req = super().post(_API_URL[:-1], json=argument)
152+
req = super().post(_JOB_API_URL[:-1], json=argument)
152153
req.raise_for_status()
153154

154155
# Process the response.
@@ -211,7 +212,7 @@ def _handle_sigint_during_get_result(*_): # pragma: no cover
211212

212213
try:
213214
for retries in range(num_retries):
214-
req = super().get(urljoin(_API_URL, execution_id))
215+
req = super().get(urljoin(_JOB_API_URL, execution_id))
215216
req.raise_for_status()
216217
r_json = req.json()
217218
status = r_json['status']

projectq/backends/_ionq/_ionq_http_client_test.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import pytest
2020
import requests
21-
from requests.compat import urljoin
2221

2322
from projectq.backends._exceptions import JobSubmissionError, RequestTimeoutError
2423
from projectq.backends._ionq import _ionq_http_client
@@ -30,9 +29,6 @@ def no_requests(monkeypatch):
3029
monkeypatch.delattr('requests.sessions.Session.request')
3130

3231

33-
_api_url = 'https://api.ionq.co/v0.1/jobs/'
34-
35-
3632
def test_authenticate():
3733
ionq_session = _ionq_http_client.IonQ()
3834
ionq_session.authenticate('NotNone')
@@ -55,7 +51,7 @@ def user_password_input(prompt):
5551

5652
def test_is_online(monkeypatch):
5753
def mock_get(_self, path, *args, **kwargs):
58-
assert urljoin(_api_url, 'backends') == path
54+
assert 'https://api.ionq.co/v0.2/backends' == path
5955
mock_response = mock.MagicMock()
6056
mock_response.json = mock.MagicMock(
6157
return_value=[
@@ -91,7 +87,7 @@ def mock_get(_self, path, *args, **kwargs):
9187

9288
def test_show_devices(monkeypatch):
9389
def mock_get(_self, path, *args, **kwargs):
94-
assert urljoin(_api_url, 'backends') == path
90+
assert 'https://api.ionq.co/v0.2/backends' == path
9591
mock_response = mock.MagicMock()
9692
mock_response.json = mock.MagicMock(
9793
return_value=[
@@ -187,7 +183,7 @@ def _dummy_update(_self):
187183
}
188184

189185
def mock_post(_self, path, *args, **kwargs):
190-
assert path == _api_url[:-1]
186+
assert path == 'https://api.ionq.co/v0.2/jobs'
191187
assert 'json' in kwargs
192188
assert expected_request == kwargs['json']
193189
mock_response = mock.MagicMock()
@@ -201,7 +197,7 @@ def mock_post(_self, path, *args, **kwargs):
201197
return mock_response
202198

203199
def mock_get(_self, path, *args, **kwargs):
204-
assert urljoin(_api_url, 'new-job-id') == path
200+
assert path == 'https://api.ionq.co/v0.2/jobs/new-job-id'
205201
mock_response = mock.MagicMock()
206202
mock_response.json = mock.MagicMock(
207203
return_value={
@@ -433,7 +429,7 @@ def _dummy_update(_self):
433429
)
434430

435431
def mock_post(_self, path, **kwargs):
436-
assert _api_url[:-1] == path
432+
assert path == 'https://api.ionq.co/v0.2/jobs'
437433
mock_response = mock.MagicMock()
438434
mock_response.json = mock.MagicMock(return_value=err_data)
439435
return mock_response
@@ -472,7 +468,7 @@ def _dummy_update(_self):
472468
)
473469

474470
def mock_post(_self, path, *args, **kwargs):
475-
assert path == _api_url[:-1]
471+
assert path == 'https://api.ionq.co/v0.2/jobs'
476472
mock_response = mock.MagicMock()
477473
mock_response.json = mock.MagicMock(
478474
return_value={
@@ -483,7 +479,7 @@ def mock_post(_self, path, *args, **kwargs):
483479
return mock_response
484480

485481
def mock_get(_self, path, *args, **kwargs):
486-
assert urljoin(_api_url, 'new-job-id') == path
482+
assert path == 'https://api.ionq.co/v0.2/jobs/new-job-id'
487483
mock_response = mock.MagicMock()
488484
mock_response.json = mock.MagicMock(
489485
return_value={
@@ -533,7 +529,7 @@ def _dummy_update(_self):
533529
request_num = [0]
534530

535531
def mock_get(_self, path, *args, **kwargs):
536-
assert urljoin(_api_url, 'old-job-id') == path
532+
assert path == 'https://api.ionq.co/v0.2/jobs/old-job-id'
537533
json_response = {
538534
'id': 'old-job-id',
539535
'status': 'running',
@@ -591,7 +587,7 @@ def _dummy_update(_self):
591587
request_num = [0]
592588

593589
def mock_get(_self, path, *args, **kwargs):
594-
assert urljoin(_api_url, 'old-job-id') == path
590+
assert path == 'https://api.ionq.co/v0.2/jobs/old-job-id'
595591
json_response = {
596592
'id': 'old-job-id',
597593
'status': 'running',

0 commit comments

Comments
 (0)