# How to read the result of this HHL algorithm circuit output?

I have computed the final states of a 1-qubit HHL circuit using initial conditions

$$A|x\rangle = |b\rangle$$ $$\begin{bmatrix} 8 & 6+i \\ 6-i & -1\end{bmatrix} |x\rangle = \begin{bmatrix} \sqrt{\frac{3}{4}} \\ \sqrt{\frac{1}{4}} \end{bmatrix}$$

by passing the initial conditions through the following circuit:

and end up with the following final-states table (we are now at the far right of the diagram before final measurement of $$q_3$$) (alternative implementations):

and also the final-states table after the 2 different collapse scenarios after measurement of $$q_3$$ (alternative implementations):

Analytically, the 3rd qubit's state numbers should in the end look like:

$$|x\rangle = A^{-1}|b\rangle=\begin{bmatrix} \frac{1}{45} & \frac{6+i}{45} \\ \frac{6-i}{45} & -\frac{8}{45}\end{bmatrix}\begin{bmatrix} \sqrt{\frac{3}{4}} \\ \sqrt{\frac{1}{4}} \end{bmatrix}=\begin{bmatrix} -0.0111 + 0.0859i \\ 0.0192 + 0.0265i \end{bmatrix}$$

which then implies

$$P_{b=0} = 0.0075$$ $$P_{b=1} = 0.0010$$

with the ratio $$\frac{P_{b=0}}{P_{b=1}} = 6.968$$.

I have pooled the complex state vector amplitudes in the case of $$\color{red}{|xxx1\rangle}$$ collapsed remains:

$$|_{q_2 = 0}\rangle = (0.37 - 0.01i) + (-0.01 + 0.20i) + (-0.02 + 0.33i) + (0.02 + 0.01i) \\= 0.36 + 0.53i$$ $$|_{q_2 = 1}\rangle = (0.24+0.02i)+(0.01 + 0.10i) +(0.03 +0.16i)+(-0.01i) \\= 0.28+0.27i$$

which then implies

$$P_{b=0} = 0.410$$ $$P_{b=1} = 0.151$$

with the ratio $$\frac{P_{b=0}}{P_{b=1}} \approx 2.705$$.

As pointed out by @MarkSpinelli too in the comments, $$q_0, q_1$$ should theoretically have reverted back to their original state $$|00\rangle$$ at the end of the circuit?

Could anyone confirm if the circuit diagram above is indeed correct for HHL algorithm, please?

• Shouldn't your first two qubits revert back to $|0\rangle$? After all, they are just part of the QPE. Commented Jun 21, 2023 at 17:28
• how did you run this? did you run it on an actual device, or were you simulating it. Commented Jun 22, 2023 at 19:50
• @MarkSpinelli it's all simulated by following the density matrix over the circuit. I think this circuit diagram is not quite right, but most of the other diagrams I have seen use some vague "QFT" blackboxes or other abstractions that make them unimplementable ... Commented Jun 22, 2023 at 21:47

One of your challenges is that you're only doing phase estimation over two qubits. Basically, this means you're trying to get a 2-bit approximation to the eigenvalues of $$e^{i\pi A/2}$$, i.e. approximating them to $$e^{i\pi 0.x_1x_2}$$. If it happens that the eigenvalues are exactly of that form, then you can expect your answers to come out well. The further away you are, the more messy your results will look.
There's a lot that you can do for your simple example to help it. (It depends how much you feel like this is cheating.) At the very least, you're supposed to have some promises about the range of the eigenvalues of $$A$$. Let's say we know that $$\|A\|<12$$, and thus we imagine the eigenvalues are in the range $$\pm 12$$. We need to make sure that the $$e^{i\theta A}$$ and $$e^{2i\theta A}$$ that you use as the controlled-operations in the phase estimation are chosen such that the range of eigenvalues $$\theta A$$ fall within $$-\pi$$ to $$\pi$$. That way there's no ambiguity in what the eigenvalues are. So, in this case, you'd pick $$\theta=\pi/12$$. Any general case should give you some sort of guarantee like that. It still doesn't guarantee that the eigenvalues are anywhere near close to the set your phase estimation is looking at. The only way to do that without further knowledge is to perform phase estimation using a much larger auxiliary register.
In your specific case, you already know the eigenvalues of $$A$$, so you can actually tune things much better. For example, if you implement $$e^{i7\pi/2\sqrt{229}}e^{iA\pi/\sqrt{229}}$$, then this has exactly the eigenvalues $$e^{\pm i\pi/2}$$ and your calculation should work exactly. Even if you want to use the more generic version where you're not relying on so much information about $$A$$, this is a great way to check that things are really working as you're expecting.
(The other thing that you have to be aware of is that you'll never calculate $$A^{-1}|b\rangle$$. There will always be a normalisation factor.)