From 24af196b68d4bda436d980c7c7adb32d31eb3616 Mon Sep 17 00:00:00 2001 From: Nguyen Damien Date: Tue, 2 Apr 2024 22:28:03 +0200 Subject: [PATCH] Fix linter warnings --- projectq/backends/_ionq/_ionq_http_client.py | 14 ++++-- .../backends/_ionq/_ionq_http_client_test.py | 48 +++++++++---------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/projectq/backends/_ionq/_ionq_http_client.py b/projectq/backends/_ionq/_ionq_http_client.py index a0d54b80..ac31a91f 100644 --- a/projectq/backends/_ionq/_ionq_http_client.py +++ b/projectq/backends/_ionq/_ionq_http_client.py @@ -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. @@ -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. @@ -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 diff --git a/projectq/backends/_ionq/_ionq_http_client_test.py b/projectq/backends/_ionq/_ionq_http_client_test.py index 6219bfd1..46f9617f 100644 --- a/projectq/backends/_ionq/_ionq_http_client_test.py +++ b/projectq/backends/_ionq/_ionq_http_client_test.py @@ -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) @@ -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':