Hi there,
I have been building circuits using qml.QubitUnitary
and am getting confused by the wiring convention in Pennylane when using more than 2 wires in a single operation.
Consider the following example
import pennylane as qml
dev2 = qml.device('default.qubit', wires=2)
@qml.qnode(dev2)
def circuit2():
qml.Hadamard(wires=0)
return qml.probs(wires=[0,1])
Executing circuit2()
returns
array([0.5, 0. , 0.5, 0. ])
This corresponds to the superposition |00> + |10>, so I deduce that the wire numbers passed as argument to qml.probs
are ordered from most significant to least significant qubit.
Expanding this example to three qubits,
dev3 = qml.device('default.qubit', wires=3)
@qml.qnode(dev3)
def circuit3():
qml.Hadamard(wires=0)
return qml.probs(wires=[0,1,2])
and executing circuit3()
, we obtain as expected
array([0.5, 0. , 0. , 0. , 0.5, 0. , 0. , 0. ])
By reordering the wires to [1,2,0]
, I would now expect to obtain
array([0.5 , 0.5, 0. , 0. , 0. , 0. , 0., 0. ])
but instead I get
>>> @qml.qnode(dev3)
... def circuit3b():
... qml.Hadamard(wires=0)
... return qml.probs(wires=[1,2,0])
...
>>> circuit3b()
array([0.5, 0. , 0.5, 0. , 0. , 0. , 0. , 0. ])
The same ordering seems to be used for qml.QubitUnitary
. What is wrong in my reasoning?