Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed IonQ dynamic backends fetch, which relied on an incorrect path.

## [v0.7.2] - 2022-04-11

### Changed
Expand Down
7 changes: 4 additions & 3 deletions projectq/backends/_ionq/_ionq_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
RequestTimeoutError,
)

_API_URL = 'https://api.ionq.co/v0.1/jobs/'
_API_URL = 'https://api.ionq.co/v0.2/'
_JOB_API_URL = urljoin(_API_URL, 'jobs/')


class IonQ(Session):
Expand Down Expand Up @@ -148,7 +149,7 @@ def run(self, info, device):

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

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

try:
for retries in range(num_retries):
req = super().get(urljoin(_API_URL, execution_id))
req = super().get(urljoin(_JOB_API_URL, execution_id))
req.raise_for_status()
r_json = req.json()
status = r_json['status']
Expand Down
22 changes: 9 additions & 13 deletions projectq/backends/_ionq/_ionq_http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import pytest
import requests
from requests.compat import urljoin

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


_api_url = 'https://api.ionq.co/v0.1/jobs/'


def test_authenticate():
ionq_session = _ionq_http_client.IonQ()
ionq_session.authenticate('NotNone')
Expand All @@ -55,7 +51,7 @@ def user_password_input(prompt):

def test_is_online(monkeypatch):
def mock_get(_self, path, *args, **kwargs):
assert urljoin(_api_url, 'backends') == path
assert 'https://api.ionq.co/v0.2/backends' == path
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value=[
Expand Down Expand Up @@ -91,7 +87,7 @@ def mock_get(_self, path, *args, **kwargs):

def test_show_devices(monkeypatch):
def mock_get(_self, path, *args, **kwargs):
assert urljoin(_api_url, 'backends') == path
assert 'https://api.ionq.co/v0.2/backends' == path
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value=[
Expand Down Expand Up @@ -187,7 +183,7 @@ def _dummy_update(_self):
}

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

def mock_get(_self, path, *args, **kwargs):
assert urljoin(_api_url, 'new-job-id') == path
assert path == 'https://api.ionq.co/v0.2/jobs/new-job-id'
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value={
Expand Down Expand Up @@ -433,7 +429,7 @@ def _dummy_update(_self):
)

def mock_post(_self, path, **kwargs):
assert _api_url[:-1] == path
assert path == 'https://api.ionq.co/v0.2/jobs'
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(return_value=err_data)
return mock_response
Expand Down Expand Up @@ -472,7 +468,7 @@ def _dummy_update(_self):
)

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

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

def mock_get(_self, path, *args, **kwargs):
assert urljoin(_api_url, 'old-job-id') == path
assert path == 'https://api.ionq.co/v0.2/jobs/old-job-id'
json_response = {
'id': 'old-job-id',
'status': 'running',
Expand Down Expand Up @@ -591,7 +587,7 @@ def _dummy_update(_self):
request_num = [0]

def mock_get(_self, path, *args, **kwargs):
assert urljoin(_api_url, 'old-job-id') == path
assert path == 'https://api.ionq.co/v0.2/jobs/old-job-id'
json_response = {
'id': 'old-job-id',
'status': 'running',
Expand Down