Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad behavior when working with sympy #885

Open
Earendil-WBG opened this issue Jun 14, 2024 · 0 comments
Open

Bad behavior when working with sympy #885

Earendil-WBG opened this issue Jun 14, 2024 · 0 comments
Labels

Comments

@Earendil-WBG
Copy link

Earendil-WBG commented Jun 14, 2024

I found that when using sympy expression as coefficients in FermionOperator, the expression would be transformed automatically into float numbers. For example:

from openfermion.ops import FermionOperator
from sympy import Rational

a = FermionOperator('0^ 0', Rational(1, 2))
a

This gives the output:

1/2 [0^ 0]

But when doing:

a = FermionOperator('0^ 0', Rational(1, 2))
b = FermionOperator('1^ 1', Rational(1, 2))
a + b

Then it outputs:

1/2 [0^ 0] +
0.500000000000000 [1^ 1]

Which is not what I would expect. This is probably due to that, in the SymbolicOperator class' addition method (line 435-436):

            for term in addend.terms:
                self.terms[term] = self.terms.get(term, 0.0) + addend.terms[term]

When term isn't find in self, its coefficient is set to 0.0, which might cause some type conversion for sympy expression. Since it originates in SymbolicOperator , it would probably happen in other operator classes.

Version: 1.6.1

@fdmalone fdmalone added the bug label Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants