Skip to content

Commit

Permalink
Use numpy eigh instead of scipy eigh with driver kwarg
Browse files Browse the repository at this point in the history
In Qiskit#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 Qiskit#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
  • Loading branch information
mtreinish committed Oct 20, 2020
1 parent 651b460 commit f43fd45
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion qiskit/quantum_info/synthesis/two_qubit_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/numpy-bump-b14a4a0ec1c0636f.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f43fd45

Please sign in to comment.