QN-SPSA for hybrid models

Hi,

I am working on developing a VQC-based quantum PINN for solving diffusion problems.

In my model, the role of the quantum circuit is to predict a value u, which is then used as part of a classical loss function. I am using the expectation value of a PauliZ observable as the output of the circuit, and integrate it via a TorchLayer.

I have tried optimizing my model via ADAM and LBFGS, but I think it keeps running into barren plateaus and gets stuck in local minima. I wanted to try to incorporate QN-SPSA for optimization to see if it improves my results, however, I am not sure how to do this, since the documentation ( qml.QNSPSAOptimizer — PennyLane 0.41.1 documentation) only mentions using the output of a qnode as the loss function.

I am not sure if my question is ill-posed and using a QN-SPSA (or QNGD) is even possible with a classical loss function.

I would greatly appreciate any help on this!

Thank you,
Klim

Hi @Klim
Welcome to the forum!
Unfortunately, we experienced a high volume of questions at the end of the day today and I couldn’t get to this one on time.
I will try to help you next week since I am off tomorrow.

Thanks for understanding.

Hi!
I will ask around about the QNSPSA optimizer. But it seems to be the case that it is designed to be used with a qnode as the loss function, see this demo for reference and more information.
Could the qml.SPSAOptimizer be useful in your situation?

Thanks for your question.

Hi Daniela,

I would really appreciate if you could ask around, thank you!

I haven’t used simple SPSA, as I wanted to try to incorporate quantum gradients somehow, but thank you for the suggestion.

Hi, just to confirm our initial suspicion. Yes, qml.SPSAOptimizer is designed to be used with the output of a QNode as the loss function.
You could try other things, but it is not intended to work with anything else apart from a QNode output.

Thanks for your question!