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

Adapting generators to opmath enabled/disabled #5415

Merged
merged 37 commits into from
Mar 21, 2024

Conversation

PietropaoloFrisoni
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni commented Mar 19, 2024

Context: After enabling the new operator arithmetic by default, we want the generators in the source code to return a LinearCombination instance or a Hamiltonian instance wherever possible.

Description of the Change: The generators touched in this PR are modified so that they return qml.Hamiltonian instead of Sum, Prod, or Sprod instances. When opmath is enabled, qml.Hamiltonian points to pennylane.ops.op_math.linear_combination.LinearCombination, and when it is disabled, it points to pennylane.ops.qubit.hamiltonian.Hamiltonian. This ensures that the appropriate instance is used consistently.
Note that the generators unchanged in this PR are modified (wherever possible) in #5410 , #5411 , #5412 (including the changelog entry).

Benefits: A more coherent choice depending on whether opmath is enabled or disabled.

Possible Drawbacks: None that I can think of, except that old opmath would be deprecated in the future. Therefore, some precautions that have been taken here (to ensure that tests associated with generators work even with opmath disabled) might become useless.

Related GitHub Issues: None.

[sc-57982]

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.

@PietropaoloFrisoni PietropaoloFrisoni changed the title empty commit Adapting generators to opmath enabled/disabled Mar 19, 2024
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.47%. Comparing base (29f1d90) to head (853d0d1).

Additional details and impacted files
@@            Coverage Diff             @@
##           ham-tests    #5415   +/-   ##
==========================================
  Coverage      99.47%   99.47%           
==========================================
  Files            400      400           
  Lines          37146    37143    -3     
==========================================
- Hits           36950    36949    -1     
+ Misses           196      194    -2     

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

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review March 19, 2024 21:16
@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as draft March 20, 2024 20:25
@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review March 20, 2024 21:04
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.

I think we can have best of both worlds with the suggestion. Else looks great 👍 Happy to approve with that fixed :)

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.

I think one pair of legacy and new tests can be combined now, but no blocking comments. Looks good to me, glad this is 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.

nice 👌

@PietropaoloFrisoni PietropaoloFrisoni merged commit c290f28 into ham-tests Mar 21, 2024
31 of 32 checks passed
@PietropaoloFrisoni PietropaoloFrisoni deleted the Adapting-generators-to-opmath branch March 21, 2024 15:07
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.

5 participants