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

BraketAwsQubitDevice unnecessarily computes parameter-shifted gradients for SV1. #223

Closed
kshyatt-aws opened this issue Jan 17, 2024 · 3 comments · Fixed by #224
Closed
Labels
bug Something isn't working

Comments

@kshyatt-aws
Copy link
Contributor

Describe the bug

Consider a circuit like:

sv1_device_arn = "arn:aws:braket:::device/quantum-simulator/amazon/sv1"
dm1_device_arn = "arn:aws:braket:::device/quantum-simulator/amazon/dm1"
dev = qml.device("braket.aws.qubit", device_arn=sv1_device_arn, wires=nqubits)
nqubits = 4
@qml.qnode(dev)
def quantum_circuit(input, weights):
    # Prepare circuit here
    for i in range(nqubits):
        qml.H(i)
    # Measurement layer
    return [qml.expval(qml.PauliZ(i)) for i in range(nqubits)]

When SV1 is used, this line is triggered. This will compute parameter-shifted derivatives even on the forward pass, when they should not be computed. This makes running with SV1 ~10x slower (and incurs extra costs) compared to DM1.

To reproduce
Run above code snippet.

Expected behavior
The Braket-PL device should only compute the gradient if it's "really" requested.

Screenshots or logs
N/A

System information
A description of your system. Please provide:

  • Amazon Braket Python PennyLane Plugin version: 1.23.0
  • Amazon Braket Python SDK version: 1.66.0
  • Amazon Braket Python Schemas version: N/A
  • Amazon Braket Python Default Simulator version: N/A
  • Python version: 3.9

Additional context
One other solution would be to avoid calling execute_and_gradients entirely in this case.

@kshyatt-aws kshyatt-aws added the bug Something isn't working label Jan 17, 2024
@speller26 speller26 linked a pull request Jan 18, 2024 that will close this issue
5 tasks
@speller26
Copy link
Member

The problem is execute_and_gradients being automatically called if the device supports its own gradient computation method and the execution is analytic (shots = 0); this is decided upstream by PennyLane, and isn't controlled in the plugin. However, I've added a warning to the parameter-shift fallback path.

@speller26
Copy link
Member

Did not intend to auto-close the issue

@speller26 speller26 reopened this Jan 18, 2024
@laurencap
Copy link

@kshyatt-aws confirmed with me that we can close the issue, since any additional work would be outside this repo. Thanks!

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

Successfully merging a pull request may close this issue.

3 participants