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.17k stars 568 forks source link

fix sum hash issue #5851

Closed albi3ro closed 2 weeks ago

albi3ro commented 2 weeks ago

Context:

Sum.hash uses frozenset to calculate the hash in an order independent way. The problem is that frozenset ignores the fact that some operations may occur multiple times in the sum. This leads to an incorrect hash.

The bad hash then propagated to incorrect eigvals and diagonalizing_gates

Description of the Change:

Uses collections.Counter to count how many times the operations occur.

Benefits:

Correct answers.

Possible Drawbacks:

speed.

Related GitHub Issues:

Fixes #5849 [sc-65903]

codecov[bot] commented 2 weeks ago

Codecov Report

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

Project coverage is 99.67%. Comparing base (9b3060f) to head (4d01d52).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5851 +/- ## ========================================== - Coverage 99.67% 99.67% -0.01% ========================================== Files 421 421 Lines 40189 39896 -293 ========================================== - Hits 40060 39766 -294 - Misses 129 130 +1 ```

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