Skip to content

Commit cc32669

Browse files
committed
Add / update tests for predicates in stabiliser sim
Added a new unit test that checks we include the CliffordCircuitPredicate only when we're running with a stabilizer simulator type (and not when we have a statevector simulator). Also update test_simulator to expect to fail on the predicate check in process_circuit(), rather than breaking on get_result().
1 parent e5cda8f commit cc32669

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

tests/integration/backend_test.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
QuantinuumAPI,
5757
QuantinuumAPIError,
5858
)
59-
from pytket.extensions.quantinuum.backends.quantinuum import _ALL_GATES, GetResultFailed
59+
from pytket.extensions.quantinuum.backends.quantinuum import _ALL_GATES
6060
from pytket.predicates import CompilationUnit
6161
from pytket.wasm import WasmFileHandler
6262

@@ -597,19 +597,17 @@ def test_simulator(
597597
assert sum(stab_counts.values()) == n_shots
598598
assert len(stab_counts) == 2
599599

600-
# test non-clifford circuit fails on stabilizer backend
601-
# unfortunately the job is accepted, then fails, so have to check get_result
600+
# test non-clifford circuit fails predicate check
601+
# when run on stabilizer backend
602602
non_stab_circ = (
603603
Circuit(2, name="non_stab_circ").H(0).Rx(0.1, 0).CX(0, 1).measure_all()
604604
)
605605
non_stab_circ = stabilizer_backend.get_compiled_circuit(non_stab_circ)
606-
broken_handle = stabilizer_backend.process_circuit(
607-
non_stab_circ, n_shots, language=language
608-
)
609-
610-
with pytest.raises(GetResultFailed) as _:
611-
_ = stabilizer_backend.get_result(broken_handle)
612606

607+
with pytest.raises(CircuitNotValidError):
608+
_ = stabilizer_backend.process_circuit(
609+
non_stab_circ, n_shots, noisy_simulation=False, language=language
610+
)
613611

614612
@pytest.mark.skipif(skip_remote_tests, reason=REASON)
615613
@pytest.mark.timeout(120)

tests/unit/backend.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
from pytket.extensions.quantinuum import QuantinuumAPIOffline, QuantinuumBackend
4+
from pytket.predicates import CliffordCircuitPredicate
5+
6+
7+
@pytest.mark.parametrize(
8+
"simulator_type,should_have_clifford_predicate",
9+
[
10+
("state-vector", False),
11+
("stabilizer", True),
12+
],
13+
)
14+
def test_clifford_circuits_for_stabilizer(
15+
simulator_type: str,
16+
should_have_clifford_predicate: bool,
17+
) -> None:
18+
"""Check that the stabilizer simulator restricts circuits to be Clifford circuits,
19+
and the statevector simulator does not."""
20+
qapi_offline = QuantinuumAPIOffline()
21+
backend = QuantinuumBackend(
22+
"H1-1E",
23+
api_handler=qapi_offline, # type: ignore
24+
simulator=simulator_type,
25+
)
26+
required_predicates = backend.required_predicates
27+
assert should_have_clifford_predicate == any(
28+
isinstance(pred, CliffordCircuitPredicate) for pred in required_predicates
29+
)

0 commit comments

Comments
 (0)