catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

`qml.sample` differs in shape when using Catalyst

Open erick-xanadu opened this issue 2 years ago • 2 comments

from catalyst import qjit, measure, cond
import pennylane as qml

@qml.qnode(qml.device("lightning.qubit", wires=1, shots=100))
def circuit():
    return qml.sample()

print(circuit().shape)
print(qjit(circuit)().shape)
$ python test.py 
(100,)
(100, 1)

erick-xanadu avatar Feb 15 '24 21:02 erick-xanadu

Not a bug, that is how we return the samples, but it would be a nice improvement to unify the output. Could probably be solved together with #341

dime10 avatar Feb 15 '24 23:02 dime10

Note that PennyLane always produces a 2D array (n_shots, n_qubits), except when there is only one wire. I think this is a bit inconsistent so I've proposed to adjust this on the PennyLane side.

dime10 avatar Apr 08 '24 21:04 dime10