Skip to content

Commit

Permalink
Add unit tests for heralding option
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-k committed May 25, 2023
1 parent 2b18aeb commit 0e74868
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/test_iqm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.
"""Tests for the IQM client.
"""
from mockito import ANY, verify, when
import json
from mockito import ANY, kwargs, verify, unstub, when

# pylint: disable=unused-argument
import pytest
Expand All @@ -28,6 +29,7 @@
ClientConfigurationError,
IQMClient,
QuantumArchitectureSpecification,
RunRequest,
SingleQubitMapping,
Status,
__version__,
Expand Down Expand Up @@ -189,6 +191,38 @@ def test_submit_circuits_with_duration_check_disabled_returns_id(
assert job_id == existing_run


def test_submit_circuits_does_not_activate_heralding_by_default(base_url, sample_circuit):
client = IQMClient(base_url)
circuits = [Circuit.parse_obj(sample_circuit)]
expected_request_str = json.loads(RunRequest(circuits=circuits, shots=10, heralding='none').json(exclude_none=True))
when(requests).post(f'{base_url}/jobs', json=expected_request_str, **kwargs).thenReturn(
MockJsonResponse(201, {'id': str(existing_run)})
)
client.submit_circuits(circuits=circuits, shots=10)
unstub()


def test_submit_circuits_sets_heralding_mode_in_run_request(base_url, sample_circuit):
client = IQMClient(base_url)
circuits = [Circuit.parse_obj(sample_circuit)]
expected_request_str = json.loads(RunRequest(circuits=circuits, shots=1, heralding='zeros').json(exclude_none=True))
when(requests).post(f'{base_url}/jobs', json=expected_request_str, **kwargs).thenReturn(
MockJsonResponse(201, {'id': str(existing_run)})
)
client.submit_circuits(circuits=circuits, heralding='zeros')


def test_submit_circuits_raises_with_invalid_heralding_mode(base_url, sample_circuit):
client = IQMClient(base_url)
with pytest.raises(ValueError, match='value is not a valid enumeration member'):
client.submit_circuits(
qubit_mapping={'Qubit A': 'QB1', 'Qubit B': 'QB2'},
circuits=[Circuit.parse_obj(sample_circuit)],
heralding='bamboleo',
shots=1000,
)


def test_get_run_adds_user_agent(mock_server, base_url, calibration_set_id, sample_circuit):
"""
Tests that get_run without client signature adds the correct User-Agent header
Expand Down

0 comments on commit 0e74868

Please sign in to comment.