# Parameter-shift rule (Part 1)

When we talk about variational circuits, we look at a hybrid structure where we see a quantum circuit and quantum measurements which are trained by a classical optimization algorithm. Some examples are Variational Quantum Eigensolver, Quantum Approximate Optimization Algorithm and some aspects of Quantum Machine Learning.

Briefly we have three ingredients for the quantum structure :

1. An initial fixed quantum state.
2. A parametrized quantum circuit which is also known as ansatz with some free parameters $\theta$.
3. Measurement of an observable at the output.

Typically the expectation value represents the output of the objective function $f(\theta)$ which is given by the following equation :

$f(\theta) = \left\langle \psi \middle | U_G^{\dagger}(\theta) A U_G(\theta) \middle| \psi \right\rangle$

where $U_G(\theta) = e^{-ia\theta G}$ and the generator gate G is hermitian.

Some of the promising approaches for the classical optimization include gradient descent, stochastic gradient descent, ADAM when the input data set is large. Another promising approach for calculating the gradient of the quantum parametrized circuits is the parameter shift rule.

### Parameter-shift rule

The parameter-shift rule can be easily applied to quantum circuits with the generator gates having 2 unique eigenvalues. Parameter shift rule states that if we have a generator gate G with 2 unique eigenvalues, we can write the derivative of the expectation value of the quantum circuit as:

$\frac{d}{d\theta} f(\theta) = r[f(\theta + \frac{\pi}{4r}) - f(\theta - \frac{\pi}{4r})]$ where r is the shift constant.

What do you mean by an operator being idempotent? Let say we have an operator A which is both hermitian and unitary, then AA = $A \dagger A$ = I. Using this property and the taylor series expansion and write the unitary operator $U_G(\theta)$ as $I \cos{\theta} - iA\sin{\theta}$ as the operator can be written in the euler form as $e^{-i\theta A}$ and using the above idempotent property and the taylor series we can write it in the above form.

Parameter-shift rule when the generator gate is both unitary and hermitian :

$\frac{d}{d\theta} f(\theta) = \left \langle \psi \middle | G U_G^{\dagger} (\theta) A U_G(\theta) \middle | \psi \right\rangle - \left \langle \psi \middle | U_G^{\dagger} (\theta) A G U_G(\theta) \middle | \psi \right\rangle$ Using the commutator formula we can write the above as :

$\frac{d}{d\theta} f(\theta) = \left \langle \psi \middle | U_G^{\dagger} (\theta) [G , A] U_G(\theta) \middle | \psi \right\rangle$

where [A , B] = AB-BA.

In order to convert the above commutator formula to unitary operator format we use the following mathematical identity :

$[A , B] = -i(U_i^{\dagger}(\frac{\pi}{2})BU_i(\frac{\pi}{2}) - U_i^{\dagger} (\frac{-\pi}{2})BU_i(\frac{-\pi}{2}))$

Using the above identity in the derivative equation gives us :

$\frac{d}{d\theta} = \left \langle \psi \middle | U_G^{\dagger} (\theta + \frac{\pi}{2}) A U_G(\theta + \frac{\pi}{2}) \middle | \psi \right\rangle - \left \langle \psi \middle | U_G^{\dagger} (\theta - \frac{\pi}{2}) A U_G(\theta - \frac{\pi}{2}) \middle | \psi \right\rangle$

= $f(\theta + \frac{\pi}{2}) - f(\theta - \frac{\pi}{2})$

The above gets a bit complex when the generator gate isn't unitary but still has 2 unique eigenvalues. In such cases we introduce a shift constant r which is equivalent to $\frac{a}{2}(e_1-e_0)$ where e represent the eigenvalues.

Thus we can write the unitary operator as:

$U_G = e^{-ia\theta G} = I\cos{r\theta} - i \frac{a}{r}G\sin{r\theta}$

A special case of the above is :

$U_G(\frac{\pi}{4r}) = \frac{1}{\sqrt{2}}(I \pm \frac{a}{r}G)$

and again taking the derivative of $U_G(\theta) = e^{-ia\theta G}$ comes out to be $-iaGe^{-ia\theta G}$.

Using the derivative equation like we used before (using the product rule) and replacing the value of the above special case of the unitary operator in the derivative equation, we get the final parameter shift rule equation consisting of the the shift constant r as :

$\frac{d}{d\theta} f(\theta) = r\left \langle \psi \middle | U_G^{\dagger} (\theta + \frac{\pi}{4r}) A U_G(\theta + \frac{\pi}{4r}) \middle | \psi \right\rangle - \left \langle \psi \middle | U_G^{\dagger} (\theta - \frac{\pi}{4r}) A U_G(\theta - \frac{\pi}{4r}) \middle | \psi \right\rangle$

$= r[f(\theta + \frac{\pi}{4r}) - f(\theta - \frac{\pi}{4r})]$

The value of the shift constant r here depends on the type of parametrizations. If we use $R_X(\theta)$ then r comes out to be $\frac{1}{2}$ and if we write the above in the form of $R_X(\pi t)$, then the value of r comes out to be $\frac{\pi}{2}$.

So here we see how to apply the parameter-shift rule to 1 qubit geenrator gates. In the case of two qubit generator gates we use gate decomposition to perform the same. We will be discussing that in the next part of the article.

References :