PennyLaneAI / qml

Introductions to key concepts in quantum programming, as well as tutorials and implementations from cutting-edge quantum computing research.
https://pennylane.ai/qml
Apache License 2.0
522 stars 184 forks source link

Correction in the "QSVT in Practice" demo #910

Closed jezerjojo14 closed 11 months ago

jezerjojo14 commented 11 months ago

https://pennylane.ai/qml/demos/tutorial_apply_qsvt

In the above tutorial, we have a QSVT circuit U which is a block encoding of some singular value transform of A, f(A). The tutorial claims that (1/2)(U+adjoint(U)) will block encode the real part of f(A). And the function real_u constructs a circuit that realizes this matrix with the help of an ancilla qubit.

This however only works when A is Hermitian, which it is in the example that the tutorial then uses. But it is not true generally.

What should work instead is (1/2)(U1 + adjoint(U2)) where U1 is a QSVT circuit block encoding f(A) and U2 is a QSVT circuit block encoding f(adjoint(A)).

The function real_u can be slightly modified by replacing A with its transpose when applying the adjoint circuit.

def real_u(A, phi):
    qml.Hadamard(wires="ancilla1")
    qml.ctrl(sum_even_odd_circ, control=("ancilla1",), control_values=(0,))(A, phi, "ancilla2", [0, 1, 2])
    qml.ctrl(qml.adjoint(sum_even_odd_circ), control=("ancilla1",), control_values=(1,))(A.T, phi, "ancilla2", [0, 1, 2])
    qml.Hadamard(wires="ancilla1")
Jaybsoni commented 11 months ago

Hi @jezerjojo14,

Nice catch! You are indeed correct, the expression provided only works when A is symmetric. We will open up a PR to make this amendment right away.

Cheers,

jezerjojo14 commented 11 months ago

Apologies, but if my understanding of QSVT is correct, I now realise that even-polynomial circuits also only work as singular value transformations when the matrix is non-Hermitian (edit: I meant Hermitian). If you change the tutorial to work for general matrices I think you'll also have to restrict it to odd polynomials. Either that or I suppose you can leave the tutorial the way it is and mention that it only works for Hermitian matrices. In that case it can maybe be mentioned that any linear system of equations can be solved by inverting a Hermitian matrix (there's that trick the original HHL algorithm used to create a Hermitian matrix from any non-Hermitian matrix).

Jaybsoni commented 11 months ago

Hey @jezerjojo14,

Thanks for the clarification. We will need a little bit of time to look into this claim and verify that statement. If true, we can update the demo to reflect it. In the meantime, could you elaborate on how even-polynomial circuits don't work for hermitian matrices?

We will get back to you soon with an updated. Cheers,

jezerjojo14 commented 11 months ago

A matrix A takes its right singular vector v_i to its corresponding left singular vector u_i scaled up by the corresponding singular value sigma_i.

We want a matrix f(A) that takes its right singular vector v_i to its corresponding left singular vector u_i scaled up by f(sigma_i).

It is my understanding that the QSVT circuits for even polynomials don't take right singular vectors to the corresponding left singular vectors like they do for odd polynomials. Instead they take their right singular vector v_i and scale it up to f(sigma_i)*v_i.

In the paper "Grand Unification of Quantum Algorithms", theorem 4 defines the QSVT. Equation 47 shows how it's defined for even polynomials and we see that u_k is not in the equation.

CatalinaAlbornoz commented 11 months ago

Hi @jezerjojo14, thank you for your comment. We will get back to you shortly.

CatalinaAlbornoz commented 11 months ago

Hi @jezerjojo14, the PennyLane team has been working on fixing the demo. I'll let you know once it's fixed. Thank you once again for pointing out the correction!

Jaybsoni commented 11 months ago

Hey @jezerjojo14,

Ah I see, because of the extra projector, we end up in the wrong subspace after applying the QSVT subroutine for even transformations. The two spaces only match when our operator's left and right singular vector spaces coincide, which happens for hermitian operators. This clears things up!

We have updated the demo to specify this assumption! As you mentioned, one could generalize this approach by simply forgoing the even polynomial and using a strict odd polynomial approximation. Thanks for the feedback!

Cheers,

KetpuntoG commented 11 months ago

Thanks @jezerjojo14 for opening the issue and @Jaybsoni for working on it 🚀