Skip to content
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

Methods to commute terms in Fermi objects #6196

Merged
merged 87 commits into from
Sep 18, 2024

Conversation

willjmax
Copy link
Contributor

@willjmax willjmax commented Aug 30, 2024

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).

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
Copy link
Contributor

@austingmhuang austingmhuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @willjmax. I left some initial comments but it looks good so far.

pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
tests/fermi/test_fermionic.py Outdated Show resolved Hide resolved
@willjmax
Copy link
Contributor Author

willjmax commented Sep 4, 2024

[sc-72571]

Copy link
Contributor

@austingmhuang austingmhuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Some small comments but should be good to go soon.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
willjmax and others added 2 commits September 6, 2024 11:04
Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com>
Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com>
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @willjmax, looks good, please address my final minor comments on the doc.

pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
willjmax and others added 3 commits September 16, 2024 13:04
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
willjmax and others added 3 commits September 18, 2024 10:34
pennylane/fermi/fermionic.py Show resolved Hide resolved
@willjmax willjmax enabled auto-merge (squash) September 18, 2024 18:30
@willjmax willjmax merged commit 09ae791 into PennyLaneAI:master Sep 18, 2024
37 checks passed
mudit2812 pushed a commit that referenced this pull request Sep 23, 2024
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)`.

---------

Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com>
Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants