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

Bosonic operators #1085

Merged
merged 49 commits into from
May 23, 2023
Merged

Bosonic operators #1085

merged 49 commits into from
May 23, 2023

Conversation

ftroisi
Copy link
Collaborator

@ftroisi ftroisi commented Mar 3, 2023

Summary

Details and comments

@CLAassistant
Copy link

CLAassistant commented Mar 3, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

A few initial observations. We will also need to add a release note 👍

qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
@mrossinek mrossinek added this to the 0.7.0 milestone Mar 10, 2023
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Overall I think this PR is already in pretty good shape. I left quite a few comments, some of which
are nitpicks, others are a bit more broad. In general, I'd like to add these notes:

  • we need to add a release note (see here)
  • you need to run the code formatter: make black (from the repo root)
  • you need to add bosonicop as a spell exception to .pylintdict
  • the docstrings are mostly not formatted properly. This can be quite tricky when just getting
    started so I suggest this in our offline-scheduled meeting. I left some pointers in my
    comments below already though.

qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
ordered_op = self.normal_order()

data = defaultdict(complex) # type: dict[str, _TCoeff]
# TODO: use parallel_map to make this more efficient (?)
Copy link
Member

Choose a reason for hiding this comment

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

FYI for another reviewer: this TODO is copied over from FermionicOp and out-of-scope for this PR

test/second_q/mappers/test_bosonic_linear_mapper.py Outdated Show resolved Hide resolved
test/second_q/mappers/test_bosonic_linear_mapper.py Outdated Show resolved Hide resolved
@mrossinek mrossinek requested a review from ElePT May 3, 2023 14:25
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Here are a few more comments in preparation for our meeting (no need to address them before).

qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/operators/bosonic_op.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Thanks Francesco! Just a few more steps. We were looking for a specific way of defining properties and property setters, see specific comments in the code.

qiskit_nature/second_q/mappers/bosonic_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_mapper.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Yay! The CI passes!! I took a look at the rendered docs and I think there are two last things that can be improved (getting picky here):
Screenshot 2023-05-22 at 14 54 52

  1. The definitions of the sigma +/- operators should be in separate lines (idk why Sphinx is not getting the line break)
  2. I think that the two references would look better if they were in separate lines too.

I added two suggestions that will hopefully fix this :)

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

One last last thing

qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
ftroisi and others added 3 commits May 22, 2023 15:04
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Sorry, there was a missing empty line in my code block suggestion from before and it didn't render properly. New suggestion should fix that (also added an empty line between imports and code in the example below because I think it looks a bit better)

Screenshot 2023-05-22 at 16 04 17

qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
ftroisi and others added 2 commits May 22, 2023 16:16
Co-authored-by: Elena Peña Tapia <[email protected]>
ElePT
ElePT previously approved these changes May 22, 2023
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Max will probably give a last round of review, but in terms of docs, I have nothing to say other than good job. Thanks a lot!

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Okay, some last final nitpicky comments.
Once these changes are applied I'm confident we can merge this PR 👍

qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
qiskit_nature/second_q/mappers/bosonic_linear_mapper.py Outdated Show resolved Hide resolved
@woodsp-ibm woodsp-ibm mentioned this pull request May 22, 2023
mrossinek
mrossinek previously approved these changes May 23, 2023
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

Assuming I did not mess up my prior suggestions, CI should pass on this...


Thanks a lot, Francesco, for your hard work on this great contribution to Qiskit Nature! 🎉
Thank you, Elena, for your support in reviewing and helping Francesco out on the home stretch of this PR.

@mergify mergify bot merged commit f67eb91 into qiskit-community:main May 23, 2023
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
* Created bosonic operator file. Some notes on the code

* modified ordering functions using commutator instead of anti-commutator

* Created simplify method

* Created test class for bosonic operator

* Moved normal_order and index_order before simplify. Fixed the expected results

* Fixed tests. Hermicity test is still missing

* Improved algorithm for simplify. Now calls normal order as first operation. Fixed tests

* fixed is_hermitian method

* Addressed PR comments

* Pipelines fixes

* Created bosonic_linear_mapper class

* Added some unit tests for bosonic linear mapper. Pipelines fixes

* Removed trailing whitspace

* Fixed test case +_0 -_0 with truncation 2

* Implemented test cases +_0 -_1 and -_1 +_0. Some CI fixes

* Added test case +_0 +_0

* Some CI fixes

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>

* Added test for commutator relation

* Added terms to pylintdict

* Updated some mapper tests

* Addressed some PR comments. Fixed final tests

* Addressed PR comments for docstrings

* Further doc fixes

* Further CI fixes

* Added release note

* Spell fix in release note

* Added methods from_terms and _permute_terms

* Addressed PR comments

* ran make black

* Added r in front of docstring

* Added reference for bosonic op truncation

* Addressed PR comments

* Added mapper example in bosonicLinearMapper docString

* Updated error message

* Renamed truncation property. Defined its setter

* Apply suggestions for max_occupation setter

Co-authored-by: Elena Peña Tapia <[email protected]>

* ran make black

* Removed unused import

* Doc fixes

Co-authored-by: Elena Peña Tapia <[email protected]>

* Doc fix

Co-authored-by: Elena Peña Tapia <[email protected]>

* ran make black

* Doc fix

Co-authored-by: Elena Peña Tapia <[email protected]>

* ran make black

* Apply suggestions from code review

Co-authored-by: Max Rossmannek <[email protected]>

* Minor doc fix

* Apply suggestions from code review

* Update qiskit_nature/second_q/mappers/bosonic_mapper.py

---------

Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a BosonicOperator
6 participants