-
Notifications
You must be signed in to change notification settings - Fork 210
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
Fix issue1258 #1259
Fix issue1258 #1259
Conversation
|
Pull Request Test Coverage Report for Build 6315372064
💛 - Coveralls |
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.
Interesting approach, thanks for fixing this!
Before merging, please also add a release note which explains the bug and states that it has been fixed. Please focus on this being an end-user centric document, so try to keep it from being too technical.
Sorry, I misinterpreted the CONTRIBUTING.md, assuming that fixes like this don't count as 'end user facing' and therefore don't need release notes. I added a short release note now, I hope this is appropriate in length and detail. |
Maybe this might logically be better to convert to scalar https://numpy.org/doc/stable/reference/generated/numpy.ndarray.item.html ? While sum works you did have to comment to explain what its really doing. |
@woodsp-ibm |
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.
I prefer the .item()
method for converting to scalar. I actually did not know about this, so thanks a lot, Steve, for pointing this out! 👍
releasenotes/notes/fix-from-polynomial-tensor-constant-9df7f63be4a4c819.yaml
Outdated
Show resolved
Hide resolved
…be4a4c819.yaml Co-authored-by: Max Rossmannek <[email protected]>
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 for your contribution! 👍
* fixes issue 1258 * style fixes after make black * Add release note for fix-issue1258 * replace sum() with item() to get scalar * Update releasenotes/notes/fix-from-polynomial-tensor-constant-9df7f63be4a4c819.yaml Co-authored-by: Max Rossmannek <[email protected]> * Update fix-from-polynomial-tensor-constant-9df7f63be4a4c819.yaml --------- Co-authored-by: Max Rossmannek <[email protected]>
Summary
Fixes issue #1258
For BosonicOp, FermionicOp, SpinOp, VibrationalOp, changed the line that takes care of the empty string coefficient (constant part of operator) in
from_polynomial_tensor
constructor to assign a scalar number rather than 0d array.Details and comments
PolynomialTensor stores all coefficients as tensors, including the empty string contribution, which is consistent. The SparseLabelOps have a scalar number coefficient per label string. When constructed from PolynomialTensor, coefficients are assigned from the scalar elements of the corresponding tensor. However, the constant term (empty string) is dealt with separately, assigning the 0d tensor:
To convert this also to scalar, this is replaced by: