PennyLaneAI / catalyst

A JIT compiler for hybrid quantum programs in PennyLane
https://docs.pennylane.ai/projects/catalyst
Apache License 2.0
131 stars 29 forks source link

`qml.sample` differs in shape when using Catalyst #521

Open erick-xanadu opened 7 months ago

erick-xanadu commented 7 months ago
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)
dime10 commented 7 months ago

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 commented 6 months ago

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.