This page was generated from docs/tutorials/12_gradients_framework.ipynb.

Gradient Framework#

This tutorial demonstrates the use of the qiskit_algorithms.gradients module to evaluate quantum gradients using the Qiskit Primitives.


The gradient frameworks allows the evaluation of quantum gradients (see Schuld et al. and Mari et al.). Besides gradients of expectation values of the form


and sampling probabilities of the form

\[p_j(\theta) = |\langle j | \psi(\theta)\rangle|^2\]

the gradient frameworks also support the evaluation of the Quantum Geometric Tensor (QGT) and Quantum Fisher Information (QFI) of quantum states \(|\psi\left(\theta\right)\rangle\).

A quick refresher on Qiskit Primitives#

The Qiskit Primitives work as an abstraction level between algorithms and (real/simulated) quantum devices. Instead of having to manually deal with tasks such as parameter binding or circuit transpilation, the primitives module offers a Sampler and an Estimator class that take the circuits, the observable Hamiltonians, and the circuit parameters and return the sampling distribution and the computed expectation values respectively.

qiskit.primitives provides two classes for evaluating the circuit: - The Estimator class allows to evaluate expectation values of observables with respect to states prepared by quantum circuits. - The Sampler class returns quasi-probability distributions as a result of sampling quantum circuits.

The qiskit_algorithms.gradients Framework#

The qiskit_algorithms.gradients module contains tools to compute both circuit gradients and circuit metrics. The gradients extend the BaseEstimatorGradient and BaseSamplerGradient base classes. These are abstract classes on top of which different gradient methods have been implemented. The methods currently available in this module are: - Parameter Shift Gradients - Finite Difference Gradients - Linear Combination of Unitaries Gradients - Simultaneous Perturbation Stochastic Approximation (SPSA) Gradients

Additionally, the module offers reverse gradients for efficient classical computations.

The metrics available are based on the notion of the Quantum Geometric Tensor (QGT). There is a BaseQGT class (Estimator-based) on top of which different QGT methods have been implemented: - Linear Combination of Unitaries QGT - Reverse QGT (classical) As well as a Quantum Fisher Information class (QFI) that is initialized with a reference QGT implementation from the above list.