Skip to content

Commit

Permalink
Add / update tests for predicates in stabiliser sim
Browse files Browse the repository at this point in the history
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 compilation, rather
than breaking on get_result().
  • Loading branch information
isobelhooper committed Jan 16, 2025
1 parent 50a165f commit 1c671f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tests/integration/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
QuantinuumAPI,
QuantinuumAPIError,
)
from pytket.extensions.quantinuum.backends.quantinuum import _ALL_GATES, GetResultFailed
from pytket.extensions.quantinuum.backends.quantinuum import _ALL_GATES
from pytket.predicates import CompilationUnit
from pytket.wasm import WasmFileHandler

Expand Down Expand Up @@ -597,17 +597,11 @@ def test_simulator(
assert len(stab_counts) == 2

# test non-clifford circuit fails on stabilizer backend
# unfortunately the job is accepted, then fails, so have to check get_result
non_stab_circ = (
Circuit(2, name="non_stab_circ").H(0).Rx(0.1, 0).CX(0, 1).measure_all()
)
non_stab_circ = stabilizer_backend.get_compiled_circuit(non_stab_circ)
broken_handle = stabilizer_backend.process_circuit(
non_stab_circ, n_shots, language=language
)

with pytest.raises(GetResultFailed) as _:
_ = stabilizer_backend.get_result(broken_handle)
with pytest.raises(CircuitNotValidError):
_ = stabilizer_backend.get_compiled_circuit(non_stab_circ)


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

from pytket.extensions.quantinuum import QuantinuumAPIOffline, QuantinuumBackend
from pytket.predicates import CliffordCircuitPredicate


@pytest.mark.parametrize(
"simulator_type,should_have_clifford_predicate",
[
("state-vector", False),
("stabilizer", True),
],
)
def test_clifford_circuits_for_stabilizer(
simulator_type: str,
should_have_clifford_predicate: bool,
) -> None:
qapi_offline = QuantinuumAPIOffline()
backend = QuantinuumBackend(
"H1-1E",
api_handler=qapi_offline, # type: ignore
simulator=simulator_type,
)
required_predicates = backend.required_predicates
assert should_have_clifford_predicate == any(
isinstance(pred, CliffordCircuitPredicate) for pred in required_predicates
)

0 comments on commit 1c671f3

Please sign in to comment.