211 lines
10 KiB
Plaintext
211 lines
10 KiB
Plaintext
---
|
||
title: SlsqpOptimizer
|
||
description: API reference for qiskit.optimization.algorithms.SlsqpOptimizer
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.optimization.algorithms.SlsqpOptimizer
|
||
---
|
||
|
||
<span id="qiskit-optimization-algorithms-slsqpoptimizer" />
|
||
|
||
# qiskit.optimization.algorithms.SlsqpOptimizer
|
||
|
||
<Class id="qiskit.optimization.algorithms.SlsqpOptimizer" isDedicatedPage={true} github="https://github.com/qiskit-community/qiskit-aqua/tree/stable/0.8/qiskit/optimization/algorithms/slsqp_optimizer.py" signature="SlsqpOptimizer(iter=100, acc=1e-06, iprint=0, trials=1, clip=100.0, full_output=False)" modifiers="class">
|
||
The SciPy SLSQP optimizer wrapped as an Qiskit [`OptimizationAlgorithm`](qiskit.optimization.algorithms.OptimizationAlgorithm "qiskit.optimization.algorithms.OptimizationAlgorithm").
|
||
|
||
This class provides a wrapper for `scipy.optimize.fmin_slsqp` ([https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.optimize.fmin\_slsqp.html](https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.optimize.fmin_slsqp.html)) to be used within the optimization module. The arguments for `fmin_slsqp` are passed via the constructor.
|
||
|
||
**Examples**
|
||
|
||
```python
|
||
>>> from qiskit.optimization.problems import QuadraticProgram
|
||
>>> from qiskit.optimization.algorithms import SlsqpOptimizer
|
||
>>> problem = QuadraticProgram()
|
||
>>> # specify problem here
|
||
>>> x = problem.continuous_var(name="x")
|
||
>>> y = problem.continuous_var(name="y")
|
||
>>> problem.maximize(linear=[2, 0], quadratic=[[-1, 2], [0, -2]])
|
||
>>> optimizer = SlsqpOptimizer()
|
||
>>> result = optimizer.solve(problem)
|
||
```
|
||
|
||
Initializes the SlsqpOptimizer.
|
||
|
||
This initializer takes the algorithmic parameters of SLSQP and stores them for later use of `fmin_slsqp` when [`solve()`](#qiskit.optimization.algorithms.SlsqpOptimizer.solve "qiskit.optimization.algorithms.SlsqpOptimizer.solve") is invoked. This optimizer can be applied to find a (local) optimum for problems consisting of only continuous variables.
|
||
|
||
**Parameters**
|
||
|
||
* **iter** (`int`) – The maximum number of iterations.
|
||
|
||
* **acc** (`float`) – Requested accuracy.
|
||
|
||
* **iprint** (`int`) –
|
||
|
||
The verbosity of fmin\_slsqp :
|
||
|
||
* iprint \<= 0 : Silent operation
|
||
* iprint == 1 : Print summary upon completion (default)
|
||
* iprint >= 2 : Print status of each iterate and summary
|
||
|
||
* **trials** (`int`) – The number of trials for multi-start method. The first trial is solved with the initial guess of zero. If more than one trial is specified then initial guesses are uniformly drawn from `[lowerbound, upperbound]` with potential clipping.
|
||
|
||
* **clip** (`float`) – Clipping parameter for the initial guesses in the multi-start method. If a variable is unbounded then the lower bound and/or upper bound are replaced with the `-clip` or `clip` values correspondingly for the initial guesses.
|
||
|
||
* **full\_output** (`bool`) – If `False`, return only the minimizer of func (default). Otherwise, output final objective function and summary information.
|
||
|
||
### \_\_init\_\_
|
||
|
||
<Function id="qiskit.optimization.algorithms.SlsqpOptimizer.__init__" signature="__init__(iter=100, acc=1e-06, iprint=0, trials=1, clip=100.0, full_output=False)">
|
||
Initializes the SlsqpOptimizer.
|
||
|
||
This initializer takes the algorithmic parameters of SLSQP and stores them for later use of `fmin_slsqp` when [`solve()`](#qiskit.optimization.algorithms.SlsqpOptimizer.solve "qiskit.optimization.algorithms.SlsqpOptimizer.solve") is invoked. This optimizer can be applied to find a (local) optimum for problems consisting of only continuous variables.
|
||
|
||
**Parameters**
|
||
|
||
* **iter** (`int`) – The maximum number of iterations.
|
||
|
||
* **acc** (`float`) – Requested accuracy.
|
||
|
||
* **iprint** (`int`) –
|
||
|
||
The verbosity of fmin\_slsqp :
|
||
|
||
* iprint \<= 0 : Silent operation
|
||
* iprint == 1 : Print summary upon completion (default)
|
||
* iprint >= 2 : Print status of each iterate and summary
|
||
|
||
* **trials** (`int`) – The number of trials for multi-start method. The first trial is solved with the initial guess of zero. If more than one trial is specified then initial guesses are uniformly drawn from `[lowerbound, upperbound]` with potential clipping.
|
||
|
||
* **clip** (`float`) – Clipping parameter for the initial guesses in the multi-start method. If a variable is unbounded then the lower bound and/or upper bound are replaced with the `-clip` or `clip` values correspondingly for the initial guesses.
|
||
|
||
* **full\_output** (`bool`) – If `False`, return only the minimizer of func (default). Otherwise, output final objective function and summary information.
|
||
</Function>
|
||
|
||
## Methods
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
|
||
| [`__init__`](#qiskit.optimization.algorithms.SlsqpOptimizer.__init__ "qiskit.optimization.algorithms.SlsqpOptimizer.__init__")(\[iter, acc, iprint, trials, clip, …]) | Initializes the SlsqpOptimizer. |
|
||
| [`get_compatibility_msg`](#qiskit.optimization.algorithms.SlsqpOptimizer.get_compatibility_msg "qiskit.optimization.algorithms.SlsqpOptimizer.get_compatibility_msg")(problem) | Checks whether a given problem can be solved with this optimizer. |
|
||
| [`is_compatible`](#qiskit.optimization.algorithms.SlsqpOptimizer.is_compatible "qiskit.optimization.algorithms.SlsqpOptimizer.is_compatible")(problem) | Checks whether a given problem can be solved with the optimizer implementing this method. |
|
||
| [`multi_start_solve`](#qiskit.optimization.algorithms.SlsqpOptimizer.multi_start_solve "qiskit.optimization.algorithms.SlsqpOptimizer.multi_start_solve")(minimize, problem) | Applies a multi start method given a local optimizer. |
|
||
| [`solve`](#qiskit.optimization.algorithms.SlsqpOptimizer.solve "qiskit.optimization.algorithms.SlsqpOptimizer.solve")(problem) | Tries to solves the given problem using the optimizer. |
|
||
|
||
## Attributes
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ |
|
||
| [`clip`](#qiskit.optimization.algorithms.SlsqpOptimizer.clip "qiskit.optimization.algorithms.SlsqpOptimizer.clip") | Returns the clip value for this optimizer. |
|
||
| [`trials`](#qiskit.optimization.algorithms.SlsqpOptimizer.trials "qiskit.optimization.algorithms.SlsqpOptimizer.trials") | Returns the number of trials for this optimizer. |
|
||
|
||
### clip
|
||
|
||
<Attribute id="qiskit.optimization.algorithms.SlsqpOptimizer.clip">
|
||
Returns the clip value for this optimizer.
|
||
|
||
**Return type**
|
||
|
||
`float`
|
||
|
||
**Returns**
|
||
|
||
The clip value.
|
||
</Attribute>
|
||
|
||
### get\_compatibility\_msg
|
||
|
||
<Function id="qiskit.optimization.algorithms.SlsqpOptimizer.get_compatibility_msg" signature="get_compatibility_msg(problem)">
|
||
Checks whether a given problem can be solved with this optimizer.
|
||
|
||
Checks whether the given problem is compatible, i.e., whether the problem contains only continuous variables, and otherwise, returns a message explaining the incompatibility.
|
||
|
||
**Parameters**
|
||
|
||
**problem** (`QuadraticProgram`) – The optimization problem to check compatibility.
|
||
|
||
**Return type**
|
||
|
||
`str`
|
||
|
||
**Returns**
|
||
|
||
Returns a string describing the incompatibility.
|
||
</Function>
|
||
|
||
### is\_compatible
|
||
|
||
<Function id="qiskit.optimization.algorithms.SlsqpOptimizer.is_compatible" signature="is_compatible(problem)">
|
||
Checks whether a given problem can be solved with the optimizer implementing this method.
|
||
|
||
**Parameters**
|
||
|
||
**problem** (`QuadraticProgram`) – The optimization problem to check compatibility.
|
||
|
||
**Return type**
|
||
|
||
`bool`
|
||
|
||
**Returns**
|
||
|
||
Returns True if the problem is compatible, False otherwise.
|
||
</Function>
|
||
|
||
### multi\_start\_solve
|
||
|
||
<Function id="qiskit.optimization.algorithms.SlsqpOptimizer.multi_start_solve" signature="multi_start_solve(minimize, problem)">
|
||
Applies a multi start method given a local optimizer.
|
||
|
||
**Parameters**
|
||
|
||
* **minimize** (`Callable`\[\[`array`], `Tuple`\[`array`, `Any`]]) – A callable object that minimizes the problem specified
|
||
* **problem** (`QuadraticProgram`) – A problem to solve
|
||
|
||
**Return type**
|
||
|
||
`OptimizationResult`
|
||
|
||
**Returns**
|
||
|
||
The result of the multi start algorithm applied to the problem.
|
||
</Function>
|
||
|
||
### solve
|
||
|
||
<Function id="qiskit.optimization.algorithms.SlsqpOptimizer.solve" signature="solve(problem)">
|
||
Tries to solves the given problem using the optimizer.
|
||
|
||
Runs the optimizer to try to solve the optimization problem.
|
||
|
||
**Parameters**
|
||
|
||
**problem** (`QuadraticProgram`) – The problem to be solved.
|
||
|
||
**Return type**
|
||
|
||
`OptimizationResult`
|
||
|
||
**Returns**
|
||
|
||
The result of the optimizer applied to the problem.
|
||
|
||
**Raises**
|
||
|
||
[**QiskitOptimizationError**](qiskit.optimization.QiskitOptimizationError "qiskit.optimization.QiskitOptimizationError") – If the problem is incompatible with the optimizer.
|
||
</Function>
|
||
|
||
### trials
|
||
|
||
<Attribute id="qiskit.optimization.algorithms.SlsqpOptimizer.trials">
|
||
Returns the number of trials for this optimizer.
|
||
|
||
**Return type**
|
||
|
||
`int`
|
||
|
||
**Returns**
|
||
|
||
The number of trials.
|
||
</Attribute>
|
||
</Class>
|
||
|