# How to extract a solution to HHL from the full statevector?

I am having a difficult time trying to extract an HHL matrix inversion solution from the full system statevector.

I have a 32x32 size matrix A and a 32x1 vector b, and I ran HHL on 13 qubits. HHL outputted the following circuit diagram:

Following the textbook, the solution vector would correspond to the ancilla qubit being in state $$|1\rangle$$, and all the interior work qubits being in state $$|0\rangle$$.

So do the correct vector components in this case correspond to the coefficients of $$|1000000000000\rangle$$ to $$|1000000011111\rangle$$? The solution vector has a full element count of $$2^{13}=8192$$. I've calculated these corresponding solution indices to be 4095:4128. However, in trying to extract this solution from the complete statevector I am getting completely erroneous results. Any help would be greatly appreciated!

• Hi and welcome to Quantum Computing SE. Note that the solution gained in HHL algorithm is only similar to actual $|x\rangle$. Does ratios of elements in your "HHL solution" corespond to ratios in the expected solution? If so, you obtained correct results. Jan 4 at 21:44

You should compare the normalised classical solution to the normalised solution vector you compute from the Statevector. If the solution is still wrong it might be that you are using the wrong ordering of qubits, so maybe you have to take the reverse order with respect to what you were doing, i.e. $$|0000000000001\rangle$$ to $$|1111100000001\rangle$$