Repository: PennyLaneAI/pennylane
Pull request #4668 (2023-10-12 13:37:30)

Fix grover operator work wires
The default to `GroverOperator` for work wires was `None`. Unfortunately this was being interpreted as `work_wires = Wires([None,])`.  This PR makes it so that `work_wires=None` is interpreted as `work_wires = Wires([])`.

Fixes https://github.com/PennyLaneAI/pennylane-qiskit/issues/339

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4668?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
All modified lines are covered by tests :white_check_mark:
> Comparison is base [(`ea7e1d4`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/ea7e1d4e4c5039aec9d4b9c059f1829d7dd10630?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.63% compared to head [(`a1c5529`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4668?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.63%.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #4668   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         376      376           
  Lines       33672    33672           
=======================================
  Hits        33548    33548           
  Misses        124      124           
```


| [Files](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4668?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) | Coverage Δ | |
|---|---|---|
| [pennylane/templates/subroutines/grover.py](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4668?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#diff-cGVubnlsYW5lL3RlbXBsYXRlcy9zdWJyb3V0aW5lcy9ncm92ZXIucHk=) | `100.00% <100.00%> (ø)` | |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4668?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).


Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 3d7a8d7fc..d500a55ed 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -340,6 +340,9 @@
 
 <h3>Bug fixes 🐛</h3>
 
+* Providing `work_wires=None` to `qml.GroverOperator` no longer interprets `None` as a wire.
+  [(#4668)](https://github.com/PennyLaneAI/pennylane/pull/4668)
+
 * Fixed issue where `__copy__` method of the `qml.Select()` operator attempted to access un-initialized data.
 [(#4551)](https://github.com/PennyLaneAI/pennylane/pull/4551)
 
diff --git a/pennylane/templates/subroutines/grover.py b/pennylane/templates/subroutines/grover.py
index b6178e0e7..5f3cbf094 100644
--- a/pennylane/templates/subroutines/grover.py
+++ b/pennylane/templates/subroutines/grover.py
@@ -113,7 +113,10 @@ class GroverOperator(Operation):
         if (not hasattr(wires, "__len__")) or (len(wires) < 2):
             raise ValueError("GroverOperator must have at least two wires provided.")
 
-        self._hyperparameters = {"n_wires": len(wires), "work_wires": Wires(work_wires)}
+        self._hyperparameters = {
+            "n_wires": len(wires),
+            "work_wires": Wires(work_wires) if work_wires is not None else Wires([]),
+        }
 
         super().__init__(wires=wires, id=id)
 


Test patch:
diff --git a/tests/templates/test_subroutines/test_grover.py b/tests/templates/test_subroutines/test_grover.py
index bc2f0dce0..987ef2d5d 100644
--- a/tests/templates/test_subroutines/test_grover.py
+++ b/tests/templates/test_subroutines/test_grover.py
@@ -62,6 +62,12 @@ def test_work_wires():
     assert ops[2].hyperparameters["work_wires"] == work_wire
 
 
+def test_work_wires_None():
+    """Test that work wires of None are not inpreted as work wires."""
+    op = qml.GroverOperator(wires=(0, 1, 2, 3), work_wires=None)
+    assert op.hyperparameters["work_wires"] == qml.wires.Wires([])
+
+
 @pytest.mark.parametrize("bad_wires", [0, (0,), tuple()])
 def test_single_wire_error(bad_wires):
     """Assert error raised when called with only a single wire"""