Skip to content

Commit

Permalink
Fixing bug QSVT wire order (PennyLaneAI#5959)
Browse files Browse the repository at this point in the history
**Context:** 
The order of the wires in QSVT is not maintained as they are used as a
set internally.

**issue**
Solves issue PennyLaneAI#5965

---------

Co-authored-by: soranjh <[email protected]>
  • Loading branch information
KetpuntoG and soranjh committed Jul 12, 2024
1 parent 50def12 commit f1b5e31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

<h3>Bug fixes 🐛</h3>

* `qml.QSVT` is updated to store wire order correctly.
[(#5959)](https://github.com/PennyLaneAI/pennylane/pull/5959)

* `qml.devices.qubit.measure_with_samples` now returns the correct result if the provided measurements
contain sum of operators acting on the same wire.
[(#5978)](https://github.com/PennyLaneAI/pennylane/pull/5978)
Expand All @@ -66,7 +69,7 @@
<h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):

Guillermo Alonso,
Ahmed Darwish,
Astral Cai,
Yushao Chen,
Expand Down
6 changes: 3 additions & 3 deletions pennylane/templates/subroutines/qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ def __init__(self, UA, projectors, id=None):
"projectors": projectors,
}

ua_wires = UA.wires.toset()
proj_wires = set.union(*(proj.wires.toset() for proj in projectors))
total_wires = qml.wires.Wires(UA.wires) + qml.wires.Wires.all_wires(
[proj.wires for proj in projectors]
)

total_wires = ua_wires.union(proj_wires)
super().__init__(wires=total_wires, id=id)

def map_wires(self, wire_map: dict):
Expand Down
7 changes: 7 additions & 0 deletions tests/templates/test_subroutines/test_qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ def test_decomposition_queues_its_contents(self):
for op1, op2 in zip(ops, decomp):
qml.assert_equal(op1, op2)

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

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

0 comments on commit f1b5e31

Please sign in to comment.