# Quantum algorithm for linear system of equations (HHL) - Final Step: How can I find my vector of solution $|x\rangle$?

I'm working on solving a linear system with the quantum algorithm HHL. I don't understand how I can recover my vector $$|x\rangle$$ of real solution of the system starting from the states measured with ancilla qubit in $$|1\rangle$$. I found something about using tomography but I don't know how to apply it successfully to my circuit with Qiskit.

Can someone help me? Many thanks.

Quick answer: You will not be able to fully recover $$x$$.

Explanations:

1. By design, the HHL algorithm stores $$x$$ in the amplitudes of a quantum state. Because of how quantum mechanics works, the vector representing the quantum state (i.e. containing all the amplitudes of the quantum state) needs to be of unit-norm (according to the Euclidean norm). Because of this, the result stored in the amplitudes of your quantum state is (most of the time) not $$\vec{x}$$ but rather $$\vert x \rangle = \frac{\vec{x}}{\vert\vert\vec{x}\vert\vert}$$. Also because quantum states are defined up to a global-phase, the most general expression of the "solution" of the linear system stored in the amplitudes is $$\vert x \rangle = e^{i\phi}\frac{\vec{x}}{\vert\vert\vec{x}\vert\vert}.$$

2. As said in point 1, the HHL algorithm stores the result of the linear system provided by the user in the amplitudes of a quantum state. The problem is that these amplitudes are not directly measurable. You can measure the value of your qubits and the measured value will depend (probabilistically) on the underlying amplitudes, but you can't measure the amplitudes.

One way to approximate the amplitudes (up to a global phase) is to use quantum state tomography. Here are some links related to quantum state tomography in Qiskit:

• Presumably the biggest issue is that to perform tomography on the state in an attempt to recover $x$ (subject to the caveats you mention) is efficiency? Is it not the case that you need to repeat the whole thing enough times that you'd have been better performing the classical calculation? – DaftWullie Mar 5 at 12:41
• I never used tomography but from what I read you are right: if you want to recover a good approximation of the whole state you will need to repeat your algorithm+measurements an exponential number of times, which would defeat the whole purpose of HHL (and of all the quantum algorithm I know). – Nelimee Mar 5 at 12:42
• Yes, I also think that the only possibility we have to make an estimation of x is by tomography operation, but we lose all the advantage of quantum computation... So I ask you guys, how can I interpret the probability results on ancilla qubit of my algorithm in connection to the problem I'm try to solving? – Nicolò Cangini Mar 5 at 13:41
• I would say this is 100% problem-dependent. It depends on what is your problem, what kind of information you will need to solve your problem and what information you will be able to extract from the quantum state. This would be a whole question on its own, only describing your problem might be quite long. If you want to investigate on your own you can try to understand the theory behind quantum measurement (en.wikipedia.org/wiki/Measurement_in_quantum_mechanics). I will not be able to help you more on this topic, I also need to improve my understanding of measurement. – Nelimee Mar 6 at 14:00