qiskit-nature icon indicating copy to clipboard operation
qiskit-nature copied to clipboard

Add a `SparseLabelOp` class

Open mrossinek opened this issue 3 years ago • 1 comments

What should we add?

In #665 I am proposing the addition of a PolynomialTensor class, which is a storage container for coefficients in a matrix representation. Our SecondQuantizedOp (sub)classes on the other hand, generally store data of the form:

{
  "op_idx1 op_idx2": 0.0,
  "op_idx1 op_idx3": 1.0,
}

In other words, they are essentially label-coefficient dictionaries, which can be thought of as the result of np.ravel(matrix) matches with it's indices.

More specifically, the FermionicOp and VibrationalOp used to be almost copies of one another, but the former has been improved significantly in terms of capabilities and performance, whereas the latter has not gotten all these ugprades.

Thus, this issue proposes the introduction of a base class, which should handle all the operations which are case-agnostic (i.e. not specific to fermionic, vibrational or spin settings). Similar to the PolynomialTensor, this likely means that the class will look somewhat like the following:

from qiskit.opflow.mixins import StarAlgebraMixin
from qiskit.quantum_info.operators.mixins import TolerancesMixin

class SparseLabelOp(StarAlgebraMixin, TolerancesMixin):

    def __init__(self, data: Dict[str, complex]):
        self._data = data

    # TODO: implement mathematical operations supported by StarAlgebraMixin

    @abstractmethod
    def commutativity(self) -> bool:
        ...

    @abstractmethod
    def normal_ordered(self) -> SparseLabelOp:
        ...

    @abstractmethod
    def simplify(self) -> SparseLabelOp:
        ...

    @abstractclassmethod
    def zero(cls, ...) -> SparseLabelOp:
        # TBD: arguments to this method
        ...

    @abstractclassmethod
    def one(cls, ...) -> SparseLabelOp:
        # TBD: arguments to this method
        ...

Some operations may have to fall back on self.commutativity to be correctly implemented.

:warning: This issue will be fleshed out with more details later.

mrossinek avatar May 25 '22 18:05 mrossinek

I would like to work on this please! 😄

javabster avatar Jun 14 '22 13:06 javabster