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 grover operator work wires #4668

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@

<h3>Bug fixes 🐛</h3>

* Providing `work_wires=None` to `qml.GroverOperator` no longer interprets `None` as a wire.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
[(#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)

Expand Down
5 changes: 4 additions & 1 deletion pennylane/templates/subroutines/grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def __init__(self, wires=None, work_wires=None, id=None):
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 else Wires([]),
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
}

super().__init__(wires=wires, id=id)

Expand Down
6 changes: 6 additions & 0 deletions tests/templates/test_subroutines/test_grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Loading