Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stopping condition thresholds #609

Merged
merged 7 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

### Bug fixes

* Ensure the stopping condition decompositions are respected for larger templated QFT and Grover operators.
[(#609)](https://github.com/PennyLaneAI/pennylane-lightning/pull/609)

* Move concurrency group specifications from reusable Docker build workflow to the root workflows.
[(#604)](https://github.com/PennyLaneAI/pennylane-lightning/pull/604)

Expand Down
14 changes: 7 additions & 7 deletions pennylane_lightning/core/lightning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def stopping_condition(self):
and observable) and returns ``True`` if supported by the device."""

def accepts_obj(obj):
if obj.name == "QFT" and len(obj.wires) < 10:
return True
if obj.name == "GroverOperator" and len(obj.wires) < 13:
return True
return (not isinstance(obj, qml.tape.QuantumTape)) and getattr(
self, "supports_operation", lambda name: False
)(obj.name)
if obj.name == "QFT":
return len(obj.wires) < 10
if obj.name == "GroverOperator":
return len(obj.wires) < 13
is_not_tape = not isinstance(obj, qml.tape.QuantumTape)
is_supported = getattr(self, "supports_operation", lambda name: False)(obj.name)
return is_not_tape and is_supported

return qml.BooleanFn(accepts_obj)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class TestDenseMatrixDecompositionThreshold:
input = [
(qml.QFT, 8, True),
(qml.QFT, 10, False),
(qml.QFT, 14, False),
(qml.GroverOperator, 8, True),
(qml.GroverOperator, 13, False),
]

@pytest.mark.parametrize("op, n_wires, condition", input)
def test_threshold(self, op, n_wires, condition):
wires = np.linspace(0, n_wires - 1, n_wires, dtype=int)
wires = range(n_wires)
op = op(wires=wires)
assert ld.stopping_condition.__get__(op)(op) == condition
dev = ld(n_wires)
assert dev.stopping_condition(op) == condition
Loading