Skip to content

Commit

Permalink
Merge pull request #132 from iqm-finland/fix-iqm-client-imports
Browse files Browse the repository at this point in the history
Upgrade to iqm-client 17.6
  • Loading branch information
ollityrkko committed Jun 11, 2024
2 parents 38eadfd + c227d19 commit 2428999
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 14.1
============

* Require iqm-client >= 17.6. `#132 <https://github.com/iqm-finland/cirq-on-iqm/pull/132>`_

Version 14.0
============

Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions src/iqm/cirq_iqm/iqm_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
25 changes: 14 additions & 11 deletions tests/test_iqm_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand All @@ -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()

0 comments on commit 2428999

Please sign in to comment.