PennyLaneAI / catalyst

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

[Bug] `mcm_method="one-shot"` and `mcm_method="single-branch-statistics"` return differently shaped sample arrays #877

Open josh146 opened 1 week ago

josh146 commented 1 week ago
dev = qml.device("lightning.qubit", wires=5, shots=20)

@qml.qjit
@qml.qnode(dev, mcm_method="one-shot", postselect_mode="fill-shots")
def one_shot(x):
    qml.RX(x, wires=0)
    m_0 = catalyst.measure(0, postselect=1)
    return qml.sample(wires=0)

@qml.qjit
@qml.qnode(dev, mcm_method="single-branch-statistics", postselect_mode="fill-shots")
def sbs(x):
    qml.RX(x, wires=0)
    m_0 = catalyst.measure(0, postselect=1)
    return qml.sample(wires=0)
>>> one_shot(0.9)
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
>>> sbs(0.9)
array([[1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1],
       [1]])
dime10 commented 1 week ago

Duplicate of https://github.com/PennyLaneAI/catalyst/issues/521

josh146 commented 1 week ago

Ah! I guess the difference here is that the difference in shape both happens with @qjit applied, so from a user perspective it looks like a different bug