PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.36k stars 604 forks source link

Legacy operator arithmetic deprecation #6287

Closed mudit2812 closed 1 month ago

mudit2812 commented 1 month ago

Context: Legacy op math is being deprecated.

Description of the Change:

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 using simplify and PauliSentence.hamiltonian with legacy op math, so there will be up to 4 warnings at once when using these.

Additionally, qml.qchem.tapering.symmetry_generators and qml.qchem.tapering.clifford use PauliSentence.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 to True once before merging to confirm that legacy op math tests do not fail.

[sc-71940] [sc-66727] [sc-66724]

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.39%. Comparing base (d9e833a) to head (455c9a9). Report is 4 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #6287 +/- ## ========================================== - Coverage 99.70% 99.39% -0.32% ========================================== Files 445 445 Lines 42260 42271 +11 ========================================== - Hits 42137 42016 -121 - Misses 123 255 +132 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

PietropaoloFrisoni commented 1 month ago

Should we also replace use_legacy_opmath with legacy_opmath_only in this test?

mudit2812 commented 1 month ago

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.

PietropaoloFrisoni commented 1 month ago

To fix the error in:

tests/optimize/test_momentum_qng.py::TestOptimize::test_single_qubit_vqe_using_expval_h_multiple_input_params (added today) and tests/optimize/test_qng.py::TestOptimize::test_single_qubit_vqe_using_expval_h_multiple_input_params

I guess we can safely remove the recwarn parameter. I am not sure about the other failures

mudit2812 commented 1 month ago

It looks like I just need to add back some of the duplicate tests we had for legacy opmath tests to pass. For some reason, the legacy opmath enable only happens after all the parameters for parametrized tests are created, so we're ending up in a situation where we create LinearCombinations and Prods when Hamiltonians and Tensors are expected.

mudit2812 commented 1 month ago

Confirmation that all tests pass with --disable-opmath=True here.

Alex-Preciado commented 1 month ago

Proceeding to force merge after discussing with @mudit2812 !! Context: Tests that used to run in CI for legacy opmath have been changed to only run in the Plugin Test Matrix