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

SProd.terms() flattens out nested terms #5885

Merged
merged 9 commits into from
Jul 12, 2024
Merged

SProd.terms() flattens out nested terms #5885

merged 9 commits into from
Jul 12, 2024

Conversation

astralcai
Copy link
Contributor

@astralcai astralcai commented Jun 20, 2024

Context:
The .terms() method of Sum, LinearCombination, Hamiltonian, Prod all flatten out any nested terms, but SProd does not. For examples:

>>> coeffs, ops = (2 * (qml.X(0) + qml.Y(0))).terms()
>>> len(ops)
1

Description of the Change:
Make it so that SProd flattens out the terms.

Benefits:
More consistent behaviour

[sc-66627]

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (dbb26f2) to head (732d867).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5885      +/-   ##
==========================================
- Coverage   99.67%   99.67%   -0.01%     
==========================================
  Files         425      425              
  Lines       40926    40632     -294     
==========================================
- Hits        40793    40498     -295     
- Misses        133      134       +1     

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

@astralcai astralcai marked this pull request as ready for review July 10, 2024 15:38
@lillian542 lillian542 self-requested a review July 11, 2024 19:14
Copy link
Contributor

@lillian542 lillian542 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 🎉

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 👍

just one minor question

pennylane/ops/op_math/sprod.py Show resolved Hide resolved
pennylane/ops/op_math/sprod.py 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.

Thanks @astralcai !

@astralcai astralcai enabled auto-merge (squash) July 12, 2024 14:59
@astralcai astralcai merged commit 2963166 into master Jul 12, 2024
40 checks passed
@astralcai astralcai deleted the sprod-terms branch July 12, 2024 15:41
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.

3 participants