qml.gradients.generate_multi_shift_rule

generate_multi_shift_rule(frequencies, shifts=None, orders=None)[source]

Computes the parameter shift rule with respect to two parametrized unitaries, given their generator’s eigenvalue frequency spectrum. This corresponds to a shift rule that computes off-diagonal elements of higher order derivative tensors. For the second order, this corresponds to the Hessian.

Parameters
  • frequencies (list[tuple[int or float]]) – List of eigenvalue frequencies corresponding to the each parametrized unitary.

  • shifts (list[tuple[int or float]]) – List of shift values corresponding to each parametrized unitary. If unspecified, equidistant shifts are assumed. If supplied, the length of each tuple in the list must be the same as the length of the corresponding tuple in frequencies.

  • orders (list[int]) – the order of differentiation for each parametrized unitary. If unspecified, the first order derivative shift rule is computed for each parametrized unitary.

Returns

a tuple of coefficients, shifts for the first parameter, and shifts for the second parameter, describing the gradient rule for the parameter-shift method.

For parameters \(\phi_a\) and \(\phi_b\), the coefficients \(c_i\) and the shifts \(s^{(a)}_i\), \(s^{(b)}_i\), combine to give a gradient rule of the following form:

\[\frac{\partial^2}{\partial\phi_a \partial\phi_b}f = \sum_{i} c_i f(\phi_a + s^{(a)}_i, \phi_b + s^{(b)}_i).\]

where \(f(\phi_a, \phi_b) = \langle 0|U(\phi_a)^\dagger V(\phi_b)^\dagger \hat{O} V(\phi_b) U(\phi_a)|0\rangle\) for some observable \(\hat{O}\) and unitaries \(U(\phi_a)=e^{iH_a\phi_a}\) and \(V(\phi_b)=e^{iH_b\phi_b}\).

Return type

tuple

Example

>>> generate_multi_shift_rule([(1,), (1,)])
array([[ 0.25      ,  1.57079633,  1.57079633],
       [-0.25      ,  1.57079633, -1.57079633],
       [-0.25      , -1.57079633,  1.57079633],
       [ 0.25      , -1.57079633, -1.57079633]])

This corresponds to the gradient rule

\[\begin{split}\begin{align*} \frac{\partial^2 f}{\partial x\partial y} &= \frac{1}{4} [f(x+\pi/2, y+\pi/2) - f(x+\pi/2, y-\pi/2)\\ &\phantom{\frac{1}{4}[}-f(x-\pi/2, y+\pi/2) + f(x-\pi/2, y-\pi/2) ]. \end{align*}\end{split}\]