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 grouping support for arithmetic ops #5070

Merged
merged 41 commits into from Feb 7, 2024
Merged

Add grouping support for arithmetic ops #5070

merged 41 commits into from Feb 7, 2024

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Jan 15, 2024

Context:
Adding support for Prod and SProd to be used with grouping.

Description of the Change:

  • Update Tensor.__matmul__ to stop mutating in-place and return a new op instead.
  • Added Pauli rep to Tensor. Consequently, Tensor.copy() and Tensor.map_wires() also had to be updated.
  • Moved around code inside Tensor__init__ to fix incorrect validation after the previous changes. The warning about overlapping wires is now raised in Tensor.queue() instead of at the beginning of construction, so that raising the warning pre-maturely can be prevented.
  • qml.pauli.group_observables now returns Prods if the observable list contains new arithmetic ops.
  • Update pauli_to_binary to rely on the Pauli rep. All operations that can be grouped should now always have a valid Pauli rep, so we don't need to worry about other cases, as pauli_to_binary is only a utility function for grouping.
  • Update are_pauli_words_qwc to correctly handle ops with Pauli reps. This change however means that any new arithmetic ops that have pauli_rep=None will still not work with this function. If we eventually start doing more simplification eagerly, this can be addressed.
  • split_non_commuting now creates Prods instead of Tensors for creating observables for measurements that use wires. Also made a change so that if a measurement without any wires is made, the observable that is created uses tape.wires.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@mudit2812
Copy link
Contributor Author

[sc-53504]

Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Thanks @mudit2812
Great to see progress on grouping with arithmetic ops!

I gave it a first pass and there are honestly a lot of things that I dont quite understand yet. Could you help me by providing some context to the changes where I ask questions and generally add a description to the PR what the goal is as well as developer comments. Since there are no added tests it is hard to understand the context of the PR.

Re caching and Sum not having a coeffs attribute, I think this is something we wanted to add for feature parity anyway. If this attribute existed, would this make this PR any easier?

pennylane/operation.py Outdated Show resolved Hide resolved
pennylane/operation.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/sum.py Outdated Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 22, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (4e2e344) 99.68% compared to head (3fce75c) 99.67%.
Report is 1 commits behind head on master.

Files Patch % Lines
pennylane/operation.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5070      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.02%     
==========================================
  Files         392      392              
  Lines       35844    35565     -279     
==========================================
- Hits        35732    35448     -284     
- Misses        112      117       +5     

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

pennylane/operation.py Outdated Show resolved Hide resolved
Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

looks awesome ⚛️ just a few little questions

pennylane/ops/qubit/hamiltonian.py Outdated Show resolved Hide resolved
pennylane/pauli/grouping/group_observables.py Show resolved Hide resolved
pennylane/transforms/split_non_commuting.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Qottmann Qottmann left a comment

Choose a reason for hiding this comment

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

Great job @mudit2812 🥳

Left some comments on the pauli checks. Looks overall good though 👍

pennylane/operation.py Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
pennylane/pauli/utils.py Show resolved Hide resolved
pennylane/pauli/utils.py Outdated Show resolved Hide resolved
mudit2812 and others added 3 commits February 5, 2024 18:08
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
@mudit2812 mudit2812 requested review from Qottmann and a team February 5, 2024 13:03
@Alex-Preciado Alex-Preciado removed the request for review from a team February 6, 2024 17:09
@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c1a813d) 99.68% compared to head (6a9c799) 99.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5070      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.02%     
==========================================
  Files         394      394              
  Lines       36160    35875     -285     
==========================================
- Hits        36047    35759     -288     
- Misses        113      116       +3     

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

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

looks awesome. just left one suggestion to make sure we clean up in case of errors

pennylane/pauli/grouping/group_observables.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Qottmann Qottmann 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 now 👍

@mudit2812 mudit2812 enabled auto-merge (squash) February 7, 2024 15:54
@albi3ro albi3ro disabled auto-merge February 7, 2024 17:29
@albi3ro albi3ro merged commit 22d8fca into master Feb 7, 2024
33 checks passed
@albi3ro albi3ro deleted the pauli-op-arithmetic branch February 7, 2024 17:29
@mudit2812 mudit2812 mentioned this pull request Feb 7, 2024
mlxd pushed a commit that referenced this pull request Feb 7, 2024
An edge case I missed in #5070 broke Lightning tests. This is to fix
that.
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.

None yet

6 participants