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 of differentiable matrix calculations for Pauli Sentences #5578

Merged
merged 17 commits into from
Apr 26, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Apr 25, 2024

Context:

The new operator arithmetic now enabled provides a fully differentiable pathway for calculating the matrix that was not available before.

Unfortunately, a differentiable calculation of a large dense matrix can be quite slow, and users may not realize they should be using a sparse matrix formulation instead. Just because we offer it does not make it a universally good idea.

This PR hopes to close some of that performance gap, by taking advantage of the structure of pauli sentences to improve the efficiency of calculating the matrix.

Description of the Change:

Adds in a new pathway for calculating the matrix of a pauli sentence.

Benefits:

Some performance numbers for the H5 molecule follow:

Screenshot 2024-04-25 at 9 57 05 AM

While the differentiable matrix is still not as fast as sparse matrix calculation, this method makes up a lot of ground. Note that the dense matrix is now on the same order of magnitude as the sparse matrix calculation for the legacy hamiltonian.

This formulation is also jit-able, and jitting the calculation of the matrix allows us to pick up another order of magnitude improvement.

Possible Drawbacks:

Dense is still not as fast as the sparse matrix, and might not scale as well as the sparse formulation.

Also, this pathway is much less intuitive and involves some numerical black magic.

Related GitHub Issues:

@albi3ro albi3ro requested a review from a team as a code owner April 25, 2024 14:07
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.

@albi3ro albi3ro requested review from vincentmr and mlxd April 25, 2024 14:09
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.

pennylane/pauli/pauli_arithmetic.py Show resolved Hide resolved
@Qottmann
Copy link
Contributor

[sc-58850]

Copy link

codecov bot commented Apr 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.69%. Comparing base (9151477) to head (94974a3).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5578      +/-   ##
==========================================
- Coverage   99.69%   99.69%   -0.01%     
==========================================
  Files         410      412       +2     
  Lines       38278    38269       -9     
==========================================
- Hits        38161    38151      -10     
- Misses        117      118       +1     

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

@trbromley trbromley added this to the v0.36 milestone Apr 26, 2024
Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

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

Thanks @albi3ro! A changelog entry would be very appreciated as this is a nice perf improvement.

tests/devices/qubit/test_apply_operation.py Show resolved Hide resolved
@albi3ro albi3ro requested a review from mudit2812 April 26, 2024 19:21
@trbromley
Copy link
Contributor

Note that this supersedes #5392.

Copy link
Contributor

@mudit2812 mudit2812 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. I'm happy with the tests mostly, but looks like interface testing could be bumped up a bit as codecov is failing on the branches for casting for tensorflow

@mudit2812 mudit2812 added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label Apr 26, 2024
@astralcai astralcai enabled auto-merge (squash) April 26, 2024 22:08
@astralcai astralcai merged commit 85c8528 into master Apr 26, 2024
37 checks passed
@astralcai astralcai deleted the pauli_sentence_matris branch April 26, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants