Skip to content

Commit

Permalink
Pending deprecate algorithms (Qiskit#8703)
Browse files Browse the repository at this point in the history
* Pending deprecate algorithms

* Update releasenotes/notes/pending-deprecate-min-eigen-solvers-fa4341e1014e4df0.yaml

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 27, 2022
1 parent 2ae490e commit 76da497
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 21 deletions.
36 changes: 33 additions & 3 deletions qiskit/algorithms/minimum_eigen_solvers/minimum_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 MinimumEigensolver(ABC):
"""The Minimum Eigensolver Interface.
"""Pending deprecation: Minimum Eigensolver Interface.
The Minimum Eigensolver interface has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver` interface.
This interface will be deprecated in a future release and subsequently
removed after that.
Algorithms that can compute a minimum eigenvalue for an operator
may implement this interface to allow different algorithms to be
used interchangeably.
"""

@deprecate_function(
"The Minimum Eigensolver interface has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver 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_minimum_eigenvalue(
self, operator: OperatorBase, aux_operators: Optional[ListOrDict[OperatorBase]] = None
Expand Down Expand Up @@ -67,8 +83,22 @@ def supports_aux_operators(cls) -> bool:


class MinimumEigensolverResult(AlgorithmResult):
"""Minimum Eigensolver Result."""
"""Pending deprecation: Minimum Eigensolver Result.
The MinimumEigensolverResult class has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult` class.
This class will be deprecated in a future release and subsequently
removed after that.
"""

@deprecate_function(
"The MinimumEigensolverResult class has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult class. "
"This class will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
def __init__(self) -> None:
super().__init__()
self._eigenvalue = None
Expand Down
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 @@ -14,9 +14,11 @@

from typing import List, Optional, Union, Callable
import logging
import warnings
import numpy as np

from qiskit.opflow import OperatorBase
from qiskit.utils.deprecation import deprecate_function
from ..eigen_solvers.numpy_eigen_solver import NumPyEigensolver
from .minimum_eigen_solver import MinimumEigensolver, MinimumEigensolverResult
from ..list_or_dict import ListOrDict
Expand All @@ -26,9 +28,22 @@

class NumPyMinimumEigensolver(MinimumEigensolver):
"""
The Numpy Minimum Eigensolver algorithm.
Pending deprecation: Numpy Minimum Eigensolver algorithm.
The NumPyMinimumEigensolver class has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver` class.
This class will be deprecated in a future release and subsequently
removed after that.
"""

@deprecate_function(
"The NumPyMinimumEigensolver class has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver class. "
"This class will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
def __init__(
self,
filter_criterion: Callable[
Expand All @@ -44,6 +59,9 @@ def __init__(
whether to consider this value or not. If there is no
feasible element, the result can even be empty.
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
self._ces = NumPyEigensolver(filter_criterion=filter_criterion)
self._ret = MinimumEigensolverResult()

Expand Down
40 changes: 28 additions & 12 deletions qiskit/algorithms/minimum_eigen_solvers/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
""" The Quantum Approximate Optimization Algorithm. """

from typing import List, Callable, Optional, Union
import warnings
import numpy as np

from qiskit.algorithms.optimizers import Minimizer, Optimizer
Expand All @@ -22,13 +23,19 @@
from qiskit.providers import Backend
from qiskit.utils.quantum_instance import QuantumInstance
from qiskit.utils.validation import validate_min
from qiskit.utils.deprecation import deprecate_function
from qiskit.circuit.library.n_local.qaoa_ansatz import QAOAAnsatz
from qiskit.algorithms.minimum_eigen_solvers.vqe import VQE


class QAOA(VQE):
"""
The Quantum Approximate Optimization Algorithm.
Pending deprecation: Quantum Approximate Optimization Algorithm.
The QAOA class has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.QAOA` class.
This class will be deprecated in a future release and subsequently
removed after that.
`QAOA <https://arxiv.org/abs/1411.4028>`__ is a well-known algorithm for finding approximate
solutions to combinatorial-optimization problems.
Expand All @@ -52,6 +59,13 @@ class QAOA(VQE):
the evolution to a feasible subspace of the full Hilbert space.
"""

@deprecate_function(
"The QAOA class has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.QAOA class. "
"This class will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
def __init__(
self,
optimizer: Optional[Union[Optimizer, Minimizer]] = None,
Expand Down Expand Up @@ -114,17 +128,19 @@ def __init__(
self._initial_state = initial_state
self._cost_operator = None

super().__init__(
ansatz=None,
optimizer=optimizer,
initial_point=initial_point,
gradient=gradient,
expectation=expectation,
include_custom=include_custom,
max_evals_grouped=max_evals_grouped,
callback=callback,
quantum_instance=quantum_instance,
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__(
ansatz=None,
optimizer=optimizer,
initial_point=initial_point,
gradient=gradient,
expectation=expectation,
include_custom=include_custom,
max_evals_grouped=max_evals_grouped,
callback=callback,
quantum_instance=quantum_instance,
)

def _check_operator_ansatz(self, operator: OperatorBase) -> OperatorBase:
# Recreates a circuit based on operator parameter.
Expand Down
40 changes: 36 additions & 4 deletions qiskit/algorithms/minimum_eigen_solvers/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import logging
import warnings
from time import time
from typing import Callable, Dict, List, Optional, Tuple, Union

Expand All @@ -40,6 +41,7 @@
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.utils.backend_utils import is_aer_provider
from qiskit.utils.validation import validate_min
from qiskit.utils.deprecation import deprecate_function

from ..aux_ops_evaluator import eval_observables
from ..exceptions import AlgorithmError
Expand All @@ -52,7 +54,12 @@


class VQE(VariationalAlgorithm, MinimumEigensolver):
r"""The Variational Quantum Eigensolver algorithm.
r"""Pending deprecation: Variational Quantum Eigensolver algorithm.
The VQE class has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.VQE` class.
This class will be deprecated in a future release and subsequently
removed after that.
`VQE <https://arxiv.org/abs/1304.3061>`__ is a quantum algorithm that uses a
variational technique to find
Expand Down Expand Up @@ -120,6 +127,13 @@ def my_minimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult:
"""

@deprecate_function(
"The VQE class has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.VQE 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 @@ -171,7 +185,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 @@ -641,10 +657,26 @@ def _get_eigenstate(self, optimal_parameters) -> Union[List[float], Dict[str, in


class VQEResult(VariationalResult, MinimumEigensolverResult):
"""VQE Result."""
"""Pending deprecation: VQE Result.
The VQEResult class has been superseded by the
:class:`qiskit.algorithms.minimum_eigensolvers.VQEResult` class.
This class will be deprecated in a future release and subsequently
removed after that.
"""

@deprecate_function(
"The VQEResult class has been superseded by the "
"qiskit.algorithms.minimum_eigensolvers.VQEResult class. "
"This class will be deprecated in a future release and subsequently "
"removed after that.",
category=PendingDeprecationWarning,
)
def __init__(self) -> None:
super().__init__()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
self._cost_function_evals = None

@property
Expand Down

0 comments on commit 76da497

Please sign in to comment.