Skip to content

Commit

Permalink
Fix NumPy(Minimum)Eigensolver for sparse matrices (#9575)
Browse files Browse the repository at this point in the history
* add reno

* fix sparse calculation
  • Loading branch information
Cryoris authored Feb 13, 2023
1 parent 41e0c3a commit 1fb00e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions qiskit/algorithms/eigensolvers/numpy_eigensolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 1fb00e6

Please sign in to comment.