Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement arithmetic on
SparseObservable
(#13298)
* Implement arithmetic on `SparseObservable` 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. * Match `x + x` behaviour to `x += x` 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.
- Loading branch information