pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

[BUG] Torch interface incompatibility with finite-shot mid-circuit measurements

Open trbromley opened this issue 10 months ago • 3 comments

Expected behavior

Able to execute the following QNode which includes:

  • Use of torch interface
  • Use of mid-circuit measurements
  • Finite shots and a sample-based output

Actual behavior

Error when following QNode is executed.

Additional information

No response

Source code

import pennylane as qml
import torch

dev = qml.device("default.qubit", shots=10)

@qml.qnode(dev, interface="torch")
def f(x):
    qml.RX(x, 0)
    for i in range(5):
        qml.Hadamard(0)
        qml.measure(0)
    return qml.sample(qml.PauliX(0))

x = torch.tensor(0.4)
f(x)

Tracebacks

AttributeError: 'Tensor' object has no attribute 'append'

System information

On the PL dev branch.

Existing GitHub issues

  • [X] I have searched existing GitHub issues to make sure the issue does not already exist.

trbromley avatar Mar 27 '24 13:03 trbromley

Related to this forum post.

trbromley avatar Mar 27 '24 13:03 trbromley

CC @vincentmr.

trbromley avatar Mar 27 '24 13:03 trbromley

Different errors, but also fails for jax and tensorflow.

albi3ro avatar Mar 28 '24 13:03 albi3ro