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

Improve performance for default.qubit.compute_vjp #4841

Merged
merged 19 commits into from
Nov 30, 2023
Merged

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Nov 14, 2023

[sc-46350]

For 10 qubits, 2 strongly entangling layers, and an expval on each wire:

Before these changes:

Screenshot 2023-11-15 at 9 54 01 AM

After these changes:

Screenshot 2023-11-15 at 9 54 58 AM

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

pennylane/qnode.py Outdated Show resolved Hide resolved
@albi3ro albi3ro marked this pull request as ready for review November 29, 2023 14:50
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (48aeec8) 99.65% compared to head (7da1555) 99.64%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4841      +/-   ##
==========================================
- Coverage   99.65%   99.64%   -0.02%     
==========================================
  Files         387      387              
  Lines       35018    34772     -246     
==========================================
- Hits        34898    34649     -249     
- Misses        120      123       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@vincentmr vincentmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @albi3ro .

pennylane/devices/qubit/adjoint_jacobian.py Show resolved Hide resolved
@albi3ro
Copy link
Contributor Author

albi3ro commented Nov 29, 2023

Updated benchmarks:

n_wires = 17
n_layers = 3

dev = qml.device('default.qubit')

shape = qml.StronglyEntanglingLayers.shape(n_wires=n_wires, n_layers=n_layers)
rng = qml.numpy.random.default_rng(seed=42)
params = rng.random(shape)
params_jax = jax.numpy.array(params)
params_torch = torch.tensor(params, requires_grad=True)
params_tf = tf.Variable(params)


@qml.qnode(dev, diff_method="adjoint", device_vjp=True)
def circuit_dev_jp(params):
    qml.StronglyEntanglingLayers(params, wires=range(n_wires))
    return [qml.expval(qml.PauliZ(i)) for i in range(n_wires)]

@qml.qnode(dev, diff_method="adjoint", device_vjp=False)
def circuit_dev_jac(params):
    qml.StronglyEntanglingLayers(params, wires=range(n_wires))
    return [qml.expval(qml.PauliZ(i)) for i in range(n_wires)]

Screenshot 2023-11-29 at 12 04 21 PM

Screenshot 2023-11-29 at 12 00 49 PM

@albi3ro albi3ro requested a review from a team November 29, 2023 17:53
@albi3ro albi3ro enabled auto-merge (squash) November 30, 2023 19:28
@albi3ro albi3ro merged commit 2de14a4 into master Nov 30, 2023
34 checks passed
@albi3ro albi3ro deleted the vjp-performance branch November 30, 2023 21:36
@albi3ro
Copy link
Contributor Author

albi3ro commented Dec 1, 2023

[sc-51361]

mudit2812 pushed a commit that referenced this pull request Dec 7, 2023
[sc-46350]

For 10 qubits, 2 strongly entangling layers, and an expval on each wire:


Before these changes:

<img width="837" alt="Screenshot 2023-11-15 at 9 54 01 AM"
src="https://github.com/PennyLaneAI/pennylane/assets/6364575/f8f08f51-700b-4e2d-9952-bed95a2eac2a">


After these changes:

<img width="806" alt="Screenshot 2023-11-15 at 9 54 58 AM"
src="https://github.com/PennyLaneAI/pennylane/assets/6364575/f94bfdc1-b0f8-44e8-ae3e-d5c67bb8e0f4">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants