# Quellcode für qiskit.algorithms.optimizers.cg

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2020.
#
# obtain a copy of this license in the LICENSE.txt file in the root directory
#
# 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.

from typing import Optional

from scipy.optimize import minimize
from .optimizer import Optimizer, OptimizerSupportLevel

[Doku]class CG(Optimizer):

CG is an algorithm for the numerical solution of systems of linear equations whose matrices are
symmetric and positive-definite. It is an *iterative algorithm* in that it uses an initial
guess to generate a sequence of improving approximate solutions for a problem,
in which each approximation is derived from the previous ones.  It is often used to solve
unconstrained optimization problems, such as energy minimization.

Uses scipy.optimize.minimize CG.
For further detail, please refer to
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
"""

_OPTIONS = ['maxiter', 'disp', 'gtol', 'eps']

# pylint: disable=unused-argument
[Doku]    def __init__(self,
maxiter: int = 20,
disp: bool = False,
gtol: float = 1e-5,
tol: Optional[float] = None,
eps: float = 1.4901161193847656e-08) -> None:
"""
Args:
maxiter: Maximum number of iterations to perform.
disp: Set to True to print convergence messages.
gtol: Gradient norm must be less than gtol before successful termination.
tol: Tolerance for termination.
eps: If jac is approximated, use this value for the step size.
"""
super().__init__()
for k, v in list(locals().items()):
if k in self._OPTIONS:
self._options[k] = v
self._tol = tol

[Doku]    def get_support_level(self):
""" Return support level dictionary """
return {
'bounds': OptimizerSupportLevel.ignored,
'initial_point': OptimizerSupportLevel.required
}

[Doku]    def optimize(self, num_vars, objective_function, gradient_function=None,
variable_bounds=None, initial_point=None):