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

More fermionic dunders #4209

Merged
merged 78 commits into from
Jun 15, 2023
Merged

More fermionic dunders #4209

merged 78 commits into from
Jun 15, 2023

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Jun 2, 2023

Description of the Change:

  • add __rmul__ to FermiWord and FermiSentence to handle things like 2 * FermiWord (int, float or complex or numpy array multiplied by FermiWord or FermiSentence)
  • expand __mul__ method to allow multiplication between FermiWord, FermiSentence, float, int, complex or numpy array
  • add __add__ and __radd__ method to to both FermiWord and FermiSentence to allow addition between FermiWord, FermiSentence and constants
  • add __sub__ and __rsub__ method to both FermiWord and FermiSentence to allow subtraction between FermiWord, FermiSentence and constants

@lillian542 lillian542 requested a review from soranjh June 12, 2023 19:44
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 Show resolved Hide resolved
pennylane/fermi/fermionic.py Show resolved Hide resolved
pennylane/fermi/fermionic.py Outdated Show resolved Hide resolved
pennylane/fermi/fermionic.py Show resolved Hide resolved
tests/fermi/test_fermionic.py Show resolved Hide resolved
tests/fermi/test_fermionic.py Show resolved Hide resolved
tests/fermi/test_fermionic.py Show resolved Hide resolved
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.

Looks great, thanks @lillian542. My main comment is about using arrays with length != 1. I think that should not be allowed.

pennylane/fermi/fermionic.py Show resolved Hide resolved
pennylane/fermi/fermionic.py 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 Show resolved Hide resolved
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Initial review comments

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

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

Looks good to me, thanks @lillian542!

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Just a small comment about rounding in tests. Conditionally approving based on that 👍🏼

tests/fermi/test_fermionic.py Outdated Show resolved Hide resolved
tests/fermi/test_fermionic.py Outdated Show resolved Hide resolved
tests/fermi/test_fermionic.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

LGTM 💯

@lillian542 lillian542 enabled auto-merge (squash) June 15, 2023 21:47
@lillian542 lillian542 merged commit 5824a8e into master Jun 15, 2023
@lillian542 lillian542 deleted the more_fermionic_dunders branch June 15, 2023 23:07
frederikwilde pushed a commit that referenced this pull request Jul 5, 2023
* create fermiword class

* create fermisentence class

* [skip ci] modify order

* [skip ci] remove unused import

* [skip ci] add deepcopy method

* [skip ci] replace list with generator

* [skip ci] add tests

* [skip ci] add tests

* [skip ci] add tests

* add tests

* [skip ci] run black

* [skip ci] copy fermiword

* [skip ci] rebase and fix conflict

* [skip ci] run black

* [skip ci] copy fermiword

* [skip ci] add tests

* add test to tests_passing_pylint

* add sum mult test

* [skip ci] add tests

* [skip ci] add pow tests

* add tests

* fix pylint

* add error tests

* fix pylint

* add TODO

* modify docstrings

* update changelog

* update changelog

* modify docstrings

* fix codecov

* add code review comments

* add test for indices

* fix codefactor

* multiply FermiWord and FermiSentence

* add tests for fw * fs

* add and test multiplying fermiword with  integer or float

* allow number times fermi sentence

* update tests

* Allow subtracting one FermiSentence from another

* Allow substraction

* clean up formatting and tests

* Add multiplication by complex

* Add more tests and reorganize

* update change log

* add test

* black formatting

* Add constants to FermiWord and FermiSentence

* add tests

* radd and rsub methods plus tests

* missing lines for codecov

* start adding support for tensors

* numpy and pennylane numpy tensors plus tests for __add__ and __sub__

* add tests for multiplying by tensor

* fix formatting issues post merge

* add comment regarding overriding numpy dunders

* Apply suggestions from code review

Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>

* check len of array before adding to FeriSentence

* Raise error if array with len>2 is passed to arithmetic dunders

* Apply suggestions from code review

Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>

* Update doc/releases/changelog-dev.md

* round to 10 digits

---------

Co-authored-by: soranjh <soranjh@yahoo.com>
Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
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.

3 participants