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 333fa91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tests/integration/backend_test.py
Original file line number Diff line number Diff line change
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
26 changes: 26 additions & 0 deletions tests/unit/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from pytket.predicates import CliffordCircuitPredicate

from pytket.extensions.quantinuum import QuantinuumAPIOffline, QuantinuumBackend


@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(
api_handler=qapi_offline,
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 333fa91

Please sign in to comment.