# Variational Quantum Linear Solver (Hadamard test): circuit question

Trying to understand the circuit/algorithm for VQLS and I found this diagram to show the high-level idea of doing the Hadamard test in this tutorial. But I am not quite sure why we need the two circuit blocks in the red box that I drew.

I appreciate the insight.

• Can you share the link from where you found that image so people can look at it and answer your questions more easily? Jun 24 at 15:32
• From the first glance, it looks like an uncomputation step(see that it is the exact inverse of block 2 and block 3) so as to restore the all 0 state of the ancilla register but as @epelaaez said, source of that image would be pretty helpful. Jun 24 at 16:00
• @epelaaez just added the link . Thanks Jun 24 at 16:44
• I think I answered this here: quantumcomputing.stackexchange.com/a/16934/1386. It might not be a full answer, this question is not really a duplicate, but it might be enough to fill the gap. Tell me if this does not answer your question. Jun 24 at 17:03
• @Andrien Suau Thank you Jun 24 at 17:26

This circuit is used to calculate the coefficients $$\mu_{l, l', j}$$ which appear in the numerator of $$C_ L$$

\begin{align*}\mu_{l, l', j} = \langle 0| V^\dagger A_{l'}^\dagger U Z_j U^\dagger A_l V |0\rangle\end{align*}

Hadamard test is used to calculate the expectation value $$\langle\psi|{\bf Q}|\psi\rangle$$.

Now we have,

$$\langle\psi|{\bf Q}|\psi\rangle\ = \langle 0| V^\dagger (A_{l'}^\dagger U Z_j U^\dagger A_l) V |0\rangle$$

That is, $$|\psi\rangle\ = V |0\rangle$$ and $${\bf Q} = A_{l'}^\dagger U Z_j U^\dagger A_l$$.

• Thank you so much Both of you Very clear! Salute! Jun 24 at 17:18
• But why do you need to control $A$ but not $U$ (here I refer to $U$ as the blue box of the circuit)? I thought that in a Hadamard test you need to control all the unitaries used to encode $U$ (here by $U$ I mean the general unitary in your answer) Jun 24 at 21:08
• @Enrico, You are correct in assuming that the $U$ should be controlled. However, it is also equivalent not to include the control. See Adrien Suau's answer in this question for an explanation: quantumcomputing.stackexchange.com/questions/16931/… Jun 24 at 23:25
• @thespaceman Thanks for the link, it makes perfect sense! Jun 25 at 13:18
• @Egretta.Thula Follow-up question on calculating the expectation value. $$\langle\psi|{\bf Q}|\psi\rangle\ = \langle 0| V^\dagger (A_{l'}^\dagger U Z_j U^\dagger A_l) V |0\rangle$$ I assume this is done in Z (standard) basis or do we have to do transformation based on the matrix A , similar to VQE, to measure the expectation value? Jun 29 at 19:48