Skip to content

Commit

Permalink
Merge branch 'main' into sabres-for-everyone
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Sep 29, 2022
2 parents 2c2a5af + fca3864 commit 505cab6
Show file tree
Hide file tree
Showing 73 changed files with 4,252 additions and 422 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ qiskit/utils/ @Qiskit/terra-core @manoelmarques @woodsp-ibm
providers/ @Qiskit/terra-core @jyu00
quantum_info/ @Qiskit/terra-core @ikkoham
qpy/ @Qiskit/terra-core @nkanazawa1989
pulse/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
scheduler/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
pulse/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @wshanks
scheduler/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @wshanks
visualization/ @Qiskit/terra-core @nonhermitian @nkanazawa1989
primitives/ @Qiskit/terra-core @ikkoham @t-imamichi
# Override the release notes directories to have _no_ code owners, so any review
Expand Down
16 changes: 14 additions & 2 deletions qiskit/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@
linear_solvers
Minimum Eigensolvers
--------------------
Minimum Eigen Solvers
---------------------
Algorithms that can find the minimum eigenvalue of an operator.
These algorithms are pending depreciation. One should instead make use of the
Minimum Eigensolver classes in the section below, which leverage Runtime primitives.
.. autosummary::
:toctree: ../stubs/
Expand All @@ -203,6 +205,16 @@
QAOA
VQE
Minimum Eigensolvers
--------------------
Algorithms that can find the minimum eigenvalue of an operator and leverage primitives.
.. autosummary::
:toctree: ../stubs/
minimum_eigensolvers
Optimizers
----------
Expand Down
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
53 changes: 53 additions & 0 deletions qiskit/algorithms/minimum_eigensolvers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 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
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
============================================================================
Minimum Eigensolvers Package (:mod:`qiskit.algorithms.minimum_eigensolvers`)
============================================================================
.. currentmodule:: qiskit.algorithms.minimum_eigensolvers
Minimum Eigensolvers
====================
.. autosummary::
:toctree: ../stubs/
MinimumEigensolver
NumPyMinimumEigensolver
VQE
AdaptVQE
.. autosummary::
:toctree: ../stubs/
MinimumEigensolverResult
NumPyMinimumEigensolverResult
VQEResult
AdaptVQEResult
"""

from .adapt_vqe import AdaptVQE, AdaptVQEResult
from .minimum_eigensolver import MinimumEigensolver, MinimumEigensolverResult
from .numpy_minimum_eigensolver import NumPyMinimumEigensolver, NumPyMinimumEigensolverResult
from .vqe import VQE, VQEResult

__all__ = [
"AdaptVQE",
"AdaptVQEResult",
"MinimumEigensolver",
"MinimumEigensolverResult",
"NumPyMinimumEigensolver",
"NumPyMinimumEigensolverResult",
"VQE",
"VQEResult",
]
Loading

0 comments on commit 505cab6

Please sign in to comment.