diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 436163f3..e18821cd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +Version 14.1 +============ + +* Require iqm-client >= 17.6. `#132 `_ + Version 14.0 ============ 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/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] 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): diff --git a/tests/test_iqm_sampler.py b/tests/test_iqm_sampler.py index e04499e4..8db68577 100644 --- a/tests/test_iqm_sampler.py +++ b/tests/test_iqm_sampler.py @@ -22,6 +22,7 @@ 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,16 @@ 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) + 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()