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

Methods to commute terms in Fermi objects #6196

Closed willjmax closed 2 months ago

willjmax commented 2 months ago

This PR introduces the method shift_operator to the FermiWord class. Given an initial position and a final position, the method will shift the operator in the initial position to the final position, and apply the fermion anti-commutator relations. shift_operator returns a FermiSentence object since new terms and coefficients may be introduced by the anti-commutator relations.

The following code

fw = FermiWord({(0, 0): '+', (1, 1): '-', (2, 2): '+'})
fw.shift_operator(2, 0)

produces FermiSentence({FermiWord({(0, 2): '+', (1, 0): '+', (2, 1): '-'}): 1}) which is the FermiSentence obtained by shifting the operator in the 2nd position until it reaches the 0th position. That is a+(0) a(1) a+(2) becomes a+(2) a+(0) a(1).

codecov[bot] commented 2 months ago

Codecov Report

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

Project coverage is 99.58%. Comparing base (d7db6b4) to head (5f83275). Report is 2 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #6196 +/- ## ======================================= Coverage 99.58% 99.58% ======================================= Files 444 444 Lines 42323 42367 +44 ======================================= + Hits 42149 42193 +44 Misses 174 174 ```

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

willjmax commented 2 months ago

[sc-72571]

willjmax commented 2 months ago

Last set of comments, will be happy to approve after these.

Thanks. I committed your changes.