-
Notifications
You must be signed in to change notification settings - Fork 591
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
Legacy operator arithmetic deprecation #6287
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6287 +/- ##
==========================================
- Coverage 99.70% 99.39% -0.32%
==========================================
Files 444 444
Lines 42236 42244 +8
==========================================
- Hits 42113 41989 -124
- Misses 123 255 +132 ☔ View full report in Codecov by Sentry. |
doc/releases/changelog-dev.md
Outdated
* Legacy operator arithmetic has been deprecated. This includes `qml.ops.Hamiltonian`, `qml.operation.enable_new_opmath`, | ||
`qml.operation.disable_new_opmath`, and `qml.operation.convert_to_legacy_H`. | ||
[(#6287)](https://github.com/PennyLaneAI/pennylane/pull/6287) | ||
|
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.
I am not suggesting doing that in this PR, but are we going to remove the Tensor
class without deprecating it first? If so, then I guess it can cause quite a few issues
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.
I believe the logic behind not deprecating Tensor
is that it is a private class. We've always exposed qml.Hamiltonian
in a very public way, but Tensor
has always been hidden inside the operation
module, and the recommended way to create a Tensor
has been using the @
operator. That being said, I see your point, and I'd feel wrong merging this PR before getting more input from product about it. cc @DSGuala
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.
After more discussions, Tensor
has been deprecated.
Should we also replace |
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.
There are a lot more than can be simplified around our testing with legacy opmath. Although I'm ok to approve if we're under pressure of time to merge this by today, since we're removing legacy opmath completely in a few months anyway?
tests/devices/default_qubit/test_default_qubit_preprocessing.py
Outdated
Show resolved
Hide resolved
|
||
|
||
@pytest.mark.usefixtures("legacy_opmath_only") | ||
@pytest.mark.usefixtures("use_legacy_and_new_opmath") |
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.
Actually the use_legacy_and_new_opmath
fixture can be removed because everything is going to be tested with both legacy and new opmath unless marked new_opmath_only
or legacy_opmath_only
. The use_new_opmath
fixture can also be removed because it doesn't really do anything.
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.
I still see merit in keeping the use_legacy_and_new_opmath
fixture for things that we want to keep testing in regular CI with legacy op math. I agree we can remove the use_new_opmath
fixture and should replace tests that use it with new_opmath_only
where appropriate, or not use any fixture. That way, their behaviour in regular CI won't change, but we won't run unnecessary tests in legacy op math CI.
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.
I didn't get through that much of it but here are a few comment for now :)
:func:`~pennylane.operation.convert_to_opmath` and :func:`~pennylane.operation.convert_to_H` to convert legacy operators | ||
into those using the new operator arithmetic. |
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.
Should we really suggest this? Since I guess these are also deprecated, so we just want them to enable new_opmath
and stop explicitly making Tensors and Hamiltonians.
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.
I did not deprecate these functions because they're the only way users can easily convert legacy ops into new ops without having to do something like
new_op = qml.Hamiltonian(old_op.coeffs, old_op.ops)
Args: | ||
op (Operator): The operator instance to convert. | ||
|
||
Returns: | ||
Operator: The operator as a :class:`~pennylane.Hamiltonian` instance | ||
""" | ||
with disable_new_opmath_cm(): |
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.
we don't want a deprecation warning in this one?
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.
Because a deprecation warning will be raised when a legacy Hamiltonian
is created.
Looks like running some tests only when legacy op math is active has caused some humps with codecov. Not sure if it should be addressed or not. |
Context:
Legacy op math is being deprecated.
Description of the Change:
qml.ops.Hamiltonian
is deprecated.qml.operation.Tensor
is deprecated.qml.operation.disable_new_opmath
andqml.operation.enable_new_opmath
(as well as the context managers) are deprecated.qml.operation.convert_to_legacy_H
is deprecated.PauliWord.hamiltonian
andPauliSentence.hamiltonian
is deprecated.qml.pauli.simplify
is deprecated.Removed
use_legacy_opmath
anduse_new_opmath
fixtures. Instead, we use eitherlegacy_opmath_only
,new_opmath_only
, or no fixture, as appropriate for the tests.Added warning suppression for all the above deprecation warnings to
pytest.ini
. Additionally, I also added the same warning suppressions toconftest.py
for the case when--disable-opmath=True
, since the warning filters inpytest.ini
only suppress warnings that come from inside tests, not ones that come from outside the tests, such as when deprecated code is used for creating parameters for a test.Benefits:
Possible Drawbacks:
In some instances, there will be a LOT of deprecation warnings at the same time. The most impactful example of this if if using
qml.qchem.molecular_hamiltonian
,qml.qchem.qubit_observable
. These usingsimplify
andPauliSentence.hamiltonian
with legacy op math, so there will be up to 4 warnings at once when using these.Additionally,
qml.qchem.tapering.symmetry_generators
andqml.qchem.tapering.clifford
usePauliSentence.hamiltonian
when legacy op math is enabled, so there will be up to 3 warnings at once when using these.Related GitHub Issues:
I will run the test suite with
disable_new_opmath
set toTrue
once before merging to confirm that legacy op math tests do not fail.[sc-71940] [sc-66727] [sc-66724]