Skip to content

Commit

Permalink
qsvt wire order (#6212)
Browse files Browse the repository at this point in the history
The order of the wires is not correct.
First we must take those of the projector

---------

Co-authored-by: Austin Huang <[email protected]>
  • Loading branch information
KetpuntoG and austingmhuang authored Sep 5, 2024
1 parent b47ef1c commit b37234d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
* Fix `qml.PrepSelPrep` template to work with `torch`:
[(#6191)](https://github.com/PennyLaneAI/pennylane/pull/6191)

<h3>Contributors ✍️</h3>
* The ``qml.QSVT`` template now orders the ``projector`` wires first and the ``UA`` wires second, which is the expected order of the decomposition.
[(#6212)](https://github.com/PennyLaneAI/pennylane/pull/6212)

* <h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):

Guillermo Alonso
Utkarsh Azad
Jack Brown
Christina Lee
Expand Down
4 changes: 2 additions & 2 deletions pennylane/templates/subroutines/qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ def __init__(self, UA, projectors, id=None):
"projectors": projectors,
}

total_wires = qml.wires.Wires(UA.wires) + qml.wires.Wires.all_wires(
total_wires = qml.wires.Wires.all_wires(
[proj.wires for proj in projectors]
)
) + qml.wires.Wires(UA.wires)

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

Expand Down
7 changes: 4 additions & 3 deletions tests/templates/test_subroutines/test_qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ def test_decomposition_queues_its_contents(self):
def test_wire_order(self):
"""Test that the wire order is preserved."""

op = qml.QFT(wires=[2, 1])
qsvt_wires = qml.QSVT(op, [op]).wires
assert qsvt_wires == op.wires
op1 = qml.GroverOperator(wires=[0, 3])
op2 = qml.QFT(wires=[2, 1])
qsvt_wires = qml.QSVT(op2, [op1]).wires
assert qsvt_wires == op1.wires + op2.wires

@pytest.mark.parametrize(
("quantum_function", "phi_func", "A", "phis", "results"),
Expand Down

0 comments on commit b37234d

Please sign in to comment.