qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Implement arithmetic on `SparseObservable`

Open jakelishman opened this issue 1 year ago • 2 comments

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 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.

Details and comments

Built on top of #12671, so depends on it.

jakelishman avatar Oct 08 '24 17:10 jakelishman

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

qiskit-bot avatar Oct 08 '24 17:10 qiskit-bot

Pull Request Test Coverage Report for Build 11576212029

Details

  • 375 of 410 (91.46%) changed or added relevant lines in 1 file are covered.
  • 16 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.008%) to 88.693%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/sparse_observable.rs 375 410 91.46%
<!-- Total: 375 410
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.98%
crates/qasm2/src/parse.rs 12 97.15%
<!-- Total: 16
Totals Coverage Status
Change from base Build 11572090796: 0.008%
Covered Lines: 75349
Relevant Lines: 84955

💛 - Coveralls

coveralls avatar Oct 08 '24 18:10 coveralls

Now rebased and ready for review.

jakelishman avatar Oct 24 '24 15:10 jakelishman