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

Add SparseLabelOp base class #731

Merged
merged 41 commits into from
Sep 8, 2022

Conversation

javabster
Copy link
Contributor

Summary

closes #669

Details and comments

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.

I finally had time for some more feedback on the open discussion points.

Besides that, please also relocate (now that #746 has been merged) this class to qiskit_nature/second_q/operators/sparse_label_op.py (and the matching test location).

@javabster javabster marked this pull request as ready for review August 9, 2022 21:44
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.

Some feedback for now. I think in general this looks good.

It would be good, if you could also add a release note 👍

I think, we can leave the following aspects for an extension later during the refactoring process:

  • more detailed documentation
  • addition of Parameter support

@coveralls
Copy link

coveralls commented Aug 16, 2022

Pull Request Test Coverage Report for Build 3016572442

  • 53 of 57 (92.98%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 85.315%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_nature/second_q/operators/sparse_label_op.py 52 56 92.86%
Totals Coverage Status
Change from base Build 3008133675: 0.02%
Covered Lines: 16744
Relevant Lines: 19626

💛 - Coveralls

@mrossinek mrossinek changed the title Add SparseLabelOp abstract class Add SparseLabelOp base class Aug 17, 2022
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.

Some minor comments but other than this, this LGTM 👍

@mrossinek mrossinek requested a review from woodsp-ibm August 31, 2022 11:19
@mrossinek
Copy link
Member

Following my suggestion over in #756, I will make a similar comment here:

I had another discussion with @woodsp-ibm and we said that it might be beneficial to directly implement SparseLabelOp as a subclass of Mapping. That would give full flexibility when accessing the internal _data object.
The way that you could achieve this, is by something similar to the following:

from collections.abc import Mapping
from typing import Iterator

class SparseLabelOp(..., Mapping):
    ...

    def __getitem__(self, __k: str) -> Number:
        return self._data.__getitem__(__k)

    def __len__(self) -> int:
        return self._data.__len__()

    def __iter__(self) -> Iterator[str]:
        return self._data.__iter__()

This also shows an even simpler implementation of __iter__ which is probably better than what we have right now. It will change it such that the default iteration will only return the keys (and not items) but this is inline with what Mapping does 👍

This will directly enable users to use len(...), .keys(), .values(), .items() and even use op["key"] to access specific entries 👍

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.

Other than these suggestions, this LGTM 👍

Note: if you go to the Files tab of the PR, you can batch all of these suggestions into a single commit, which will trigger fewer CI runs 👍

mrossinek
mrossinek previously approved these changes Sep 7, 2022
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.

LGTM 👍
Thanks a lot, Abby!

I'll await another official review from @woodsp-ibm before merging 👍



class SparseLabelOp(LinearMixin, AdjointMixin, TolerancesMixin, ABC, Mapping):
"""The Sparse Label Operator base class."""
Copy link
Member

Choose a reason for hiding this comment

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

Could this be fleshed out a little to explain what this is a bit more. Maybe an example usage to or something to give someone a better idea of whats this all about.

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.

Thanks, Abby! 🙂

@mrossinek mrossinek merged commit a4ea55a into qiskit-community:main Sep 8, 2022
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
* Started foundation for SparseLabelOp abstract class

* Made changes based on PR comments

* Update some docstrings

* Refactpr sparselabelop and add test

* Implemented changes requested from review

* Fix mypy error

* Remove Number bc it doesn't play nice with mypy

* Added reno

* Try adding Number check

* Update qiskit_nature/operators/second_quantization/sparse_label_op.py

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

* Made changes based on review comments

* Make review changes and fix mypy issues

* Fixed mypy errors based on Steve's suggestions

* Moved files to new  subdir

* Make class abstract

* ✨ lint ✨

* ✨ lint again ✨

* Removed qargs check

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update releasenotes/notes/sparselabelop-class-57ffd57121dadfe5.yaml

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

* Updated based on review comments

* ✨ lint ✨

* Adjusted copy and iter

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* Update qiskit_nature/second_q/operators/sparse_label_op.py

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

* ✨ lint! ✨

* ✨ lint again ✨

* Updated mapping type and added tests

* Added sparselabelop to pylintdict

* Apply suggestions from code review

* Adjusted register length

* Removed reno

Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: Manoel Marques <[email protected]>
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.

Add a SparseLabelOp class
5 participants