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

Add pauli_rep diagonalization #6113

Merged
merged 19 commits into from
Sep 9, 2024
Merged

Add pauli_rep diagonalization #6113

merged 19 commits into from
Sep 9, 2024

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Aug 16, 2024

Context:
The diagonalization transform should default to the faster pauli implementation if all the observables have a pauli_rep and we are diagonalizing everything to the measurement basis.

Description of the Change:
Check if above contitions apply, and if so, use diagonalization via rotations_and_diagonal_measurements and diagonalize_qwc_pauli_words instead. Allow conversion to either Z or eigvals for both methods.

Also includes a bug fix where the fallback method was failing to raise an error for non-commuting measurements when one of the measurements had no observable (like qml.sample()).

Benefits:
A common use case (all pauli words, everything has to be in the measurement basis) is diagonalized more efficiently.

Related Shortcut Stories:
[sc-60179]

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.

@lillian542 lillian542 marked this pull request as ready for review August 27, 2024 18:57
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (df63953) to head (0c30b7b).
Report is 348 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6113      +/-   ##
==========================================
+ Coverage   98.72%   99.60%   +0.88%     
==========================================
  Files         446      446              
  Lines       42934    42492     -442     
==========================================
- Hits        42386    42326      -60     
+ Misses        548      166     -382     

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

@lillian542 lillian542 changed the title [WIP] Add pauli_rep diagonalization Add pauli_rep diagonalization Aug 28, 2024
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Thanks, this was quite instructive to study.

I think in the PR branch there are some typos in doc (for example supported_base_obs), but it looks like these have been fixed so it would only be necessary to merge from master.

I don't want to block this PR since it seems good to me. Still, I think I should not be the final reviewer since I still lack sufficient context about this project. Potentially, someone who reviewed the first PR and who is more familiar with Pauli words would be more recommended for the final approval.

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍

@lillian542 lillian542 requested a review from mudit2812 September 6, 2024 17:53
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.

Minor docstring fixes, otherwise looks good. 🚀

lillian542 and others added 2 commits September 6, 2024 15:19
@lillian542 lillian542 enabled auto-merge (squash) September 6, 2024 19:30
@lillian542 lillian542 disabled auto-merge September 8, 2024 16:26
@lillian542 lillian542 added this pull request to the merge queue Sep 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 8, 2024
@lillian542 lillian542 enabled auto-merge (squash) September 9, 2024 14:05
@lillian542 lillian542 merged commit 15440c2 into master Sep 9, 2024
37 checks passed
@lillian542 lillian542 deleted the pauli_rep_diagonalize branch September 9, 2024 14:34
mudit2812 added a commit that referenced this pull request Sep 10, 2024
**Context:**
The diagonalization transform should default to the faster pauli
implementation if all the observables have a `pauli_rep` and we are
diagonalizing everything to the measurement basis.

**Description of the Change:**
Check if above contitions apply, and if so, use diagonalization via
`rotations_and_diagonal_measurements` and `diagonalize_qwc_pauli_words`
instead. Allow conversion to either `Z` or `eigvals` for both methods.

Also includes a bug fix where the fallback method was failing to raise
an error for non-commuting measurements when one of the measurements had
no observable (like `qml.sample()`).

**Benefits:**
A common use case (all pauli words, everything has to be in the
measurement basis) is diagonalized more efficiently.

**Related Shortcut Stories:**
[sc-60179]

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
mudit2812 added a commit that referenced this pull request Sep 12, 2024
**Context:**
The diagonalization transform should default to the faster pauli
implementation if all the observables have a `pauli_rep` and we are
diagonalizing everything to the measurement basis.

**Description of the Change:**
Check if above contitions apply, and if so, use diagonalization via
`rotations_and_diagonal_measurements` and `diagonalize_qwc_pauli_words`
instead. Allow conversion to either `Z` or `eigvals` for both methods.

Also includes a bug fix where the fallback method was failing to raise
an error for non-commuting measurements when one of the measurements had
no observable (like `qml.sample()`).

**Benefits:**
A common use case (all pauli words, everything has to be in the
measurement basis) is diagonalized more efficiently.

**Related Shortcut Stories:**
[sc-60179]

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
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