#15883·qiskit

Add `QubitSparsePauli.equal_indices` checking if another qubit sparse pauli is non-trival on the same qubits

Author: DanPuzzuoliCreated Mar 26, 2026Updated Sep 29, 2026
Labelstype: feature requestmod: quantum info

What should we add?

This is pretty trivial, the function should have the same behaviour as the python code:

def equal_indices(self, other: QubitSparsePauli) -> bool:
    return np.array_equal(self.indices, other.indices)

Despite the above being pretty trivial, it is surprisingly slow, which I think is due to the python property QubitSparsePauli.indices needing to create a numpy array from the rust data. The goal with this method is to do the comparison in rust and then only need to pass a bool to python.

Further, it may be useful to have a method like this on QubitSparsePauliList, which could either do a pairwise comparison, i.e. equivalent to x.equal_indices(y) for x, y in zip(self, other), or possibly return a list of index pairs for which x.equal_indices(y) is true for x, y in product(self, other).