Re-normalization of the output of VQLS

Hello!

I am trying to implement VQLS to solve linear systems of equations of the form Ax=b.

I know that VQLS finds an |x\rangle such that A|x\rangle \propto |b\rangle.

I am using the code from Variational Quantum Linear Solver | PennyLane Demos, but I changed the vector b from the uniform superposition to an unormalized vector b = [1,3,4,2,0.3,2,3,6].

Consequently, the only thing that I changed is the U_b() function so that it uses amplitude encoding to encode this vector:

def U_b():
    """Unitary matrix rotating the ground state to the problem vector |b> = U_b |0>."""
    qml.AmplitudeEmbedding(features = vector, wires = range(n_qubits), normalize = True)

I also changed the Hadamard test function so that it calculates the adjoints of U_b() and CA():

def local_hadamard_test(weights, l=None, lp=None, j=None, part=None):

    # First Hadamard gate applied to the ancillary qubit.
    qml.Hadamard(wires=ancilla_idx)

    # For estimating the imaginary part of the coefficient "mu", we must add a "-i"
    # phase gate.
    if part == "Im" or part == "im":
        qml.PhaseShift(-np.pi / 2, wires=ancilla_idx)

    # Variational circuit generating a guess for the solution vector |x>
    variational_block(weights)

    # Controlled application of the unitary component A_l of the problem matrix A.
    CA(l)

    # Adjoint of the unitary U_b associated to the problem vector |b>.
    # In this specific example Adjoint(U_b) = U_b.
    qml.adjoint(U_b)()

    # Controlled Z operator at position j. If j = -1, apply the identity.
    if j != -1:
        qml.CZ(wires=[ancilla_idx, j])

    # Unitary U_b associated to the problem vector |b>.
    U_b()

    # Controlled application of Adjoint(A_lp).
    # In this specific example Adjoint(A_lp) = A_lp.
    qml.adjoint(CA)(lp)

    # Second Hadamard gate applied to the ancillary qubit.
    qml.Hadamard(wires=ancilla_idx)

    # Expectation value of Z for the ancillary qubit.
    return qml.expval(qml.PauliZ(wires=ancilla_idx))

I have two questions:
1 - Can my implementation correctly solve A|x\rangle \propto |b\rangle or am I missing some steps?
2 - How can I “find” x from the output of VQLS |x\rangle? In the sense, how can I find the true x of Ax=b given the output of the VQLS?

Thank you very much in advance!

Hey @rc17782, welcome to the forum! :raised_hands:

I think your method should work. This is how I justify it:

Let \vert b \rangle be your “wonky” state and let \vert + \rangle = H \vert 0...0 \rangle. Clearly, \vert b \rangle and \vert + \rangle are related by some unitary transformation: U \vert b \rangle = \vert + \rangle.

\begin{align*} A \vert x \rangle &= \vert + \rangle \\ \vert x \rangle &= A^{-1} \vert + \rangle \\ \vert x \rangle &= A^{-1} U \vert b \rangle \\ \vert x \rangle &= \tilde{A}^{-1} \vert b \rangle \\ \end{align*}

So the problem is basically the same but with a different A. Seems fine to me? But try our your idea and let me know if it works or not!