qml.QSVT() wire chaos

Hi!

I have some problems with the QSVT() class. I have created my own unitary operator UA using LCU and now I want to use QSVT to invert the matrix. However, the wires of the QSVT() operator are not in the same order as the global wires that I defined in my circuit. When I want to simulate the circuit, I get an error stating that the “wires in circuit are inconsistent with those in wire_order”. I assume this is because of the different wire order of the QSVT operator.

Using this code snippet, one can see that the wire order has changed for the QSVT operator.

import pennylane as qml

class test_op(qml.operation.Operation):

    def __init__(self, wires, id=None):
        super().__init__(wires=wires, id=id)

    def decomposition(self):
        # Define the sequence of operations that make up the custom operation
        ops = []
        for wire in self.wires:
            ops.append(qml.PauliX(wires=wire))
        return ops
wires = ['a', 'b', 'c', 'd', 'e', 'f']
UA = test_op(wires=wires)
projectors = [qml.PCPhase(phi=0.1, dim=2, wires=wires)]*10
qsvt_op = qml.QSVT(UA, projectors)
print(wires, qsvt_op.wires)

These are the wire-lists that are printed at the end:

['a', 'b', 'c', 'd', 'e', 'f'] <Wires = ['f', 'b', 'e', 'a', 'd', 'c']>

Is that a bug and can I manually change the wire order of the QSVT operator?

Here you see my qml.about():

Name: PennyLane
Version: 0.37.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/Q556220/miniconda3/envs/qml/lib/python3.12/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           macOS-14.4-arm64-arm-64bit
Python version:          3.12.4
Numpy version:           1.26.4
Scipy version:           1.14.0
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.37.0)
- default.clifford (PennyLane-0.37.0)
- default.gaussian (PennyLane-0.37.0)
- default.mixed (PennyLane-0.37.0)
- default.qubit (PennyLane-0.37.0)
- default.qubit.autograd (PennyLane-0.37.0)
- default.qubit.jax (PennyLane-0.37.0)
- default.qubit.legacy (PennyLane-0.37.0)
- default.qubit.tf (PennyLane-0.37.0)
- default.qubit.torch (PennyLane-0.37.0)
- default.qutrit (PennyLane-0.37.0)
- default.qutrit.mixed (PennyLane-0.37.0)
- default.tensor (PennyLane-0.37.0)
- null.qubit (PennyLane-0.37.0)

Hi @leolettuce,

You’re right, this is confusing.
Are you mainly interested in obtaining the matrix for qsvt_op?
If that’s the case you can set the wire order.

print(qsvt_op.matrix(wire_order=['a', 'b', 'c', 'd', 'e', 'f']))

Let me know if this is enough for your use case and thank you for bringing this to our attention.

Hi @leolettuce,

I wanted to mention that the wire order issues with QSVT have now been solved! You can see the solution in this PR. It will be available in the next PennyLane release, which should come out in about 1 month. If you need to use it before you can use the development version of PennyLane in the meantime!