-
Notifications
You must be signed in to change notification settings - Fork 37
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
feature: support LinearCombination as observable #246
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #246 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 1207 1215 +8
Branches 290 295 +5
=========================================
+ Hits 1207 1215 +8 ☔ View full report in Codecov by Sentry. |
try: | ||
from pennylane.ops import LinearCombination | ||
except (AttributeError, ImportError): | ||
|
||
class LinearCombination: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than doing conditional imports, I'd say it's fine to wait until 0.36 is released and import normally
When I proposed the solution I did not expect the issue of having to do conditional imports. In that case I would say:
would suffice. Depending on whether new opmath is enabled, |
@_translate_observable.register(qml.ops.Hamiltonian) | ||
@_translate_observable.register(qml.Hamiltonian) | ||
def _(H: Union[qml.ops.Hamiltonian, qml.Hamiltonian]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
@_translate_observable.register(qml.ops.Hamiltonian) | |
@_translate_observable.register(qml.Hamiltonian) | |
def _(H: Union[qml.ops.Hamiltonian, qml.Hamiltonian]): | |
@_translate_observable.register | |
def _(H: Union[qml.ops.Hamiltonian, qml.Hamiltonian]): |
Otherwise,
@_translate_observable.register(qml.ops.Hamiltonian)
@_translate_observable.register(qml.Hamiltonian)
def _(H):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only since Python 3.11
Issue #, if available:
#245
Description of changes:
LinearCombination
as an observable that will be the default in the new version of PennyLaneqml.opsSProd
andqml.ops.Sum
in the observableTesting done:
tox
andtox -e integ-tests
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.