I am working on implementing a quantum-classical hybrid neural network in qiskit where input data is encoded on a quantum circuit (with say 3 qubits) using a ZZFeatureMap
, then we have parameterized quantum circuits given by TwoLocal
gates. Then the measurement is performed on the quantum circuit. The output state of the measurement from the quantum circuit goes to a classical neural network in the form of a bitstring (If the measured state is |001>, then the neural network has an input size of 3 and each node value is given by 0,0,1). After a few layers, we receive the output of the feedforward network and a loss is calculated. (Say mean-square error).
My question is: How do I backpropagate through the quantum circuit? Using Pytorch
, backprop through the classical neural network is trivial but not the quantum circuit. Is the only way to perform gradient descent through the quantum circuit by applying parameter-shift
rule to the quantum circuit, keeping all classical parameters constant? I have tried the TorchConnector
module in qiskit but that directly calculates expectation values of the quantum circuit which is not what I am looking for. This tutorial on hybrid-quantum-classical neural networks in qiskit might be a solution but again, I cannot think of a way to initialize weights of the parameterized unitaries as asked in this question.
Any help is greatly appreciated! Thanks!