Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
astralcai committed Nov 12, 2024
1 parent e1c6638 commit 3e9f732
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 3e9f732

Please sign in to comment.