common.title

Overview
Service overview
Terms of service

Privacy policy

Contact

Sign in
Sign up
common.title

Parameter-shift rule (Part 1)

Gaurav Singh

2021/04/22 12:19
#Machine Learning #Gradient #Optimization #Circuit Learning #Parameter-shift rule

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 :

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

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

f(θ)=ψ|UG(θ)AUG(θ)|ψf(\theta) = \left\langle \psi \middle | U_G^{\dagger}(\theta) A U_G(\theta) \middle| \psi \right\rangle

where UG(θ)=eiaθGU_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:

ddθf(θ)=r[f(θ+π4r)f(θπ4r)]\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 = AAA \dagger A = I. Using this property and the taylor series expansion and write the unitary operator UG(θ)U_G(\theta) as IcosθiAsinθI \cos{\theta} - iA\sin{\theta} as the operator can be written in the euler form as eiθAe^{-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 :

ddθf(θ)=ψ|GUG(θ)AUG(θ)|ψψ|UG(θ)AGUG(θ)|ψ\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 :

ddθf(θ)=ψ|UG(θ)[G,A]UG(θ)|ψ\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(Ui(π2)BUi(π2)Ui(π2)BUi(π2)) [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 :

ddθ=ψ|UG(θ+π2)AUG(θ+π2)|ψψ|UG(θπ2)AUG(θπ2)|ψ\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(θ+π2)f(θπ2)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 a2(e1e0)\frac{a}{2}(e_1-e_0) where e represent the eigenvalues.

Thus we can write the unitary operator as:

UG=eiaθG=IcosrθiarGsinrθ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 :

UG(π4r)=12(I±arG)U_G(\frac{\pi}{4r}) = \frac{1}{\sqrt{2}}(I \pm \frac{a}{r}G)

and again taking the derivative of UG(θ)=eiaθGU_G(\theta) = e^{-ia\theta G} comes out to be iaGeiaθG-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 :

ddθf(θ)=rψ|UG(θ+π4r)AUG(θ+π4r)|ψψ|UG(θπ4r)AUG(θπ4r)|ψ\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(θ+π4r)f(θπ4r)] = 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 RX(θ)R_X(\theta) then r comes out to be 12\frac{1}{2} and if we write the above in the form of RX(πt)R_X(\pi t), then the value of r comes out to be π2\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 :

© 2024, blueqat Inc. All rights reserved