From 3e9f7325c3da90eb901ace6862b10187e245abb4 Mon Sep 17 00:00:00 2001 From: Astral Cai Date: Tue, 12 Nov 2024 14:29:22 -0500 Subject: [PATCH] try this --- tests/test_gates.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/test_gates.py b/tests/test_gates.py index bc586cb9d..93ecd8ac7 100644 --- a/tests/test_gates.py +++ b/tests/test_gates.py @@ -28,6 +28,22 @@ pytest.skip("No binary module found. Skipping.", allow_module_level=True) +def _get_ld_operations(): + """Gets a set of supported operations by LightningDevice.""" + + operations = set() + for op, prop in ld.capabilities.operations.items(): + operations.add(op.__name__) + if prop.controllable: + operations.add(f"C({op.__name__})") + if prop.invertible: + operations.add(f"Adjoint({op.__name__})") + return operations + + +ld_operations = _get_ld_operations() + + @pytest.fixture def op(op_name): ops_list = { @@ -87,7 +103,7 @@ def op(op_name): return ops_list.get(op_name) -@pytest.mark.parametrize("op_name", ld.operations) +@pytest.mark.parametrize("op_name", ld_operations) def test_gate_unitary_correct(op, op_name): """Test if lightning device correctly applies gates by reconstructing the unitary matrix and comparing to the expected version""" @@ -153,7 +169,7 @@ def output(input): assert np.allclose(unitary, unitary_expected) -@pytest.mark.parametrize("op_name", ld.operations) +@pytest.mark.parametrize("op_name", ld_operations) def test_gate_unitary_correct_lt(op, op_name): """Test if lightning device correctly applies gates by reconstructing the unitary matrix and comparing to the expected version""" @@ -187,7 +203,7 @@ def output(input): assert np.allclose(unitary, unitary_expected) -@pytest.mark.parametrize("op_name", ld.operations) +@pytest.mark.parametrize("op_name", ld_operations) def test_inverse_unitary_correct(op, op_name): """Test if lightning device correctly applies inverse gates by reconstructing the unitary matrix and comparing to the expected version"""