From f43fd45bab49918c1228d592247d38e157ca1362 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 20 Oct 2020 14:35:29 -0400 Subject: [PATCH] Use numpy eigh instead of scipy eigh with driver kwarg In #5251 we updated the LAPACK driver used for the scipy hermitian optimized eigensovler to use 'evd' instead of the default 'ev'. However, this implicitly added a scipy minimum version of 1.5.0 because the driver kwarg was only added to the eigh() function in that release. [1] In that PR we didn't bump the minimum scipy version to reflect this. However, scipy 1.5.0 has a version conflict with our downstream users, mainly qiskit-aqua/qiskit-chemistry which use PySCF as an optional dependency. PySCF has a capped version of scipy in their requirements [2] which makes bumping our minimum scipy version intractable currently. To avoid this issue, this commit switches to use numpy's eigh() function [3] instead of scipy's. The numpy function uses the evd driver and was what we originally used in #5251 but was switched to use scipy's eigh() with the driver kwarg to avoid bumping the minimum version of numpy. However, between bumping the minimum numpy version and bumping the minimum scipy version, the numpy version is less problematic. [1] https://docs.scipy.org/doc/scipy/reference/release.1.5.0.html#scipy-linalg-improvements [2] https://github.com/pyscf/pyscf/blob/v1.7.5/setup.py#L490 [3] https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigh.html --- qiskit/quantum_info/synthesis/two_qubit_decompose.py | 2 +- releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml | 9 +++++++++ requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml diff --git a/qiskit/quantum_info/synthesis/two_qubit_decompose.py b/qiskit/quantum_info/synthesis/two_qubit_decompose.py index 2e76dac68732..a01ac931ee02 100644 --- a/qiskit/quantum_info/synthesis/two_qubit_decompose.py +++ b/qiskit/quantum_info/synthesis/two_qubit_decompose.py @@ -169,7 +169,7 @@ def __init__(self, unitary_matrix, eps=1e-15): for i in range(100): # FIXME: this randomized algorithm is horrendous state = np.random.default_rng(i) M2real = state.normal()*M2.real + state.normal()*M2.imag - _, P = la.eigh(M2real, driver='evd') + _, P = np.linalg.eigh(M2real, driver='evd') D = P.T.dot(M2).dot(P).diagonal() if np.allclose(P.dot(np.diag(D)).dot(P.T), M2, rtol=1.0e-13, atol=1.0e-13): break diff --git a/releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml b/releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml new file mode 100644 index 000000000000..7de56fb80f38 --- /dev/null +++ b/releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml @@ -0,0 +1,9 @@ +--- +upgrade: + - | + The minimum required version of numpy has been increased from 1.17.0 to + 1.18.0. This was done to leverage the ``numpy.linalg.eigh()`` function [#]_ + for use in :class:`qiskit.quantum_info.TwoQubitBasisDecomposer` which was + needed to provide consistent results. + + .. [#] https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigh.html diff --git a/requirements.txt b/requirements.txt index 619103ffb37b..f9bb72d4da71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ contextvars>=2.4;python_version<'3.7' jsonschema>=2.6 networkx>=2.2 retworkx>=0.5.0 -numpy>=1.17 +numpy>=1.18 ply>=3.10 psutil>=5 scipy>=1.4 diff --git a/setup.py b/setup.py index eba7481cc09f..2d519ea094bb 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ "jsonschema>=2.6", "networkx>=2.2", "retworkx>=0.5.0", - "numpy>=1.17", + "numpy>=1.18", "ply>=3.10", "psutil>=5", "scipy>=1.4",