From 3703dc3176e8742ceb79e59909b7214c7ae80bf2 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Thu, 16 Feb 2023 10:59:38 +0100 Subject: [PATCH] Fix sparse matrix conversion for `SciPyEvolver` (#9598) * Fix missing indent * add reno --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit e8bfddaeb05653d7ad22dbe1d0c1a09a09799998) --- .../algorithms/time_evolvers/classical_methods/evolve.py | 8 ++++---- .../fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/qiskit/algorithms/time_evolvers/classical_methods/evolve.py b/qiskit/algorithms/time_evolvers/classical_methods/evolve.py index e0500266001f..c170a29e4404 100644 --- a/qiskit/algorithms/time_evolvers/classical_methods/evolve.py +++ b/qiskit/algorithms/time_evolvers/classical_methods/evolve.py @@ -109,10 +109,10 @@ def _operator_to_matrix(operator: BaseOperator | PauliSumOp): "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 return op_matrix diff --git a/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml b/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml index 2440e729c00e..2013d1eaa050 100644 --- a/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml +++ b/releasenotes/notes/fix-numpy-eigensolver-sparse-0e255d7b13b5e43b.yaml @@ -1,6 +1,9 @@ --- fixes: - | - Fixed a bug in :class:`~.minimum_eigensolvers.NumPyMinimumEigensolver` and - :class:`~.eigensolvers.NumPyEigensolver` where operators that support conversion + Fixed a bug in the NumPy-based eigensolvers + (:class:`~.minimum_eigensolvers.NumPyMinimumEigensolver` / + :class:`~.eigensolvers.NumPyEigensolver`) + and in the SciPy-based time evolvers (:class:`.SciPyRealEvolver` / + :class:`.SciPyImaginaryEvolver`), where operators that support conversion to sparse matrices, such as :class:`.SparsePauliOp`, were converted to dense matrices anyways.