Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Parameter-shift rule with postselected MCMs returns wrong values #5943

Open
1 task done
dwierichs opened this issue Jul 4, 2024 · 0 comments
Open
1 task done
Labels
bug 🐛 Something isn't working

Comments

@dwierichs
Copy link
Contributor

Expected behavior

Parameter-shift differentiation with postselected MCMs works or raises an informative error.

Actual behavior

It returns wrong results.

Additional information

This topic has been discovered and discussed extensively, and a fix is known in principle.
We should either implement this fix, or deactivate the differentiation of circuits with postselected MCMs by raising an error.

Source code

x = qml.numpy.array(0.512, requires_grad=True)
for diff_method in ['backprop', 'parameter-shift']:
    print(diff_method)

    @qml.qnode(qml.device("default.qubit"), diff_method=diff_method)
    def circuit(x):
        qml.Hadamard(0)
        qml.CNOT([0, 1])
        qml.RX(x, 1)
        qml.measure(1, postselect=1)
        return qml.expval(qml.Z(0))

    print(qml.grad(circuit)(x))

Tracebacks

backprop
0.48992175838037155
parameter-shift
0.0

System information

pl dev

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@dwierichs dwierichs added the bug 🐛 Something isn't working label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant