-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added argsort and sort method to SparsePauliOp #8016
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
@ikkoham |
Pull Request Test Coverage Report for Build 2654643569
💛 - Coveralls |
@kUmezawa Is this part of QAMP? If so can you please mention the QAMP project in the description? I will also ad |
Yes, this is part of QAMP. I have updated this pr description. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Originally, the simplify method sorted as out of spec, but since 0.20.0 it no longer sorts, so this method is useful.
Basically, It looks good to me, but release note is required for new feature. Could you please add the release note?
@ikkoham |
There is an attempt to parametrize coefficients of |
As for release note, please check out this documentation. |
I haven't considered it yet.
Thank you. |
@t-imamichi |
Thanks. I'll have to think about whether we handle the error or simply just get a TypeError from NumPy when introducing Parameter for SparsePauliOp. I'll keep this in my mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also from my side the code LGTM! But what is the motivation for adding these methods? That wasn't quite clear from the PR description 🙂
I'm quite confused by the weight
argument -- I thought it was related to the coefficients and only when looking at PauliList
I realized that you define the weight as the number of non-identity Paulis. In the context of the PauliList
I see how that makes sense but since we have coefficients in the SparsePauliOp
I think this naming might be a bit unclear. Could we maybe use a more precise argument?
releasenotes/notes/0.20/add-sparsepauliop-methods-00a7e6cc7055e1d0.yaml
Outdated
Show resolved
Hide resolved
Thank you for your review.
I'm sorry that the motive is difficult to understand. As Mr. Hamamura wrote, the simplify method cannot be sorted, so the motivation was to prepare an alternative method. I will specify it in the release notes.
OK. I will consider it. |
|
||
Args: | ||
weight (bool): optionally sort by weight if True (Default: False). | ||
This argument is the same as weight of argsort method of PauliList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This argument is the same as weight of argsort method of PauliList | |
This argument is the same as weight of argsort method of :class:`.PauliList`. |
|
||
Args: | ||
weight (bool): optionally sort by weight if True (Default: False). | ||
This argument is the same as weight of sort method of PauliList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on the documentation of argsort
🙂
releasenotes/notes/0.21/add-sparsepauliop-methods-00a7e6cc7055e1d0.yaml
Outdated
Show resolved
Hide resolved
@Cryoris @ikkoham
I understand that the meaning of your advice is to point out what happens when you sort SparcePauliOp with an empty list. Is that wrong?
I will change the comment sort to argsort. |
I mean that right now it looks like sorting an empty SparsePauliOp raises an error. But I think it should not raise an error and just return the empty SparsePauliOp 🙂 |
@Cryoris
I get an error when generating a SparcePauliOp class with an empty list. |
Oh fair enough! Then of course sorting doesn't work. Thanks for trying! 🙂 |
@Cryoris >Oh fair enough! Then of course sorting doesn't work. Thanks for trying! OK. Thank you. >See comment on the documentation of argsort Added description of arguments. |
right. empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for the updates @kUmezawa!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for your contribution!
Summary
This is an update as part of QAMP's activities.
Relating issue: qiskit-advocate/qamp-spring-22#20
PauliList has argsort() method and sort() method.
We need these features in SparsePauliOp.
Details and comments
argsort() method returns the composition of permutations in the order of sorting by coefficient and sorting by Pauli.
sort() method returns a new sorted SparsePauliOp class. After sorting the coefficients using numpy's argsort, sort by Pauli.