From e31c2e8cf9cc46c13cd06db82daad6b03022bea3 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Mon, 13 Feb 2023 17:08:20 +0100 Subject: [PATCH 1/2] add reno --- .../fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml diff --git a/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml b/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml new file mode 100644 index 000000000000..2440e729c00e --- /dev/null +++ b/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed a bug in :class:`~.minimum_eigensolvers.NumPyMinimumEigensolver` and + :class:`~.eigensolvers.NumPyEigensolver` where operators that support conversion + to sparse matrices, such as :class:`.SparsePauliOp`, were converted to dense matrices anyways. From fcfc5811a34570e9e4ab343794d4548f7f4e5868 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Mon, 13 Feb 2023 17:08:30 +0100 Subject: [PATCH 2/2] fix sparse calculation --- qiskit/algorithms/eigensolvers/numpy_eigensolver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit/algorithms/eigensolvers/numpy_eigensolver.py b/qiskit/algorithms/eigensolvers/numpy_eigensolver.py index ae4a45d88cea..41af1708ae07 100755 --- a/qiskit/algorithms/eigensolvers/numpy_eigensolver.py +++ b/qiskit/algorithms/eigensolvers/numpy_eigensolver.py @@ -120,10 +120,10 @@ def _solve(self, operator: BaseOperator | PauliSumOp) -> tuple[np.ndarray, np.nd "Trying dense computation", type(operator), ) - try: - op_matrix = operator.to_matrix() - except AttributeError as ex: - raise AlgorithmError(f"Unsupported operator type `{type(operator)}`.") from ex + try: + op_matrix = operator.to_matrix() + except AttributeError as ex: + raise AlgorithmError(f"Unsupported operator type `{type(operator)}`.") from ex if isinstance(op_matrix, scisparse.csr_matrix): # If matrix is diagonal, the elements on the diagonal are the eigenvalues. Solve by sorting.