Skip to content

Commit 55d3172

Browse files
authored
Add numbers.Number to COEFFICIENT_TYPES in SymbolicOperator (#1171)
numpy.int64 and other numeric types are currently not accepted as coefficients (assuming this is not on purpose). Instead of adding them manually, numbers. Number evaluates to true for all of them. In principle int, float, complex could be removed (left them for clarity) This prevents errors like ```python def __init__(self, term=None, coefficient=1.0): if not isinstance(coefficient, COEFFICIENT_TYPES): > raise ValueError('Coefficient must be a numeric type. Got {}'.format(type(coefficient))) E ValueError: Coefficient must be a numeric type. Got <class 'numpy.int64'> ```
1 parent 5b92653 commit 55d3172

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/openfermion/ops/operators/symbolic_operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
import itertools
1717
import re
1818
import warnings
19+
import numbers
1920

2021
import sympy
2122

2223
from openfermion.config import EQ_TOLERANCE
2324

24-
COEFFICIENT_TYPES = (int, float, complex, sympy.Expr)
25+
COEFFICIENT_TYPES = (int, float, complex, sympy.Expr, numbers.Number)
2526

2627

2728
class SymbolicOperator(metaclass=abc.ABCMeta):

0 commit comments

Comments
 (0)