TensorFlow Quantum: an open-source library for the rapid prototyping of Quantum Machine Learning

Junaid S. Shaikh
4 min readMar 30, 2020

--

Over the past few years, classical ML model and promise in tackling challenging scientific issues, leading to advancement in image processing for cancer detection, predicting extreme patterns and many more. The recent progress development of quantum computing, the development of new Quantum ML models could have a profound impact on the world’s biggest problem, leading to breakthroughs in the area of medicine, sensing, material, and communication.

TensorFlow Quantum (TFQ)

Despite the multiple breakthroughs in multiple areas, there has been a lack of research tools to discover Quantum ML models that can process quantum data and execute Quantum computers available today.

Google has released ‘TensorFlow Quantum (TFQ)’ an open-source library for the rapid prototyping of Quantum ML models. TFQ provides the tools necessary for bringing quantum computing and ML research communities together to control and model natural or artificial quantum systems.

What is a Quantum ML model?

A Quantum ML model has the ability to represent and generalize data with a quantum mechanical origin. To understand quantum models, two concepts must be known — quantum data and hybrid-quantum classical models.

Quantum data shows superposition and entanglement, leading to the joint probability distribution that could require an exponential amount of classical computational resources to represents or store. Quantum data, which can be simulated on quantum processors/sensors/networks include quantum matter, quantum control, quantum communication networks, quantum metrology, and much more.

Quantum data generated by NISQ processors that are fairly small and noisy. By applying Quantum ML to noisy entangled data can maximize the extraction of useful classical information.

Hybrid-quantum classical models, Quantum models cannot use quantum processors alone — the NISQ processor will need to work with classical processors to become effective. As TensorFlow already supports heterogeneous computing across CPUs, GPUs, TPUs, it is a natural platform for experimenting with hybrid-quantum classical models.

TFQ integrates Cirq with TensorFlow and provides a high-level abstraction for the design and implementation of both discriminative and generative quantum computing primitives compatible with existing TensorFlow APIs, along with high-performance quantum circuit simulators.

TensorFlow Quantum used for hybrid quantum-classical convolutional neural networks, machine learning for quantum control, layer-wise learning for quantum neural networks, quantum dynamics learning, generative modeling of mixed quantum states, and learning to learn with quantum neural networks via classical recurrent neural networks.

How does TensorFlow Quantum work?

TFQ allows researchers to construct quantum datasets and classical control parameters as a tensor in a single computational graph. Tracing can be done using standard Keras functions.

To provide some insight on how to use quantum data, one may consider a supervised classification of quantum states using a quantum neural network. A key challenge of quantum ML is to classify ‘noisy data’.

To build and train such a model, do the following steps.

  1. Prepare quantum dataset — Quantum data is stored as tensors (a multi-dimensional array of numbers). Each quantum data tensor is defined as a quantum circuit written in Cirq that produces quantum data on the fly. The tensor is executed by TensorFlow on the quantum computer to produce a quantum dataset.
  2. Evaluate a quantum neural network model — The Parameterized quantum models can be chosen from several broad categories based on knowledge of the quantum data’s structure. The goal of the model is to perform quantum processing in order to extract information hidden in a typically entangled state. The quantum model essentially untwists the input quantum data, leaving the hidden information encoded in classical correlations, thus making it accessible to local measurements and classical post-processing.
  3. Sample or Average — The distribution of values from this random variable generally depends on the quantum state itself and on the measured observable. As many variational algorithms depend on mean values of measurements, also known as expectation values, TFQ provides methods for averaging over several runs involving steps (1) and (2).
  4. Evaluate a classical neural network model — Once correct information has been extracted, it is in a format manageable to further classical post-processing. The extracted information may still be encoded in classical correlations between measured expectations, classical deep neural networks can be applied to extract such correlations.
  5. Evaluate the cost function — Given The results of classical post-processing, a cost function is evaluated. This could be based on how precisely the model performs the classification task if the quantum data was labeled, or other measures if the task is unsupervised.
  6. Evaluate Gradients and update parameters — After evaluating the cost function, the free parameters in the pipeline should be updated in a direction expected to decrease the cost. This is most commonly performed via gradient descent.
Overview of the computational steps involved in the hybrid quantum-classical discriminative model for quantum data in TFQ.

A key feature TFQ is the ability to simultaneously train and execute many quantum circuits, this is achieved by TensorFlow’s ability to parallelize computation across a cluster of computers and the ability to simulate relatively large quantum circuits on multi-core computers.

The TensorFlow Quantum is primarily geared towards executing quantum circuits on classical-quantum circuits simulators. In the future, TFQ will be able to execute quantum circuits on actual quantum processors that are supported by Cirq, including Google’s Sycamore processor.

--

--

Junaid S. Shaikh
Junaid S. Shaikh

Written by Junaid S. Shaikh

I am a passionate software developer, blogger, writer, and entrepreneur.

No responses yet