Skip to content

Error when translating openfermion FermionOperators #142

@NRoshani

Description

@NRoshani

when running the following code

import fqe
from openfermion.ops import FermionOperator


ket = fqe.Wavefunction(param=[[4, 0, 4]])
coeff = ket.get_coeff((4,0))
coeff[1][1] = 1
ket.set_wfn(strategy="from_data", raw_data={(4, 0): coeff})
ket.normalize()

ops = FermionOperator('6^ 4^ 4 6',0.5)
ops += FermionOperator('6^ 5^ 5 6',0.5)
ops += FermionOperator('7^ 4^ 4 7',0.5)
ops += FermionOperator('7^ 5^ 5 7',0.5)

ops_fqe=fqe.get_hamiltonian_from_openfermion(ops)
result = fqe.expectationValue(wfn=ket, ops=ops_fqe)

on gets following error

 line 289, in apply_diagonal_coulomb
    _apply_diagonal_coulomb(data, self._core.string_alpha_all(),
  File "src/fqe/lib/_fqe_data.pyx", line 557, in fqe.lib.fqe_data._apply_diagonal_coulomb

However, when changing the operator to

import fqe
from openfermion.ops import FermionOperator


ket = fqe.Wavefunction(param=[[4, 0, 4]])
coeff = ket.get_coeff((4,0))
coeff[1][1] = 1
ket.set_wfn(strategy="from_data", raw_data={(4, 0): coeff})
ket.normalize()

ops = FermionOperator('2^ 0^ 0 2',0.5)
ops += FermionOperator('2^ 1^ 1 2',0.5)
ops += FermionOperator('3^ 0^ 0 3',0.5)
ops += FermionOperator('3^ 1^ 1 3',0.5)

ops_fqe=fqe.get_hamiltonian_from_openfermion(ops)
result = fqe.expectationValue(wfn=ket, ops=ops_fqe)

it suddenly works. My guess something in fqe.get_hamiltonian_from_openfermion causes the issue but I could be wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions