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

Improve QROM decomposition if no work wires provided #6967

Merged
merged 8 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,14 @@
passed to the `QNode`, instead of assuming the method is always `deferred`.
[(#6903)](https://github.com/PennyLaneAI/pennylane/pull/6903)

* The `QROM` template is upgraded to decompose more efficiently when `work_wires` are not used.
[#6967)](https://github.com/PennyLaneAI/pennylane/pull/6967)

<h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):

Guillermo Alonso,
Utkarsh Azad,
Henry Chang,
Yushao Chen,
Expand Down
2 changes: 1 addition & 1 deletion pennylane/templates/subroutines/qrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def compute_decomposition(
)
swap_ops.insert(0, qml.ctrl(new_op, control=control_swap_wires[-ind - 1]))

if not clean:
if not clean or depth == 1:
# Based on this paper (Fig 1.c): https://arxiv.org/abs/1812.00954
decomp_ops = select_ops + swap_ops

Expand Down
25 changes: 25 additions & 0 deletions tests/templates/test_subroutines/test_qrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ class TestQROM:
@pytest.mark.parametrize(
("bitstrings", "target_wires", "control_wires", "work_wires", "clean"),
[
(
["111", "101", "100", "110"],
[0, 1, 2],
[3, 4],
None,
False,
),
(
["111", "101", "100", "110"],
[0, 1, 2],
[3, 4],
None,
True,
),
(
["11", "01", "00", "10"],
[0, 1],
Expand Down Expand Up @@ -258,3 +272,14 @@ def test_wrong_wires_error(bitstrings, control_wires, target_wires, msg_match):
"""Test that error is raised if more ops are requested than can fit in control wires"""
with pytest.raises(ValueError, match=msg_match):
qml.QROM(bitstrings, control_wires, target_wires, work_wires=None)


def test_none_work_wires_case():
"""Test that clean version is not applied if work wires are not used"""

gates_clean = qml.QROM.compute_decomposition(["1", "0", "0", "1"], [0, 1], [2], [], clean=True)
expected_gates = qml.QROM.compute_decomposition(
["1", "0", "0", "1"], [0, 1], [2], [], clean=False
)

assert gates_clean == expected_gates