qiskit.opflow.gradients.Hessian¶
-
class
Hessian
(hess_method='param_shift', **kwargs)[소스]¶ Compute the Hessian of an expected value.
- 매개변수
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
- 예외
ValueError – If method !=
fin_diff
andepsilon
is not None.
-
__init__
(hess_method='param_shift', **kwargs)¶ - 매개변수
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
- 예외
ValueError – If method !=
fin_diff
andepsilon
is not None.
Methods
__init__
([hess_method])- type hess_method
Union
[str
,CircuitGradient
]
convert
(operator[, params])- type operator
OperatorBase
get_hessian
(operator[, params])Get the Hessian for the given operator w.r.t.
gradient_wrapper
(operator, bind_params[, …])Get a callable function which provides the respective gradient, Hessian or QFI for given parameter values.
parameter_expression_grad
(param_expr, param)Get the derivative of a parameter expression w.r.t.
Attributes
Returns
CircuitGradient
.-
convert
(operator, params=None)[소스]¶ - 매개변수
operator (
OperatorBase
) – The operator for which we compute the Hessianparams (
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.
- 반환값
An operator whose evaluation yields the Hessian
- 반환 형식
-
get_hessian
(operator, params=None)[소스]¶ Get the Hessian for the given operator w.r.t. the given 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.
- 반환 형식
OperatorBase
- 반환값
Operator which represents the gradient w.r.t. the given params.
- 예외
ValueError – If
params
contains a parameter not present inoperator
.ValueError – If
operator
is not parameterized.OpflowError – If the coefficient of the operator could not be reduced to 1.
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 – jax not installed
-
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.
- 매개변수
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_paramsbackend (
Union
[BaseBackend
,QuantumInstance
,None
]) – The quantum backend or QuantumInstance to use to evaluate the gradient, Hessian or QFI.
- 반환값
Function to compute a gradient, Hessian or QFI. The function takes an iterable as argument which holds the parameter values.
- 반환 형식
callable(param_values)
-
property
hess_method
¶ Returns
CircuitGradient
.- 반환 형식
CircuitGradient
- 반환값
CircuitGradient
.
-
static
parameter_expression_grad
(param_expr, param)¶ Get the derivative of a parameter expression w.r.t. the given parameter.
- 매개변수
param_expr (
ParameterExpression
) – The Parameter Expression for which we compute the derivativeparam (
ParameterExpression
) – Parameter w.r.t. which we want to take the derivative
- 반환 형식
Union
[ParameterExpression
,float
]- 반환값
ParameterExpression representing the gradient of param_expr w.r.t. param