Skip to content

Commit dfe189a

Browse files
committed
Match data types when creating array of zeros
In function `get_tensors_from_integrals`, the call to `numpy.zeros` didn't supply data type information. This resulted in the type defaulting to a float type, which then led to warnings about losing precision in the multiplications later in the method. The solution is to match the types of the values in the call to `zeros` to the types of other arrays.
1 parent 4e2d4fd commit dfe189a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/openfermion/ops/representations/interaction_operator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ def get_tensors_from_integrals(one_body_integrals, two_body_integrals):
169169
n_qubits = 2 * one_body_integrals.shape[0]
170170

171171
# Initialize Hamiltonian coefficients.
172-
one_body_coefficients = numpy.zeros((n_qubits, n_qubits))
173-
two_body_coefficients = numpy.zeros((n_qubits, n_qubits, n_qubits, n_qubits))
172+
one_dtype = one_body_integrals.dtype
173+
two_dtype = two_body_integrals.dtype
174+
one_body_coefficients = numpy.zeros((n_qubits, n_qubits), dtype=one_dtype)
175+
two_body_coefficients = numpy.zeros((n_qubits, n_qubits, n_qubits, n_qubits), dtype=two_dtype)
174176
# Loop through integrals.
175177
for p in range(n_qubits // 2):
176178
for q in range(n_qubits // 2):

0 commit comments

Comments
 (0)