Skip to content

Commit 66b2c6e

Browse files
authored
Resolves failing cirq pre-release (#794)
Apparently prior releases of openfermion were attempting to use scipy.linalg.expm to exponentiate sparse matrices. Until recently the scipy API seem to resolve the issue of using scipy.linalg.expm instead of scipy.sparse.linalg.expm. This issue was not surfaced until the 1.0.0dev release so some combination of numpy/scipy pinning or depinning has revealed this bug in openfermion. This commit fixes the issue by converting scipy.linalg.expm to scipy.sparse.linalg.expm where appropriate.
1 parent 5ef58b5 commit 66b2c6e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/openfermion/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# limitations under the License.
1212

1313
"""Define version number here and read it from setup.py automatically"""
14-
__version__ = "1.6.0dev0"
14+
__version__ = "1.5.1"

src/openfermion/circuits/gates/four_qubit_gates_test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ def test_double_excitation_matches_fermionic_evolution(exponent):
263263
op += openfermion.hermitian_conjugated(op)
264264
matrix_op = openfermion.get_sparse_operator(op)
265265

266-
time_evol_op = scipy.linalg.expm(-1j * matrix_op * exponent * numpy.pi)
266+
time_evol_op = scipy.sparse.linalg.expm(-1j * matrix_op * exponent *
267+
numpy.pi)
267268
time_evol_op = time_evol_op.todense()
268269

269270
cirq.testing.assert_allclose_up_to_global_phase(cirq.unitary(gate),

src/openfermion/testing/circuit_validation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import List
1515

1616
import numpy
17-
from scipy import linalg
17+
import scipy
1818
import cirq
1919
import openfermion
2020
from openfermion.config import EQ_TOLERANCE
@@ -46,10 +46,10 @@ def validate_trotterized_evolution(circuit: cirq.Circuit,
4646
hs_dim = 2**n_qubits
4747
qubit_op = ops[0]
4848
op_matrix = openfermion.get_sparse_operator(qubit_op, n_qubits=n_qubits)
49-
target_unitary = linalg.expm(1j * op_matrix)
49+
target_unitary = scipy.sparse.linalg.expm(1j * op_matrix)
5050
for qubit_op in ops[1:]:
5151
op_matrix = openfermion.get_sparse_operator(qubit_op, n_qubits=n_qubits)
52-
op_unitary = linalg.expm(1j * op_matrix)
52+
op_unitary = scipy.sparse.linalg.expm(1j * op_matrix)
5353
target_unitary = op_unitary.dot(target_unitary)
5454

5555
actual_unitary = circuit.unitary(qubit_order=qubits)

0 commit comments

Comments
 (0)