Skip to content

Commit

Permalink
Fix stopping condition thresholds (#609)
Browse files Browse the repository at this point in the history
* Fix stopping condition

* Auto update version

* Update changelog

* Update tests to catch decomp fallthrough

* Auto update version

* Trigger CI

---------

Co-authored-by: Dev version update bot <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mlxd and github-actions[bot] authored Feb 12, 2024
1 parent 3527765 commit 006d7e7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
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
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.35.0-dev12"
__version__ = "0.35.0-dev13"
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

0 comments on commit 006d7e7

Please sign in to comment.