From b37234d6e01397f1573b925aa721a63edcd527b4 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Thu, 5 Sep 2024 10:24:45 -0400
Subject: [PATCH] qsvt wire order (#6212)
The order of the wires is not correct.
First we must take those of the projector
---------
Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com>
---
doc/releases/changelog-dev.md | 6 +++++-
pennylane/templates/subroutines/qsvt.py | 4 ++--
tests/templates/test_subroutines/test_qsvt.py | 7 ++++---
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index be08cf91ec4..813ee6374e4 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -34,10 +34,14 @@
* Fix `qml.PrepSelPrep` template to work with `torch`:
[(#6191)](https://github.com/PennyLaneAI/pennylane/pull/6191)
-
Contributors ✍️
+* 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)
+
+* Contributors ✍️
This release contains contributions from (in alphabetical order):
+Guillermo Alonso
Utkarsh Azad
Jack Brown
Christina Lee
diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py
index 42d8fcff7fe..e272811a733 100644
--- a/pennylane/templates/subroutines/qsvt.py
+++ b/pennylane/templates/subroutines/qsvt.py
@@ -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)
diff --git a/tests/templates/test_subroutines/test_qsvt.py b/tests/templates/test_subroutines/test_qsvt.py
index acb08c00ad6..81046fd40c8 100644
--- a/tests/templates/test_subroutines/test_qsvt.py
+++ b/tests/templates/test_subroutines/test_qsvt.py
@@ -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"),