---
title: Gradient (v0.46)
description: API reference for qiskit.opflow.gradients.Gradient in qiskit v0.46
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/0.46/qiskit.opflow.gradients.Gradient
---

# Gradient

*class* `qiskit.opflow.gradients.Gradient(grad_method='param_shift', **kwargs)`

[GitHub](https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/opflow/gradients/gradient.py)

Bases: [`GradientBase`](/docs/api/qiskit/0.46/qiskit.opflow.gradients.GradientBase "qiskit.opflow.gradients.gradient_base.GradientBase")

Deprecated: Convert an operator expression to the first-order gradient.

> **Deprecated since version 0.24.0**
>
> The class `qiskit.opflow.gradients.gradient.Gradient` is deprecated as of qiskit-terra 0.24.0. It will be removed in the Qiskit 1.0 release. For code migration guidelines, visit [https://qisk.it/opflow\_migration](https://qisk.it/opflow_migration).

## Attributes

### grad\_method

Returns `CircuitGradient`.

**Returns**

`CircuitGradient`.

## Methods

### convert

`convert(operator, params=None)`

**Parameters**

- **operator** ([*OperatorBase*](/docs/api/qiskit/0.46/qiskit.opflow.OperatorBase "qiskit.opflow.operator_base.OperatorBase")) – The operator we are taking the gradient of.
- **params** ([*ParameterVector*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterVector "qiskit.circuit.parametervector.ParameterVector")  *|*[*ParameterExpression*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")  *|*[*List*](https://docs.python.org/3/library/typing.html#typing.List)*\[*[*ParameterExpression*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")*] | None*) – The parameters we are taking the gradient with respect to. If not explicitly passed, they are inferred from the operator and sorted by name.

**Returns**

An operator whose evaluation yields the Gradient.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If `params` contains a parameter not present in `operator`.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If `operator` is not parameterized.

**Return type**

[*OperatorBase*](/docs/api/qiskit/0.46/qiskit.opflow.OperatorBase "qiskit.opflow.operator_base.OperatorBase")

### get\_gradient

`get_gradient(operator, params)`

Get the gradient for the given operator w\.r.t. the given parameters

**Parameters**

- **operator** ([*OperatorBase*](/docs/api/qiskit/0.46/qiskit.opflow.OperatorBase "qiskit.opflow.operator_base.OperatorBase")) – Operator w\.r.t. which we take the gradient.
- **params** ([*ParameterExpression*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")  *|*[*ParameterVector*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterVector "qiskit.circuit.parametervector.ParameterVector")  *|*[*List*](https://docs.python.org/3/library/typing.html#typing.List)*\[*[*ParameterExpression*](/docs/api/qiskit/0.46/qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")*]*) – Parameters w\.r.t. which we compute the gradient.

**Returns**

Operator which represents the gradient w\.r.t. the given params.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If `params` contains a parameter not present in `operator`.
- [**OpflowError**](/docs/api/qiskit/0.46/opflow#qiskit.opflow.OpflowError "qiskit.opflow.OpflowError") – If the coefficient of the operator could not be reduced to 1.
- [**OpflowError**](/docs/api/qiskit/0.46/opflow#qiskit.opflow.OpflowError "qiskit.opflow.OpflowError") – If the differentiation of a combo\_fn requires JAX but the package is not installed.
- [**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError) – If the operator does not include a StateFn given by a quantum circuit
- [**Exception**](https://docs.python.org/3/library/exceptions.html#Exception) – Unintended code is reached
- [**MissingOptionalLibraryError**](/docs/api/qiskit/0.46/exceptions#qiskit.exceptions.MissingOptionalLibraryError "qiskit.exceptions.MissingOptionalLibraryError") – jax not installed

**Return type**

[*OperatorBase*](/docs/api/qiskit/0.46/qiskit.opflow.OperatorBase "qiskit.opflow.operator_base.OperatorBase")
