Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pending deprecate algo eigen_solvers #8651

Merged
merged 9 commits into from
Sep 29, 2022
36 changes: 33 additions & 3 deletions qiskit/algorithms/eigen_solvers/eigen_solver.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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`.
Expand All @@ -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,
Expand All @@ -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
Expand Down
36 changes: 33 additions & 3 deletions qiskit/algorithms/eigen_solvers/vqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 <https://arxiv.org/abs/1805.08138>`__ is a quantum algorithm that uses a
variational technique to find
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
deprecations:
- |
Module :mod:`qiskit.algorithms.eigen_solvers` is pending deprecation and
is superseded by :mod:`qiskit.algorithms.eigensolvers`