From fb1001531915dc7c0a9cdd266e12010db0953594 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Wed, 31 Aug 2022 13:19:43 -0400 Subject: [PATCH] Pending deprecate algo eigen_solvers --- .../algorithms/eigen_solvers/eigen_solver.py | 36 +++++++++++++++++-- .../eigen_solvers/numpy_eigen_solver.py | 23 +++++++++--- qiskit/algorithms/eigen_solvers/vqd.py | 36 +++++++++++++++++-- ...recate-eigen-solvers-2a4068cc9f83fba2.yaml | 5 +++ 4 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/pending-deprecate-eigen-solvers-2a4068cc9f83fba2.yaml diff --git a/qiskit/algorithms/eigen_solvers/eigen_solver.py b/qiskit/algorithms/eigen_solvers/eigen_solver.py index 28ca3e9d1f8b..a013b5c827cc 100644 --- a/qiskit/algorithms/eigen_solvers/eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/eigen_solver.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -18,18 +18,34 @@ import numpy as np from qiskit.opflow import OperatorBase +from qiskit.utils.deprecation import deprecate_function from ..algorithm_result import AlgorithmResult from ..list_or_dict import ListOrDict class Eigensolver(ABC): - """The Eigensolver Interface. + """Pending deprecation: Eigensolver Interface. + + The Eigensolver interface has been superseded by the + :class:`qiskit.algorithms.eigensolvers.Eigensolver` interface. + This interface will be deprecated in a future release and subsequently + removed after that. Algorithms that can compute eigenvalues for an operator may implement this interface to allow different algorithms to be used interchangeably. """ + @deprecate_function( + "The Eigensolver interface has been superseded by the " + "qiskit.algorithms.eigensolvers.Eigensolver interface. " + "This interface will be deprecated in a future release and subsequently " + "removed after that.", + category=PendingDeprecationWarning, + ) + def __init__(self) -> None: + pass + @abstractmethod def compute_eigenvalues( self, operator: OperatorBase, aux_operators: Optional[ListOrDict[OperatorBase]] = None @@ -63,8 +79,22 @@ def supports_aux_operators(cls) -> bool: class EigensolverResult(AlgorithmResult): - """Eigensolver Result.""" + """Pending deprecation: Eigensolver Result. + + The EigensolverResult class has been superseded by the + :class:`qiskit.algorithms.eigensolvers.EigensolverResult` class. + This class will be deprecated in a future release and subsequently + removed after that. + + """ + @deprecate_function( + "The EigensolverResult class has been superseded by the " + "qiskit.algorithms.eigensolvers.EigensolverResult class. " + "This class will be deprecated in a future release and subsequently " + "removed after that.", + category=PendingDeprecationWarning, + ) def __init__(self) -> None: super().__init__() self._eigenvalues = None diff --git a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py index 63f4a63123e9..77078dd6fbbc 100755 --- a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2021. +# (C) Copyright IBM 2018, 2022. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -14,12 +14,13 @@ import logging from typing import Callable, List, Optional, Tuple, Union - +import warnings import numpy as np from scipy import sparse as scisparse from qiskit.opflow import I, ListOp, OperatorBase, StateFn from qiskit.utils.validation import validate_min +from qiskit.utils.deprecation import deprecate_function from ..exceptions import AlgorithmError from .eigen_solver import Eigensolver, EigensolverResult from ..list_or_dict import ListOrDict @@ -32,7 +33,12 @@ class NumPyEigensolver(Eigensolver): r""" - The NumPy Eigensolver algorithm. + Pending deprecation: NumPy Eigensolver algorithm. + + The NumPyEigensolver class has been superseded by the + :class:`qiskit.algorithms.eigensolvers.NumPyEigensolver` class. + This class will be deprecated in a future release and subsequently + removed after that. NumPy Eigensolver computes up to the first :math:`k` eigenvalues of a complex-valued square matrix of dimension :math:`n \times n`, with :math:`k \leq n`. @@ -43,6 +49,13 @@ class NumPyEigensolver(Eigensolver): operator size, mostly in terms of number of qubits it represents, gets larger. """ + @deprecate_function( + "The NumPyEigensolver class has been superseded by the " + "qiskit.algorithms.eigensolvers.NumPyEigensolver class. " + "This class will be deprecated in a future release and subsequently " + "removed after that.", + category=PendingDeprecationWarning, + ) def __init__( self, k: int = 1, @@ -61,7 +74,9 @@ def __init__( fewer elements and can even be empty. """ validate_min("k", k, 1) - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._in_k = k self._k = k diff --git a/qiskit/algorithms/eigen_solvers/vqd.py b/qiskit/algorithms/eigen_solvers/vqd.py index 29d237820273..d14ac038e1fe 100644 --- a/qiskit/algorithms/eigen_solvers/vqd.py +++ b/qiskit/algorithms/eigen_solvers/vqd.py @@ -17,6 +17,7 @@ from typing import Optional, List, Callable, Union, Dict, Tuple import logging +import warnings from time import time import numpy as np @@ -37,6 +38,7 @@ from qiskit.opflow.gradients import GradientBase from qiskit.utils.validation import validate_min from qiskit.utils.backend_utils import is_aer_provider +from qiskit.utils.deprecation import deprecate_function from qiskit.utils import QuantumInstance from ..list_or_dict import ListOrDict from ..optimizers import Optimizer, SLSQP, Minimizer @@ -50,7 +52,12 @@ class VQD(VariationalAlgorithm, Eigensolver): - r"""The Variational Quantum Deflation algorithm. + r"""Pending deprecation: Variational Quantum Deflation algorithm. + + The VQD class has been superseded by the + :class:`qiskit.algorithms.eigensolvers.VQD` class. + This class will be deprecated in a future release and subsequently + removed after that. `VQD `__ is a quantum algorithm that uses a variational technique to find @@ -89,6 +96,13 @@ class VQD(VariationalAlgorithm, Eigensolver): """ + @deprecate_function( + "The VQD class has been superseded by the " + "qiskit.algorithms.eigensolvers.VQD class. " + "This class will be deprecated in a future release and subsequently " + "removed after that.", + category=PendingDeprecationWarning, + ) def __init__( self, ansatz: Optional[QuantumCircuit] = None, @@ -149,7 +163,9 @@ def __init__( """ validate_min("max_evals_grouped", max_evals_grouped, 1) - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._max_evals_grouped = max_evals_grouped self._circuit_sampler = None # type: Optional[CircuitSampler] @@ -741,8 +757,22 @@ def _get_eigenstate(self, optimal_parameters) -> Union[List[float], Dict[str, in class VQDResult(VariationalResult, EigensolverResult): - """VQD Result.""" + """Pending deprecation: VQD Result. + + The VQDResult class has been superseded by the + :class:`qiskit.algorithms.eigensolvers.VQDResult` class. + This class will be deprecated in a future release and subsequently + removed after that. + + """ + @deprecate_function( + "The VQDResult class has been superseded by the " + "qiskit.algorithms.eigensolvers.VQDResult class. " + "This class will be deprecated in a future release and subsequently " + "removed after that.", + category=PendingDeprecationWarning, + ) def __init__(self) -> None: super().__init__() self._cost_function_evals = None diff --git a/releasenotes/notes/pending-deprecate-eigen-solvers-2a4068cc9f83fba2.yaml b/releasenotes/notes/pending-deprecate-eigen-solvers-2a4068cc9f83fba2.yaml new file mode 100644 index 000000000000..044605fe345e --- /dev/null +++ b/releasenotes/notes/pending-deprecate-eigen-solvers-2a4068cc9f83fba2.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - | + Module :mod:`qiskit.algorithms.eigen_solvers` is pending deprecation and + is superseded by :mod:`qiskit.algorithms.eigensolvers`