# Evaluating the derivative of a Quantum Circuit

After this post this weekend which got an excellent response, I've been trying to get into the solution that is given by the paper and applying it to my circuit. My original circuit is far bigger and probably not good to learn and grasp the solution, so I shortened it to this:

$$CRY_{q_1,q_0}(\omega_{10})(I^{2\times2}\otimes RY(\omega_1))CRY_{q_0,q_1}(\omega_{01})(RY(\omega_0)RY(i_0)|0\rangle \otimes RY(i_1)|0\rangle)$$

Which translates directly to this circuit in qiskit

     ┌────────┐┌────────┐                     ┌─────────┐
q_0: ┤ Ry(i0) ├┤ Ry(w0) ├─────■───────────────┤ Ry(w10) ├
├────────┤└────────┘┌────┴────┐┌────────┐└────┬────┘
q_1: ┤ Ry(i1) ├──────────┤ Ry(w01) ├┤ Ry(w1) ├─────■─────
└────────┘          └─────────┘└────────┘


According to the Chapter Parameter Shift Gradient, "all standard, parameterized Qiskit gates can be shifted with $$\frac{\pi}{2}$$".

This led me to only look at III. Gradients of discrete-variable circuits. It states that _the overall unitary $$U(\theta)$$ can be decomposed into single-parameter gates. So using circuit.decompose(), I get this:

     ┌───────────┐┌───────────┐                          ┌───────────┐┌───┐┌──────────────┐┌───┐
q_0: ┤ R(i0,π/2) ├┤ R(w0,π/2) ├──■────────────────────■──┤ Ry(w10/2) ├┤ X ├┤ Ry(-0.5*w10) ├┤ X ├
├───────────┤├───────────┤┌─┴─┐┌──────────────┐┌─┴─┐├───────────┤└─┬─┘└──────────────┘└─┬─┘
q_1: ┤ R(i1,π/2) ├┤ Ry(w01/2) ├┤ X ├┤ Ry(-0.5*w01) ├┤ X ├┤ R(w1,π/2) ├──■────────────────────■──
└───────────┘└───────────┘└───┘└──────────────┘└───┘└───────────┘


This translate into the following expression

$$CX_{q_1,q_0}(I^{2\times2}\otimes RY(-0.5*\omega_{10})CX_{q_1,q_0}(I^{2\times2}\otimes RY(\frac{\omega_{10}}{2}))(I^{2\times2}\otimes R(\omega_1, \frac{\pi}{2}))CX_{q_0,q_1}(I^{2\times2}\otimes RY(-0.5*\omega_{01}))CX_{q_0,q_1}(R(\omega_0, \frac{\pi}{2})R(i_0, \frac{\pi}{2})|0\rangle \otimes RY(\frac{\omega_{01}}{2})R(i_1,\frac{\pi}{2})|0\rangle)$$

• I could further decompose it, but is that needed?
• Is this even correct? From my understanding and my notes, this is the correct way of calculating the final state vector of the circuit

If my understanding is correct, I now take the derivative of each gate. Whilst at first it seemed straightforward, I am relatively clueless as to where to begin. Now, the paper states that for a single gate $$G(\mu)$$ in the sequence where $$U(\theta) =\ V\mathcal{G}(\mu)W$$, the partial derivative $$\partial_\mu f$$ looks like this:

$$\partial_\mu f =\ \partial_\mu \langle\psi|\mathcal{G}^\dagger\hat{Q}\mathcal{G}|\psi\rangle =\ \langle\psi|\mathcal{G}^\dagger\hat{Q}(\partial_\mu\mathcal{G})|\psi\rangle + \text{h.c.} =\ \frac{1}{2}(\langle\psi|(\mathcal{G}+\partial_\mu\mathcal{G})^\dagger\hat{Q}(\mathcal{G}+\partial\mathcal{G})|\psi\rangle - \langle\psi|(\mathcal{G}-\partial_\mu\mathcal{G})^\dagger\hat{Q}(\mathcal{G}-\partial\mathcal{G})|\psi\rangle)$$

• Would this be correct? Specially concerning $$\text{h.c.}$$? How would I even go on to solve the hermitian conjugate of it?
• In $$U(\theta) =\ V\mathcal{G}(\mu)W$$, what is $$V$$ and $$W$$? What in my circuit would correspond to these? I assume that $$W$$ is everything that happens before $$\mathcal{G}(\mu)$$ is applied to $$|0\rangle$$, as it states $$|\psi\rangle=\ W|0\rangle$$?

It then tells me that $$V$$ gets absorbed into an observable Hermitian, $$\hat{Q} =\ V^\dagger\hat{B}V$$, which I can't quite follow. I assume we need the observable Hermitian to optimize for, but that's more a guess than anything really.

How do I go from here? I tried to put my open questions as bullet points and in cursive for a better overview but can understand if this is the wrong place/too much for one question. My questions probably won't end here, but maybe these give me enough insight to take on the rest by myself :)