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

Make CommutingEvolution a SymbolicOp #5682

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

dwierichs
Copy link
Contributor

@dwierichs dwierichs commented May 13, 2024

Context:
CommutingEvolution has the structure of a ScalarSymbolicOp, so we make it one.

Description of the Change:
Change base class of CommutingEvolution and adapt other attributes of the class to this change.

In addition, a dispatch branch of qml.equal for all ScalarSymbolicOps is introduced.

Benefits:
Code quality

Possible Drawbacks:

Related GitHub Issues:

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.


.. math:: O = O_1 O_2 \dots O_n.
def matrix(self, wire_order=None) -> TensorLike:
"""Raise a MatrixUndefinedError for now to force decomposition on DefaultQubit."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially instead we can treat this like GroverOperator and QFT and manually say "decompose CommutingEvolution".

Comment on lines +162 to +163
def _matrix(scalar, mat):
return qml.math.expm(-1j * scalar * mat)
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially we could make _matrix not an abstractmethod? Then we woudn't need to define this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, do we want to do the following, @albi3ro ?

  • Keep this _matrix method, removing the need for a custom matrix method.
  • Thus, remove matrix
  • Remove has_matrix, because ScalarSymbolicOp already sets it to self.base.has_matrix, and _matrix is all that is needed to go from the Hamitlonian matrix to the CommutingEvolution matrix.
  • Add a logic for apply_operation for CommutingEvolution like for GroverOperator etc

@dwierichs dwierichs requested a review from albi3ro May 16, 2024 06:43
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (5b81a8a) to head (5b6da65).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5682      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         415      415              
  Lines       38886    38602     -284     
==========================================
- Hits        38762    38477     -285     
- Misses        124      125       +1     

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

@dwierichs dwierichs added the review-ready 👌 PRs which are ready for review by someone from the core team. label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants