-
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
Implement arithmetic on SparseObservable
#13298
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 11576212029Details
💛 - Coveralls |
The simple arithmetic operators of addition, subtraction, multiplication, division and tensor product are in line with other `quantum_info` objects, including coercion from other objects (though better behaved on failed coercions, in many cases). Where appopriate, in-place operations will re-use the existing allocations. The tensor product cannot really be done in place, so it doesn't define a special `__rxor__` operator, but it inherits the standard Python behaviour of this being derived from `__xor__`. There are further mathematical operations to add around composition and evolution, and to apply a `TranspileLayout` to the observable. All of these, in the `quantum_info` style either directly deal with a layout, or take a `qargs` argument that is effectively a sublayout for the right-hand side of the operation. These will be added in a follow-up.
bbc5137
to
68b5c56
Compare
Now rebased and ready for review. |
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 looks good to me I just have some short questions below 🙂
This puts the `self is other` check into the `__add__` and `__sub__` methods so that the behaviour of `x + x` is consistent with `x += x`, with regards to the addition being done as a scalar multiplication instead of concatentation. Both forms are mathematically correct, but this makes sure they're aligned.
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!
Summary
The simple arithmetic operators of addition, subtraction, multiplication, division and tensor product are in line with other
quantum_info
objects, including coercion from other objects (though better behaved on failed coercions, in many cases).Where appopriate, in-place operations will re-use the existing allocations. The tensor product cannot really be done in place, so it doesn't define a special
__rxor__
operator, but it inherits the standard Python behaviour of this being derived from__xor__
.There are further mathematical operations to add around composition and evolution, and to apply a
TranspileLayout
to the observable. All of these, in thequantum_info
style either directly deal with a layout, or take aqargs
argument that is effectively a sublayout for the right-hand side of the operation. These will be added in a follow-up.Details and comments
Built on top of #12671, so depends on it.