1
$\begingroup$

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!

$\endgroup$

2 Answers 2

0
$\begingroup$

I understand it is tricky to do HNN with qiskit because of the lack of examples and explanations in the qiskit textbook. I recommend applying CircuitQNN will be more flexible for HNN. This might help you:

  1. https://qiskit.org/documentation/machine-learning/tutorials/01_neural_networks.html#4.1-Output:-sparse-integer-probabilities
  2. https://qiita.com/DeepRecommend/items/7a28f2e96ef165a0ed1d#dense-parity-probabilities
$\endgroup$
5
  • $\begingroup$ Hi! I'm going through both the tutorials you recommended. I will go through the details of CircuitQNN and update if it solves the problem. Thank you! $\endgroup$ Commented Jun 27, 2022 at 6:49
  • $\begingroup$ @Ananth_Rao accept the answer if the problem been solved will help a lot, thank you. Welcome to ask more questions. Two local is like a quick apply for neurons, because it pre-set most of the things. $\endgroup$
    – poig
    Commented Jun 27, 2022 at 7:27
  • $\begingroup$ *two layer(not two local) $\endgroup$
    – poig
    Commented Jun 27, 2022 at 7:36
  • $\begingroup$ @Ananth_Rao for the torchConnector and CircuitQNN, look at this qiskit.org/documentation/machine-learning/tutorials/… $\endgroup$
    – poig
    Commented Jun 27, 2022 at 7:43
  • $\begingroup$ Can you help me understand what the output of the CircuitQNN correspond to (particularly the one with dense probabilities)? How are we constructing sparse probability outputs? I have asked the question here. Thanks! $\endgroup$ Commented Jun 27, 2022 at 10:10
0
$\begingroup$

Pennylane also provides PyTorch/TensorFlow plug-ins which enable back-propagation based optimizers. For instance, for PyTorch you can use TorchLayer. This might also be relevant for the Hybrid-Neural Network case, since you have both quantum and classical parameters.

Also, SPSA is another method that you can use, which does not rely on back-propagation, and is significantly faster than parameter-shift, as it creates a perturbation vector to shift all the parameters at once by random scales, so it only requires 2 circuit evaluations, whereas parameter-shift requires exponential number of executions w.r.t the number of parameters. I do not think you even have to "freeze" the classical parameters, and you can include both the parameters for the quantum gates and the classical processing units.

Last but not least, you can also prefer a "transfer learning" based approach, depending on the task you want to solve.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.