quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.51k stars 372 forks source link

get_sparse_operator fails on non-simplified QubitOperators #880

Open jagunther opened 4 months ago

jagunther commented 4 months ago

Hi,

I noticed that get_sparse_operator() assumes that Paulistrings in a QubitOperator are simplified, i.e. there should be no Paulis within a Paulistring acting on the same tensor-factor. Normally when initialising a QubitOperator the simplification is done automatically, however, the Symmetry-conserving Bravyi-Kitaev transform does not do this. Below is a small example:

from openfermion import (
    get_sparse_operator,
    FermionOperator,
    symmetry_conserving_bravyi_kitaev,
)

fermion_op = FermionOperator("0^ 1^")
qubit_op = symmetry_conserving_bravyi_kitaev(fermion_op, 4, 2)
print(qubit_op)

# throws error
get_sparse_operator(qubit_op)