From 7d1b0e5af4d907b2f65b563b5d23f8a137fcd00b Mon Sep 17 00:00:00 2001 From: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:14:29 -0500 Subject: [PATCH] Add `work_wires` property to `GroverOperator` (#6738) **Context:** `qml.GroverOperator` now has a `work_wires` property similar to `MultiControlledX`. **Benefits:** Nice to have. **Possible Drawbacks:** None identified. **Related GitHub Issues:** Fixes #6591 [sc-78409] --------- Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com> --- doc/releases/changelog-dev.md | 3 +++ pennylane/templates/subroutines/grover.py | 5 +++++ tests/templates/test_subroutines/test_grover.py | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 8df2567e397..b2a3d3c32d4 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -341,6 +341,9 @@ such as `shots`, `rng` and `prng_key`.

Other Improvements

+* `qml.GroverOperator` now has a `work_wires` property. + [(#6738)](https://github.com/PennyLaneAI/pennylane/pull/6738) + * `Wires` object usage across Pennylane source code has been tidied up. [(#6689)](https://github.com/PennyLaneAI/pennylane/pull/6689) diff --git a/pennylane/templates/subroutines/grover.py b/pennylane/templates/subroutines/grover.py index 1d051fd3fe5..938db918d87 100644 --- a/pennylane/templates/subroutines/grover.py +++ b/pennylane/templates/subroutines/grover.py @@ -123,6 +123,11 @@ def __init__(self, wires: WiresLike, work_wires: WiresLike = (), id=None): super().__init__(wires=wires, id=id) + @property + def work_wires(self): + """Additional auxiliary wires that can be used in the decomposition of :class:`~.MultiControlledX`.""" + return self.hyperparameters["work_wires"] + @property def num_params(self): return 0 diff --git a/tests/templates/test_subroutines/test_grover.py b/tests/templates/test_subroutines/test_grover.py index 4839f9cc613..c7ca2a87d16 100644 --- a/tests/templates/test_subroutines/test_grover.py +++ b/tests/templates/test_subroutines/test_grover.py @@ -31,6 +31,12 @@ def test_repr(): assert repr(op) == expected +def test_work_wire_property(): + op = qml.GroverOperator(wires=(0, 1, 2), work_wires=(3, 4)) + expected = qml.wires.Wires((3, 4)) + assert op.work_wires == expected + + def test_standard_validity(): """Test the standard criteria for a valid operation.""" work_wires = qml.wires.Wires((3, 4))