154 lines
8.8 KiB
Plaintext
154 lines
8.8 KiB
Plaintext
---
|
||
title: Hessian
|
||
description: API reference for qiskit.opflow.gradients.Hessian
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.opflow.gradients.Hessian
|
||
---
|
||
|
||
# qiskit.opflow\.gradients.Hessian
|
||
|
||
<Class id="qiskit.opflow.gradients.Hessian" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/opflow/gradients/hessian.py" signature="Hessian(hess_method='param_shift', **kwargs)" modifiers="class">
|
||
Compute the Hessian of an expected value.
|
||
|
||
**Parameters**
|
||
|
||
* **hess\_method** (`Union`\[`str`, `CircuitGradient`]) – The method used to compute the state/probability gradient. Can be either `'param_shift'` or `'lin_comb'` or `'fin_diff'`. Ignored for gradients w\.r.t observable parameters.
|
||
* **kwargs** (*dict*) – Optional parameters for a CircuitGradient
|
||
|
||
**Raises**
|
||
|
||
**ValueError** – If method != `fin_diff` and `epsilon` is not None.
|
||
|
||
### \_\_init\_\_
|
||
|
||
<Function id="qiskit.opflow.gradients.Hessian.__init__" signature="__init__(hess_method='param_shift', **kwargs)">
|
||
**Parameters**
|
||
|
||
* **hess\_method** (`Union`\[`str`, `CircuitGradient`]) – The method used to compute the state/probability gradient. Can be either `'param_shift'` or `'lin_comb'` or `'fin_diff'`. Ignored for gradients w\.r.t observable parameters.
|
||
* **kwargs** (*dict*) – Optional parameters for a CircuitGradient
|
||
|
||
**Raises**
|
||
|
||
**ValueError** – If method != `fin_diff` and `epsilon` is not None.
|
||
</Function>
|
||
|
||
## Methods
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
||
| [`__init__`](#qiskit.opflow.gradients.Hessian.__init__ "qiskit.opflow.gradients.Hessian.__init__")(\[hess\_method]) | **type hess\_method**`Union`\[`str`, `CircuitGradient`] |
|
||
| [`convert`](#qiskit.opflow.gradients.Hessian.convert "qiskit.opflow.gradients.Hessian.convert")(operator\[, params]) | **type operator**`OperatorBase` |
|
||
| [`get_hessian`](#qiskit.opflow.gradients.Hessian.get_hessian "qiskit.opflow.gradients.Hessian.get_hessian")(operator\[, params]) | Get the Hessian for the given operator w\.r.t. |
|
||
| [`gradient_wrapper`](#qiskit.opflow.gradients.Hessian.gradient_wrapper "qiskit.opflow.gradients.Hessian.gradient_wrapper")(operator, bind\_params\[, …]) | Get a callable function which provides the respective gradient, Hessian or QFI for given parameter values. |
|
||
| [`parameter_expression_grad`](#qiskit.opflow.gradients.Hessian.parameter_expression_grad "qiskit.opflow.gradients.Hessian.parameter_expression_grad")(param\_expr, param) | Get the derivative of a parameter expression w\.r.t. |
|
||
|
||
## Attributes
|
||
|
||
| | |
|
||
| ----------------------------------------------------------------------------------------------------------- | -------------------------- |
|
||
| [`hess_method`](#qiskit.opflow.gradients.Hessian.hess_method "qiskit.opflow.gradients.Hessian.hess_method") | Returns `CircuitGradient`. |
|
||
|
||
### convert
|
||
|
||
<Function id="qiskit.opflow.gradients.Hessian.convert" signature="convert(operator, params=None)">
|
||
**Parameters**
|
||
|
||
* **operator** (`OperatorBase`) – The operator for which we compute the Hessian
|
||
* **params** (`Union`\[`Tuple`\[`ParameterExpression`, `ParameterExpression`], `List`\[`Tuple`\[`ParameterExpression`, `ParameterExpression`]], `List`\[`ParameterExpression`], `ParameterVector`, `None`]) – The parameters we are computing the Hessian with respect to Either give directly the tuples/list of tuples for which the second order derivative is to be computed or give a list of parameters to build the full Hessian for those parameters. If not explicitly passed, the full Hessian is constructed. The parameters are then inferred from the operator and sorted by name.
|
||
|
||
**Returns**
|
||
|
||
An operator whose evaluation yields the Hessian
|
||
|
||
**Return type**
|
||
|
||
[OperatorBase](qiskit.aqua.operators.OperatorBase "qiskit.aqua.operators.OperatorBase")
|
||
</Function>
|
||
|
||
### get\_hessian
|
||
|
||
<Function id="qiskit.opflow.gradients.Hessian.get_hessian" signature="get_hessian(operator, params=None)">
|
||
Get the Hessian for the given operator w\.r.t. the given parameters
|
||
|
||
**Parameters**
|
||
|
||
* **operator** (`OperatorBase`) – Operator w\.r.t. which we take the Hessian.
|
||
* **params** (`Union`\[`Tuple`\[`ParameterExpression`, `ParameterExpression`], `List`\[`Tuple`\[`ParameterExpression`, `ParameterExpression`]], `List`\[`ParameterExpression`], `ParameterVector`, `None`]) – Parameters w\.r.t. which we compute the Hessian. If not explicitly passed, the full Hessian is constructed. The parameters are then inferred from the operator and sorted by name.
|
||
|
||
**Return type**
|
||
|
||
`OperatorBase`
|
||
|
||
**Returns**
|
||
|
||
Operator which represents the gradient w\.r.t. the given params.
|
||
|
||
**Raises**
|
||
|
||
* **ValueError** – If `params` contains a parameter not present in `operator`.
|
||
* **ValueError** – If `operator` is not parameterized.
|
||
* [**OpflowError**](qiskit.opflow.OpflowError "qiskit.opflow.OpflowError") – If the coefficient of the operator could not be reduced to 1.
|
||
* [**OpflowError**](qiskit.opflow.OpflowError "qiskit.opflow.OpflowError") – If the differentiation of a combo\_fn requires JAX but the package is not installed.
|
||
* **TypeError** – If the operator does not include a StateFn given by a quantum circuit
|
||
* **TypeError** – If the parameters were given in an unsupported format.
|
||
* **Exception** – Unintended code is reached
|
||
* [**MissingOptionalLibraryError**](qiskit.aqua.MissingOptionalLibraryError "qiskit.aqua.MissingOptionalLibraryError") – jax not installed
|
||
</Function>
|
||
|
||
### gradient\_wrapper
|
||
|
||
<Function id="qiskit.opflow.gradients.Hessian.gradient_wrapper" signature="gradient_wrapper(operator, bind_params, grad_params=None, backend=None)">
|
||
Get a callable function which provides the respective gradient, Hessian or QFI for given parameter values. This callable can be used as gradient function for optimizers.
|
||
|
||
**Parameters**
|
||
|
||
* **operator** (`OperatorBase`) – The operator for which we want to get the gradient, Hessian or QFI.
|
||
* **bind\_params** (`Union`\[`ParameterExpression`, `ParameterVector`, `List`\[`ParameterExpression`]]) – The operator parameters to which the parameter values are assigned.
|
||
* **grad\_params** (`Union`\[`ParameterExpression`, `ParameterVector`, `List`\[`ParameterExpression`], `Tuple`\[`ParameterExpression`, `ParameterExpression`], `List`\[`Tuple`\[`ParameterExpression`, `ParameterExpression`]], `None`]) – The parameters with respect to which we are taking the gradient, Hessian or QFI. If grad\_params = None, then grad\_params = bind\_params
|
||
* **backend** (`Union`\[`BaseBackend`, `QuantumInstance`, `None`]) – The quantum backend or QuantumInstance to use to evaluate the gradient, Hessian or QFI.
|
||
|
||
**Returns**
|
||
|
||
Function to compute a gradient, Hessian or QFI. The function takes an iterable as argument which holds the parameter values.
|
||
|
||
**Return type**
|
||
|
||
callable(param\_values)
|
||
</Function>
|
||
|
||
### hess\_method
|
||
|
||
<Attribute id="qiskit.opflow.gradients.Hessian.hess_method">
|
||
Returns `CircuitGradient`.
|
||
|
||
**Return type**
|
||
|
||
`CircuitGradient`
|
||
|
||
**Returns**
|
||
|
||
`CircuitGradient`.
|
||
</Attribute>
|
||
|
||
### parameter\_expression\_grad
|
||
|
||
<Function id="qiskit.opflow.gradients.Hessian.parameter_expression_grad" signature="parameter_expression_grad(param_expr, param)" modifiers="static">
|
||
Get the derivative of a parameter expression w\.r.t. the given parameter.
|
||
|
||
**Parameters**
|
||
|
||
* **param\_expr** (`ParameterExpression`) – The Parameter Expression for which we compute the derivative
|
||
* **param** (`ParameterExpression`) – Parameter w\.r.t. which we want to take the derivative
|
||
|
||
**Return type**
|
||
|
||
`Union`\[`ParameterExpression`, `float`]
|
||
|
||
**Returns**
|
||
|
||
ParameterExpression representing the gradient of param\_expr w\.r.t. param
|
||
</Function>
|
||
</Class>
|
||
|