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

Move pauli word logic from qml.grouping.utils.is_commuting to qml.is_commuting #3033

Merged
merged 14 commits into from
Sep 9, 2022

Conversation

timmysilv
Copy link
Contributor

Context:
There are currently two different implementations of is_commuting(): one at the top-level for a variety of operators, and another in pennylane/grouping/utils.py specifically for Pauli words. These should be in the same place to avoid drift, give a simpler user interface and ease future development, so I'm putting them in the same place (qml.is_commuting)

Description of the Change:

  • Move the Pauli word is_commuting logic to qml.is_commuting() (thereby removing qml.grouping.utils.is_commuting()), and try to check this before other checks
  • If it deems one or both operators to not be Pauli words, check if either are Tensors
    • If they are, raise an exception
    • Else, carry on
  • Explicitly remove support for Prod and Sum classes (as well as Tensors) since we do not yet have an implementation to support them

Benefits:

  • Single method for users to check if two operators commute. Distinguishing logic for Pauli words vs. other operators is hidden away.
  • Explicitly removes support for (non-Pauli word) Tensors, as well as composite operators

Possible Drawbacks:

  • qml.is_commuting() is becoming large and messy (as hinted by our pylint disabled features 😄 ). Hopefully this gets some love in the future. The code is still organized and legible, just a warning.

Related GitHub Issues:
Fixes #3007

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

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.

@codecov
Copy link

codecov bot commented Sep 7, 2022

Codecov Report

Merging #3033 (02616ac) into master (29acf0d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3033   +/-   ##
=======================================
  Coverage   99.66%   99.66%           
=======================================
  Files         271      271           
  Lines       23161    23164    +3     
=======================================
+ Hits        23084    23087    +3     
  Misses         77       77           
Impacted Files Coverage Δ
pennylane/grouping/__init__.py 100.00% <ø> (ø)
pennylane/grouping/utils.py 100.00% <ø> (ø)
pennylane/ops/functions/is_commuting.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

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

Nice work @timmysilv!

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.

Great to have this simplification!

@timmysilv timmysilv merged commit 7033aec into master Sep 9, 2022
@timmysilv timmysilv deleted the single-is-commuting branch September 9, 2022 19:44
@rmoyard rmoyard added this to the v0.26.0 milestone Sep 9, 2022
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.

[BUG] qml.is_commuting breaks with Tensor operators.
4 participants