Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima authored Apr 2, 2024
1 parent 20abc15 commit 24af196
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
14 changes: 10 additions & 4 deletions projectq/backends/_ionq/_ionq_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def can_run_experiment(self, info, device):

def user_agent(self):
"""Set a User-Agent header for this session."""
self.headers.update({'User-Agent': f'projectq-ionq/0.8.0'})
self.headers.update({'User-Agent': 'projectq-ionq/0.8.0'})

def authenticate(self, token=None):
"""Set an Authorization header for this session.
Expand Down Expand Up @@ -174,7 +174,13 @@ def run(self, info, device):
}
raise JobSubmissionError(f"{failure['code']}: {failure['error']} (status={status})")

def get_result(self, device, execution_id, sharpen=None, num_retries=3000, interval=1):
def get_result(
self,
device,
execution_id,
sharpen=None,
num_retries=3000,
interval=1): # pylint: disable=too-many-arguments,too-many-locals
"""
Given a backend and ID, fetch the results for this job's execution.
Expand Down Expand Up @@ -226,8 +232,8 @@ def _handle_sigint_during_get_result(*_): # pragma: no cover

# Check if job is completed.
if status == 'completed':
r = super().get(urljoin(_JOB_API_URL, req_json.get('results_url')), params=params)
r_json = r.json()
r_get = super().get(urljoin(_JOB_API_URL, req_json.get('results_url')), params=params)
re_json = r_get.json()
meas_mapped = req_json['registers']['meas_mapped']
meas_qubit_ids = json.loads(req_json['metadata']['meas_qubit_ids'])
output_probs = r_json
Expand Down
48 changes: 24 additions & 24 deletions projectq/backends/_ionq/_ionq_http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,29 @@ def mock_post(_self, path, *args, **kwargs):
return mock_response


def mock_get(_self, path, *args, **kwargs):
if path == 'https://api.ionq.co/v0.3/jobs/new-job-id':
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value={
'id': 'new-job-id',
'status': 'completed',
'qubits': 4,
'metadata': {'meas_qubit_ids': '[2, 3]'},
'registers': {'meas_mapped': [2, 3]},
'results_url': 'new-job-id/results',
}
)
elif path == 'https://api.ionq.co/v0.3/jobs/new-job-id/results':
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value={
{'2': 1},
}
)
else:
raise ValueError(f"Unexpected URL: {path}")
return mock_response
def mock_get(_self, path, *args, **kwargs):
if path == 'https://api.ionq.co/v0.3/jobs/new-job-id':
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value={
'id': 'new-job-id',
'status': 'completed',
'qubits': 4,
'metadata': {'meas_qubit_ids': '[2, 3]'},
'registers': {'meas_mapped': [2, 3]},
'results_url': 'new-job-id/results',
}
)
elif path == 'https://api.ionq.co/v0.3/jobs/new-job-id/results':
mock_response = mock.MagicMock()
mock_response.json = mock.MagicMock(
return_value={
{'2': 1},
}
)
else:
raise ValueError(f"Unexpected URL: {path}")
return mock_response

monkeypatch.setattr('requests.sessions.Session.post', mock_post)
monkeypatch.setattr('requests.sessions.Session.get', mock_get)
Expand Down Expand Up @@ -534,7 +534,7 @@ def _dummy_update(_self):
'update_devices_list',
_dummy_update.__get__(None, _ionq_http_client.IonQ),
)
request_num = [0]
# request_num = [0]

def mock_get(_self, path, *args, **kwargs):
if path == 'https://api.ionq.co/v0.3/jobs/old-job-id':
Expand Down

0 comments on commit 24af196

Please sign in to comment.