amazon-braket-pennylane-plugin-python icon indicating copy to clipboard operation
amazon-braket-pennylane-plugin-python copied to clipboard

Support `qml.sample()` without specifying the observable

Open king-p3nguin opened this issue 8 months ago • 2 comments

Issue #, if available: Related to #98

Description of changes:

  • qml.sample() can now be used without specifying the observable.

Example:

import pennylane as qml
from pennylane import numpy as np

dev_managed_sim = qml.device(
    "braket.aws.qubit",
    device_arn="arn:aws:braket:::device/quantum-simulator/amazon/sv1",
    wires=2,
    shots=10,
)

@qml.qnode(dev_managed_sim)
def circuit(a):
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RX(a, wires=1)
    # return qml.sample(qml.PauliZ(0))
    # return qml.sample()
    return qml.sample(wires=[0])


# x = np.array(0.543)
x = np.array([0.543, 0.3])
print(circuit(x))

output:

[[0 1 0 1 1 0 0 1 1 1]
 [1 0 1 0 1 0 0 1 1 0]]

Testing done:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • [x] I have read the CONTRIBUTING doc
  • [x] I used the commit message format described in CONTRIBUTING
  • [x] I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • [x] I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • [x] I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

king-p3nguin avatar Jun 07 '24 09:06 king-p3nguin