QML
By: Nicholas Teague
Tags: Quantum Machine Learning, Quantum Computing, Machine Learning

Took a week off from working on the preprocessing library to play a little catch up in another interesting domain, one occurring at the intersection of quantum computing and machine learning aka quantum machine learning — a topic this blog has explored previously such as in our 2018 presentation on the same subject.

This sidetrack manifested primarily as a deep dive into the TensorFlow Quantum library, sort of an extension from the well known TensorFlow library for training neural networks. The progress made in the field since that 2018 presentation has been considerable, with nearly every nook of machine learning now finding some theoretic claim staked within QML. Interestingly, this progression of QML has sort of followed in a similar trajectory as the path first trodden decades ago with classical machine learning, as the early branches to establish beachheads were applications like clustering algorithms, kernel methods, principle components, things like that. A common similarity between these methods were the use of quantum algorithms that could speed up linear algebra operations, such as the calculation of eigenvalues, using quantum algorithms like HHL or QSVT. Other applications could make use of quantum optimization algorithms like QAOA. Of course while these speedups were demonstrated in theory, their potential in practice has been somewhat constrained under the reality of current generations of gate based quantum computing hardware, which are still in the NISQ (noisy intermediate scale quantum) era lacking sufficient noise tolerance to reach scale for fault tolerance enabling error correction.

The TensorFlow Quantum library circumvents this problem by applying NISQ-compatible QML frameworks that more closely approach modern paradigms of deep learning, albeit those similarities are not direct analogs as the networks built on top of quantum computing circuits have some fundamental distinctions in their implementations in comparison to neural networks. This essay will walk through the foundations of the library by way of discussions surrounding the origin paper: “TensorFlow Quantum: A Software Framework for Quantum Machine Learning” by Michael Broughton et al. In fact one way to think about this essay is as a companion for the paper, drawing discussions based on my review of the paper and supporting tutorial notebooks.

As a quick disclaimer, it’s worth noting that the benefits of quantum neural networks are not necessarily universal in comparison to classical machine learning. In fact, one of the key findings demonstrated in these tutorials was that quantum neural networks are primarily of benefit in application towards data sets incorporating elements of quantum information, such as would be found for example in simulated atomic systems or as may be registered with a quantum sensor etc. Otherwise classical networks are as a rule expected to train models either quicker or with better performance metrics. (Quantum information differs from classical information due to the use of complex numbers as well as the constraints imposed on matrix elements such as to ensure probability of measurements sum to unity etc.) So yeah, a time and a place for quantum, for now that time is primarily for niche applications.

So what does it mean to implement a neural network on quantum hardware? Well first we’re going to have to throw out all of our preconceptions of what constitutes a neural network, which would traditionally include fundamental elements such as layered aggregations of neurons populated with weights and activation functions. In our quantum neural networks we’ll be feeding our input data embedded into quantum bits, aka qubits, and so any operations applied onto that form will need to be conducted by aggregations of quantum gates applied sequentially to and between those qubits through the progression of time steps. With each of these gate operations, we’ll be rotating the superposition state around an axis of those qubits’ “Bloch spheres”.

Broadly speaking, quantum algorithms are means to craft by such gate rotations a shaped superposition of collective qubit states such that the probabilistic measurement operations on the returned qubit states are more likely to collapse to classical states corresponding to some desired output. Where for example in the context of our quantum neural networks, the desired output state may correspond to the labels of a supervised training operation.

So if we’re not using layered neurons of weights and activation functions, how can this be considered a neural network? Well the answer is that for our qubit states, the corollary to neural network weights will be parameterized gate applications, where these parameters control the magnitude or direction of Bloch sphere rotations. Of course not all of our gates need be parameterized, these could be interspersed with single and multi-qubit gate interlinks serving as scaffolding for conditional interactions between nodes. This leads to a big distinction between quantum and classical neural networks, the use of densely connected layers, where in classical networks it is common for all nodes in a layer to each be connected to all nodes in a preceding layer, in our quantum networks we are more constrained to the depth of gate applications on NISQ hardware, and so it may be that each layer of gates only interacts with adjacent qubits instead of all to all. This reduced information flow is compensated by the depth of information capacity of multi-qubit superpositions.

The realized gated network can then be given a form of supervised training to fit the parameterized gate sets to result in a returned superposition more aligned with our target state as a function of inputs. However we may find that these parameterized gates on their own are insufficient to fully capture the breadth of transformation function representations, especially considering the necessity of overcoming noisy hardware. The architectures considered in the TensorFlow Quantum paper address this by integrating classical networks commixed with the parameterized gates, in what they refer to as hybrid quantum classical neural networks (HQCNN).

The paper demonstrates how classical neural networks can be integrated in a variety of fashions. For instance, the output statistics from measurement operations can be fed into a classical network to translate those states to a consolidated prediction. As another example, the parameters of the gates could themselves be derived as a function of a classic neural network, in fact the interplay between quantum and classic network channels could become quite elaborate, such as with alternating layer types between quantum and classical or other structured flows.

To anyone with knowledge of how classic neural networks are trained by backpropagation, it may be surprising that this kind of wholly different form of parameterization could be integrated into a training loop. As intuition would suggest, the chain rule of backpropagation doesn’t directly translate to quantum primitives. However, there is a very clean solution realized by the simple modularity inherent in the networks. In other words, if in a forward pass the returned measurements from a quantum network are fed as input to a classical network, then in the backward pass we can simply apply the returned gradients from the classical network as input to the gradient calculations of the quantum network. Modular.

When it comes time to calculate gradients for parameters of a quantum layer, it turns out that there is no single perfect solution to be applied universally as is the case with backpropagation for classical neural networks. While some variations on gradient descent are available for use, they may be inadequate for some gate configurations due to inadequate gradient signal, a concept referred to as “barren plateaus” — sort of like the QNN equivalent to the vanishing gradient problem in recurrent networks although that is just a loose analogy, here it is more a product of exponential dimensionality. In fact in addition to means of address like certain structures of gate configurations and initializations, the library even has a form of variational gradient calculations that have built in gate clipping to pare down dimensionality when barren plateaus surface. From what I gather this is more of an issue with randomized gate configurations (like those random configurations applied in Google’s recent demonstration of quantum supremacy).