Skip to content

Commit

Permalink
support iqm-client 20.5
Browse files Browse the repository at this point in the history
Signed-off-by: kukushechkin <[email protected]>
  • Loading branch information
kukushechkin committed Nov 21, 2024
1 parent 0a3b520 commit e82575b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/test_iqm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import re
import uuid

from mockito import ANY, expect, mock, unstub, verifyNoUnwantedInteractions, when
from mockito import ANY, expect, matchers, mock, unstub, verifyNoUnwantedInteractions, when
import numpy as np
import pytest
from qiskit import QuantumCircuit, transpile
from qiskit.circuit import ClassicalRegister, Parameter, QuantumRegister
from qiskit.circuit.library import CZGate, RGate, RXGate, RYGate, XGate, YGate
import requests

from iqm.iqm_client import (
APIConfig,
Expand All @@ -35,6 +36,7 @@
RunRequest,
)
from iqm.qiskit_iqm.iqm_provider import IQMBackend, IQMJob
from tests.utils import get_mock_ok_response


@pytest.fixture
Expand Down Expand Up @@ -113,12 +115,16 @@ def test_set_max_circuits(backend):


def test_serialize_circuit_raises_error_for_non_transpiled_circuit(circuit, linear_3q_architecture):
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)
client = IQMClient(url='http://some_url')
client._token_manager = None # Do not use authentication
when(client).get_dynamic_quantum_architecture(None).thenReturn(linear_3q_architecture)
when(client).get_dynamic_quantum_architecture(linear_3q_architecture.calibration_set_id).thenReturn(
linear_3q_architecture
)

backend = IQMBackend(client)
circuit = QuantumCircuit(3)
circuit.cz(0, 2)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_iqm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def run_request():
def test_get_backend(linear_3q_architecture):
url = 'http://some_url'
when(IQMClient).get_dynamic_quantum_architecture(None).thenReturn(linear_3q_architecture)
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)

provider = IQMProvider(url)
backend = provider.get_backend()
Expand All @@ -59,6 +62,9 @@ def test_get_backend(linear_3q_architecture):
def test_client_signature(adonis_architecture):
url = 'http://some_url'
provider = IQMProvider(url)
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)
when(requests).get(
'http://some_url/api/v1/calibration/default/gates', headers=matchers.ANY, timeout=matchers.ANY
).thenReturn(get_mock_ok_response(adonis_architecture.model_dump()))
Expand All @@ -69,6 +75,9 @@ def test_client_signature(adonis_architecture):
def test_get_facade_backend(adonis_architecture, adonis_coupling_map):
url = 'http://some_url'
when(IQMClient).get_dynamic_quantum_architecture(None).thenReturn(adonis_architecture)
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)

provider = IQMProvider(url)
backend = provider.get_backend('facade_adonis')
Expand All @@ -83,6 +92,9 @@ def test_get_facade_backend_raises_error_non_matching_architecture(linear_3q_arc
url = 'http://some_url'

when(IQMClient).get_dynamic_quantum_architecture(None).thenReturn(linear_3q_architecture)
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)

provider = IQMProvider(url)
with pytest.raises(ValueError, match='Quantum architecture of the remote quantum computer does not match Adonis.'):
Expand Down Expand Up @@ -113,6 +125,9 @@ def test_facade_backend_raises_error_on_remote_execution_fail(adonis_architectur
when(IQMClient).submit_run_request(...).thenReturn(uuid.uuid4())
when(IQMClient).get_run(ANY(uuid.UUID)).thenReturn(RunResult.from_dict(result))
when(IQMClient).get_run_status(ANY(uuid.UUID)).thenReturn(RunStatus.from_dict(result_status))
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)

provider = IQMProvider(url)
backend = provider.get_backend('facade_adonis')
Expand Down
5 changes: 4 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class AllowedOps(TypedDict):

def get_mocked_backend(architecture: DynamicQuantumArchitecture) -> tuple[IQMBackend, IQMClient]:
"""Returns an IQM backend running on a mocked IQM client that returns the given architecture."""
client = IQMClient(url='http://localhost')
when(requests).get('http://some_url/info/client-libraries', headers=matchers.ANY, timeout=matchers.ANY).thenReturn(
get_mock_ok_response({'iqm-client': {'min': '0.0', 'max': '999.0'}})
)
client = IQMClient(url='http://some_url')
when(client).get_dynamic_quantum_architecture(None).thenReturn(architecture)
when(client).get_dynamic_quantum_architecture(architecture.calibration_set_id).thenReturn(architecture)
backend = IQMBackend(client)
Expand Down

0 comments on commit e82575b

Please sign in to comment.