From 647f5db3a553ac83c1055f4d4b3720526eca17cb Mon Sep 17 00:00:00 2001 From: Olli Tyrkko Date: Mon, 10 Jun 2024 14:59:59 +0300 Subject: [PATCH 1/4] Fix imports --- docs/user_guide.rst | 2 +- src/iqm/cirq_iqm/iqm_sampler.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 63e1d4aa..c2c481b1 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -287,7 +287,7 @@ The below table summarises the currently available options: Setting this value to ``0.0`` will disable circuit duration check. The default value ``None`` means the server default value will be used. * - `heralding_mode` - - :py:class:`~iqm_client.iqm_client.HeraldingMode` + - :py:class:`~iqm_client.models.HeraldingMode` - "zeros" - Heralding mode to use during execution. The default value is "none", "zeros" enables heralding. diff --git a/src/iqm/cirq_iqm/iqm_sampler.py b/src/iqm/cirq_iqm/iqm_sampler.py index 1923f9a1..4e2d75eb 100644 --- a/src/iqm/cirq_iqm/iqm_sampler.py +++ b/src/iqm/cirq_iqm/iqm_sampler.py @@ -27,13 +27,12 @@ import cirq import numpy as np -from iqm import iqm_client from iqm.cirq_iqm.devices.iqm_device import IQMDevice, IQMDeviceMetadata from iqm.cirq_iqm.iqm_operation_mapping import map_operation -from iqm.iqm_client import HeraldingMode, IQMClient, JobAbortionError, RunRequest +from iqm.iqm_client import Circuit, HeraldingMode, IQMClient, JobAbortionError, RunRequest -def serialize_circuit(circuit: cirq.Circuit) -> iqm_client.Circuit: +def serialize_circuit(circuit: cirq.Circuit) -> Circuit: """Serializes a quantum circuit into the IQM data transfer format. Args: @@ -43,7 +42,7 @@ def serialize_circuit(circuit: cirq.Circuit) -> iqm_client.Circuit: data transfer object representing the circuit """ instructions = tuple(map(map_operation, circuit.all_operations())) - return iqm_client.Circuit(name='Serialized from Cirq', instructions=instructions) + return Circuit(name='Serialized from Cirq', instructions=instructions) class IQMSampler(cirq.work.Sampler): From 363b6be8533c227bc67e1a46826c6e56088da452 Mon Sep 17 00:00:00 2001 From: Olli Tyrkko Date: Mon, 10 Jun 2024 16:38:11 +0300 Subject: [PATCH 2/4] Fix tests --- tests/test_iqm_sampler.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/test_iqm_sampler.py b/tests/test_iqm_sampler.py index e04499e4..cd888b5d 100644 --- a/tests/test_iqm_sampler.py +++ b/tests/test_iqm_sampler.py @@ -16,12 +16,13 @@ import uuid import cirq -from mockito import ANY, mock, verify, when +from mockito import ANY, expect, mock, verify, when import numpy as np import pytest import sympy # type: ignore from iqm.cirq_iqm import Adonis +import iqm.cirq_iqm as module_under_test from iqm.cirq_iqm.iqm_sampler import IQMResult, IQMSampler, ResultMetadata from iqm.iqm_client import ( Circuit, @@ -344,17 +345,18 @@ def test_run_iqm_batch_allows_to_override_polling_timeout( np.testing.assert_array_equal(results[1].measurements['some stuff'], np.array([[1]])) +@pytest.mark.usefixtures('unstub') def test_credentials_are_passed_to_client(): user_auth_args = { 'auth_server_url': 'https://fake.auth.server.com', 'username': 'fake-username', 'password': 'fake-password', } - with when(IQMClient)._update_tokens(): - sampler = IQMSampler('http://url', Adonis(), **user_auth_args) - assert sampler._client._credentials.auth_server_url == user_auth_args['auth_server_url'] - assert sampler._client._credentials.username == user_auth_args['username'] - assert sampler._client._credentials.password == user_auth_args['password'] + when(module_under_test.iqm_sampler).IQMClient('http://url', client_signature=ANY, **user_auth_args).thenReturn( + mock(IQMClient) + ) + IQMSampler('http://url', Adonis(), **user_auth_args) + verify(module_under_test.iqm_sampler, times=1).IQMClient('http://url', client_signature=ANY, **user_auth_args) @pytest.mark.usefixtures('unstub') @@ -364,15 +366,14 @@ def test_client_signature_is_passed_to_client(): assert f'cirq-iqm {version("cirq-iqm")}' in sampler._client._signature +@pytest.mark.usefixtures('unstub') def test_close_client(): user_auth_args = { 'auth_server_url': 'https://fake.auth.server.com', 'username': 'fake-username', 'password': 'fake-password', } - with when(IQMClient)._update_tokens(): - sampler = IQMSampler('http://url', Adonis(), **user_auth_args) - try: - sampler.close_client() - except Exception as exc: # pylint: disable=broad-except - assert False, f'sampler created with credentials raised an exception {exc} on .close_client()' + sampler = IQMSampler('http://url', Adonis(), **user_auth_args) + sampler._client = mock(IQMClient) + expect(sampler._client, times=1).close_auth_session().thenReturn(True) + sampler.close_client() From 6e274bb15cc2d3ea30acb17e8891d8ac2840b535 Mon Sep 17 00:00:00 2001 From: Olli Tyrkko Date: Mon, 10 Jun 2024 16:48:28 +0300 Subject: [PATCH 3/4] Require iqm-client >= 17.6 --- CHANGELOG.rst | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 436163f3..5a90ff60 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +Version 14.1 +============ + +* Require iqm-client >= 17.6. + Version 14.0 ============ diff --git a/pyproject.toml b/pyproject.toml index 0731cd38..ffa354e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ "numpy", "cirq-core[contrib] ~= 1.2", "ply", # Required by cirq.contrib.qasm_import - "iqm-client >= 17.1, < 18.0" + "iqm-client >= 17.6, < 18.0" ] [project.urls] From c227d197c5d4406bb41015f94320b008623349db Mon Sep 17 00:00:00 2001 From: Olli Tyrkko Date: Tue, 11 Jun 2024 10:08:42 +0300 Subject: [PATCH 4/4] Add PR number to CHANGELOG, fix tests --- CHANGELOG.rst | 2 +- tests/test_iqm_sampler.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5a90ff60..e18821cd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ Changelog Version 14.1 ============ -* Require iqm-client >= 17.6. +* Require iqm-client >= 17.6. `#132 `_ Version 14.0 ============ diff --git a/tests/test_iqm_sampler.py b/tests/test_iqm_sampler.py index cd888b5d..8db68577 100644 --- a/tests/test_iqm_sampler.py +++ b/tests/test_iqm_sampler.py @@ -16,7 +16,7 @@ import uuid import cirq -from mockito import ANY, expect, mock, verify, when +from mockito import ANY, mock, verify, when import numpy as np import pytest import sympy # type: ignore @@ -374,6 +374,8 @@ def test_close_client(): 'password': 'fake-password', } sampler = IQMSampler('http://url', Adonis(), **user_auth_args) - sampler._client = mock(IQMClient) - expect(sampler._client, times=1).close_auth_session().thenReturn(True) + mock_client = mock(IQMClient) + sampler._client = mock_client + when(mock_client).close_auth_session().thenReturn(True) sampler.close_client() + verify(mock_client, times=1).close_auth_session()