VQLS with non-trivial |b>

Good evening,

I am using a modified version of the sample Penny Lane VQLS code in order to solve a system of PDE’s. In this case the state |b> will not be U = H1H2H3. I have been able to represent |b> as the result of a sum unitaries, with scalar coefficients. Similar to decomposing the A operator (matrix) in A|x>=|b>. While I can see how to modify the sample code to add each of the gates for U, I am not sure how to apply the coefficients for summing here. Would these be rotations prior (or after?) to applying the CNOT, CY, CX?


Thank you very much for any help/advice

Hi @Dan_Velez and welcome to the Xanadu forum.

It seems like you want to create an operation U that is the sum of a set of operations (e.g. something like 0.5*RY*CNOT + 1.3*RY*CY + ...), and you’re wondering how to add the coefficients (0.5, 1.3, etc. above)? Is this correct?

I’m not sure how that could be done. I think that this might be easiest approached by attempting to create the cost function, as they do in the tutorial, adding the coefficients later after having calculated the necessary expectation values. This is what seems to be done in the tutorial, in the cost_loc() function, when they add the coefficients for A_i after getting the expectation values returned from local_hadamard_test().

Let me know if I understood your question correctly, or if I can clarify anything else.

Thank you. You understood the question perfectly. I have been playing with the idea of trying to implement an amplitude to the calling of U to prepare |b>, but I don’t think this works with the template cost function.

And I think you are correct that I need to go back to basics to see how the derivation of the cost function can be modified to a more complex U. In most “tutorial” cases of VQLS, |b> usually has equal elements.

This seems to work now

1 Like

Hi @Dan_Velez,

Thank you very much for the update. We are glad to know your model seems to be working now. Let us know if there’s anything else we can help with.


Thanks. I believe there is a factor of 2 in the second term from the internal sum, which cancels the 2 in 1/(2n), but the basic form here should be correct

Thanks for sharing @Dan_Velez!

slight correction to formula… no d’s (or u’s) in the denominator (PSI norm)

1 Like

Hi @Dan_Velez , could you please reshare the way you find out those gates and coefficients for the b vector? I found a way to do it for normalized vector in Qiskit but still struggling to find a way in Pennylane. Could you provide the approach or methods you used to find it here?

Hi @sajal, was your answer to this thread what you needed to answer this question too? Or is this a different question?