2
$\begingroup$

Just read this paper from Xanadu on Quantum Transfer Learning and a couple of things are unclear to me regarding the optimisation step.

  1. How is back-propagation done through the classical weights feeding into the quantum unitaries?
  2. How do they even calculate cross-entropy loss without adding some sort of squashing function to the final output to give outputs in $[0,1]$ (my best guess is that the squashing function is implicit in the fact that you have to measure multiple times to get an expectation value).

PS: I know this might be overly-specific for SE but I suppose this is the best avenue short of writing the authors.

$\endgroup$
2
$\begingroup$

How is back-propagation done through the classical weights feeding into the quantum unitaries?

In this particular case, the gradient of the quantum variational circuit is computed using the parameter-shift rule. The parameter-shift rule allows us to compute the gradient by simply evaluating linear combinations of the variational circuit under study, so works with both quantum simulators and hardware.

For example, given a variational quantum circuit $U(\boldsymbol \theta)$ and some measured observable $\hat{B}$, the derivative of the expectation value

$$\langle \hat{B} \rangle (\boldsymbol\theta) = \langle 0 \mid U(\boldsymbol\theta)^\dagger \hat{B} U(\boldsymbol\theta) \mid 0\rangle$$

with respect to the input circuit parameters $\boldsymbol{\theta}$ is given by

$$\nabla_{\theta_i}\langle \hat{B} \rangle(\boldsymbol\theta) = \frac{1}{2} \left[ \langle \hat{B} \rangle\left(\boldsymbol\theta + \frac{\pi}{2}\hat{\mathbf{e}}_i\right) - \langle \hat{B} \rangle\left(\boldsymbol\theta - \frac{\pi}{2}\hat{\mathbf{e}}_i\right) \right].$$

Thus, the gradient of the expectation value can be calculated by evaluating the same variational quantum circuit, but with shifted parameter values.

To 'integrate' the quantum circuit into the larger classical ML model, we use PennyLane; which allows you to create an arbitrary hybrid classical-quantum ML model that supports backpropagation using either TensorFlow, PyTorch, or Autograd.

In this particular case, two good resources are:

  • Quantum transfer learning tutorial. This is a self contained tutorial that follows the general structure of the PyTorch transfer learning tutorial, with difference of using a quantum circuit to perform the final classification task.

  • The XanaduAI/quantum-transfer-learning GitHub repo, which contains the code for the numerical experiments in the paper.

How do they even calculate cross-entropy loss

In this case, since PennyLane lets us use PyTorch to drive the overall model, we simply use nn.CrossEntropyLoss() class provided by PyTorch.

References

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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