What's it all about?
At @pennylaneai, we've been developing QML software and algorithms for a couple years now. Since there is now growing interest, we want give a VIP guided tour of the current landscape of QML. [THREAD]
-Quantum circuits are differentiable programs
-Quantum circuits can be trained by gradient descent with the parameter-shift rule
-Quantum circuits can be nodes in differentiable hybrid computations
The trick here is to *use the quantum circuit itself* to compute the gradient.
This rule is easy to describe, but magical at first sight. In fact, there's no deep magic—unless you consider trigonometry magic 🧙
The answer is a simple recipe:
-Shift u forward by an extra pi/2 and evaluate that circuit
-Shift u backwards by pi/2 and evaluate
-Take the linear combination [C(u+pi/2) - C(u-pi/2)]/2
The resulting value is exactly equal to dC/du!
Here's a simple analogy:
The derivative of sin(u) is cos(u) = sin(u+pi/2).
If we have a device that evaluates the "sin" function, we can find its derivative at any point, using that same device, by simply shifting the argument.
The parameter-shift rule is basically the identity cos(u) = [sin(u+pi/2) - sin(u-pi/2)]/2.
So we need to evaluate the device twice to compute the derivative with respect to u.
Fortunately, this step is embarassingly parallelizable. If we had access to many QPUs, we could compute all the gradient elements at the same time. 😁
Fortunately, the devs of these libraries were forward-thinking (though maybe they didn't originally anticipate connecting to quantum computers!). They provide a way to define custom functions.
With these two pieces, PyTorch now knows how to train quantum circuits or hybrid quantum-classical models, just like it would train a neural network.
In a nutshell, those ideas are the basis of modern QML libraries like pennylane.ai or TensorFlow Quantum. It's also the basis for the "Qiskit & PyTorch integration" you may have seen from an @qiskit hackathon project last year.
"The TensorFlow of Quantum Computing"
If you enjoy it, consider following or starring our GitHub repos: github.com/XanaduAI/penny…, github.com/XanaduAI/qml
Stay tuned!
