amazon-braket / amazon-braket-pennylane-plugin-python

A plugin for allowing Xanadu PennyLane to use Amazon Braket devices
https://amazon-braket-pennylane-plugin-python.readthedocs.io/
Apache License 2.0
44 stars 38 forks source link

Support `qml.counts` for circuits #195

Closed yitchen-tim closed 1 month ago

yitchen-tim commented 11 months ago

Describe the feature you'd like qml.counts is already supported for AHS programs. There is a great value in making qml.counts available for circuits.

How would this feature be used? Please describe.

import pennylane as qml
dev = qml.device("braket.local.qubit", wires=2, shots=100)

@qml.qnode(dev)
def test_circ():
    qml.PauliZ(0)
    return qml.counts()

test_circ()

returning measurement counts.

Describe alternatives you've considered Today, users has to change their circuit to use a Braket supported return type such as qml.expval(qml.PauliZ(0))

@qml.qnode(dev)
def test_circ():
    qml.PauliZ(0)
    return qml.expval(qml.PauliZ(0))

and then do

test_circ.device.task.result().measurement_counts

Users could not use the same circuit to first test on a pennylane simulator before running on a Braket QPU. Also, users do not want to know qml.expval(qml.PauliZ(0)), they just use it to get the circuit to run, so that they can get the measurement_counts stored in the plugin device. Furthermore, when using batch_execute, test_circ.device.task is empty. Users need to go to console and find the results of the tasks they submitted.

Mostafa-Atallah2020 commented 1 month ago

I am asking to work on this issue for uhack me and my teammate @Tatgithub02

anushkrishnav commented 1 month ago

@yitchen-tim I went over the code base, seems like an interesting problem, can you elobrate more on this ? Do you want me to implement the count method from qml or ??

yitchen-tim commented 1 month ago

HI @anushkrishnav , thanks for the interest in contributing. When using Braket backend such as Braket local simulator, the qml.counts() throws error. I have updated the full code in the description that reproduces the error. So yes, this issue is about adding support of returning counts to Braket backends.

For more examples about using Braket backends in pennylane, you can refer to the example notebooks in here.

king-p3nguin commented 1 month ago

Hi, I would also like to work on this issue for the unitaryhack.