qiskit/releasenotes/notes/0.19/optimizer-minimize-5a5a1e9d...

58 lines
1.7 KiB
YAML

---
features:
- |
Added an :meth:`.Optimizer.minimize` method to all optimizers:
:class:`~qiskit.algorithms.optimizers.Optimizer` and derived classes.
This method mimics the signature of SciPy's ``minimize()`` function and
returns an :class:`~qiskit.algorithms.optimizers.OptimizerResult`.
For example
.. code-block:: python
import numpy as np
from qiskit.algorithms.optimizers import COBYLA
def loss(x):
return -(x[0] - 1) ** 2 - (x[1] + 1) ** 3
initial_point = np.array([0, 0])
optimizer = COBYLA()
result = optimizer.minimize(loss, initial_point)
optimal_parameters = result.x
minimum_value = result.fun
num_function_evals = result.nfev
deprecations:
- |
The :meth:`.Optimizer.optimize` method for all the optimizers
(:class:`~qiskit.algorithms.optimizers.Optimizer` and derived classes) is
now deprecated and will be removed in a future release. Instead, the
:meth:`.Optimizer.minimize` method should be used which mimics the signature
of SciPy's ``minimize()`` function.
To replace the current `optimize` call with `minimize` you can replace
.. code-block:: python
xopt, fopt, nfev = optimizer.optimize(
num_vars,
objective_function,
gradient_function,
variable_bounds,
initial_point,
)
with
.. code-block:: python
result = optimizer.minimize(
fun=objective_function,
x0=initial_point,
jac=gradient_function,
bounds=variable_bounds,
)
xopt, fopt, nfev = result.x, result.fun, result.nfev