Getting Started with Machine Learning: The Quantum Edition
Tags: machinelearning, quantumcomputing, beginners
Published: 2022-03-18 10:34:14

We all want to automate the repetitive stuff and to take that to the next level, we need [machine learning](https://www.oracle.com/ng/data-science/machine-learning/what-is-machine-learning/). The legend says that if you have enough data, sufficient compute resources and a proficient engineer, you can build applications that perform repetitive tasks with a speed and accuracy that matches and sometimes exceeds the capabilities of the average human. Data here ranges from what you have in your excel sheets to text, images, audio and videos. So whether the goal is predicting a quantity like the price of housing, identifying objects in an image or recommending movies to you, machine learning is here to save the day.

In this article, you will learn about machine learning systems, quantum computing, how quantum computing helps machine learning and tools that are available to help you get started with quantum machine learning.

## **Quantum Computing**

To understand the quantum aspect, we will take a brief detour into the realm of Physics (stay with me). Quantum means small and as such, quantum mechanics refers to the study of small particles like atoms and electrons. Scientists studying these particles in the 20th century realized that most of the rules that govern larger bodies (classical mechanics) break down on such a small scale. This means that these rules were indeed approximations that seemed to work objectively since we hadn’t encountered this edge case. Two important phenomena that would help understand this quantum business are quantum superposition and entanglement.


### **Quantum Superposition**

You are currently looking at an electronic device (don’t look away) and are probably 100% sure about what it is (a phone, laptop or any other device). Would you believe me if I said that your observation is wrong? Well, quantum superposition tells us that before fixing our attention on any aspect of reality, said aspect exists as a combination of infinite possible states. With the introduction of human perception via our senses, a particular state is fixed and that is what we experience.

![Quantum meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9kue0u1a015zcu3e9sx.jpeg)

Similarly, we are initially made to believe that machines fundamentally interact with bits that are either 0s or 1s as most machines are built based on this assumption. However, it turns out that before observation, these bits exist in a state where all possible values from 0 through infinite decimals to 1 are superimposed. Now isn’t that interesting? ‌‌‌‌Working off this, the qubit (quantum bit) was introduced and it is essentially a bit that is both 0 and 1 simultaneously. This simplifies the scenario of an infinite number states as we can’t possibly tackle that straight up.


### **Quantum Entanglement**

Now, imagine that you passed a random stranger and by chance brushed shoulders with them, apologize and move on. However, upon reaching your destination, you find out that you can precisely determine their location, name and internet passwords. Wouldn’t that be strange? Well, that is what quantum entanglement is all about.

![Umbrella academy meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtcmccyv5nk9s7hokwdh.jpeg)

Two quantum particles that somehow end up interacting with each other end up being aware of their properties regardless of how far apart they are. Einstein called this “spooky action at a distance” and to be honest, I agree. Since entangled qubits know each other and one qubit can be entangled with multiple other qubits, this speeds up information processing exponentially.

## **Quantum Computing in Machine Learning**

The typical machine learning process up to building a model on a high level involves:

* Gathering data from all relevant sources
* Labelling this data and confirming these labels (validation)
* Transforming the data into a form that helps the model understand it
* Building possible candidate models based on various approaches and selecting the best based on a test.

![Machine learning flow diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dstdislekllk84eesqwh.jpg "The Machine Learning Process. Credit: Machine World (Blogspot)")

Quantum machine learning works by making the data processing and/or model building stages quantum-based. If both are not quantum then we have a regular classical machine learning setup. Also, if the input data is loaded and preprocessed as a quantum state or the model is quantum-based, then we have a hybrid quantum-classical system. Finally, if both are quantum (data and modelling algorithm), we have a full-blown quantum-based machine learning system.

These quantum machine learning models are the result of either the conversion of classical models into a quantum version or the development of quantum models from scratch.


### **What quantum computing brings to the table**

As you would now agree, quantum machine learning has the potential to reduce the[ time it takes a system to learn](https://research.ibm.com/blog/quantum-kernels). Also, training on a quantum computer would mean that more data can be processed quickly by taking advantage of the range of available states. Finally, the accuracy of the resulting systems even for reasonably complicated problems increases even when the same quantity of data is used.

Quantum advantages have been seen when applied to algorithms like[ principal component analysis](https://arxiv.org/abs/1904.05803),[ support vector machines and kernel methods](https://qiskit.org/documentation/stable/0.24/tutorials/machine_learning/01_qsvm_classification.html),[ quantum reinforcement learning](https://arxiv.org/abs/2103.15084),[ quantum convolutional neural networks](https://www.nature.com/articles/s41567-019-0648-8) and so on.

## **Getting into the thick of things**

Though quantum computers are still under active development with IBM recently creating the[ first quantum processor with 127 quantum bits](https://research.ibm.com/blog/127-qubit-quantum-processor-eagle) (qubits), enthusiasts and independent researchers are not left out. There are libraries and environments built so that we can utilize quantum computing hardware and simulated environments. Some of these will be discussed below.


### **IBM Quantum**

[IBM Quantum](https://www.ibm.com/quantum-computing/) provides a cloud-based environment for carrying out quantum computing. It consists of the[ quantum composer](https://quantum-computing.ibm.com/composer/docs/iqx/) a tool that enables you to build quantum circuits via a graphical interface, access [quantum services](https://quantum-computing.ibm.com/docs/services/#services-overview) like systems and simulators as well as a [quantum lab](https://quantum-computing.ibm.com/lab). In the quantum lab, you can (without download or installation) program quantum circuits and take advantage of other functions of[ Qiskit](https://qiskit.org/) (an open-source package for programming on quantum hardware or simulators).

![IBM Quantum computer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/apgaknefk77w59hewmqt.jpg "The innards of an IBM quantum computer. Credit: IBM")

Qiskit is[ described](https://qiskit.org/overview) as the most feature-rich, popular and open quantum computing SDK. The SDK is in Python and has modules for solving problems in machine learning, nature (chemistry), finance and optimization. For machine learning specifically, it can be used to implement quantum support vector machines, quantum generative adversarial networks and variational quantum classifiers. It also has sub-modules for implementing other forms of quantum neural networks, and even a Pytorch runtime for hybrid quantum-classical machine learning. It's quite the package.‌‌

### **Azure Quantum**

[Azure Quantum](https://azure.microsoft.com/en-us/services/quantum/) is a Microsoft provided cloud service that lets you write quantum programs and use quantum computing in production. They introduce the Quantum Development Kit (QDK) in a programming language called Q# which works with Python and C#. The Quantum Development Kit has libraries for solving problems in chemistry, numerics and machine learning.

![Azure quantum homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92xff69nnxa2pqz9ao7e.png "Azure Quantum Homepage")

Focusing on machine learning, with Q#, model architectures are instantiated and then with Python, these models can be imported and data can be parsed in for training. A little weird, I know but it works. The most interesting bit of this arrangement is how scripts in Q# can be made to directly interact with Python scripts using namespaces.

With Q# and the quantum development kit, applications can be created and connected to host programs that are written either in Python or a .NET language. Microsoft offers $10,000[ in free credits](https://microsoft.qualtrics.com/jfe/form/SV_3fl9dfFrkC3g0aG?aq_source=organic) for use on quantum hardware after which use will require a charge.


### **TensorFlow Quantum (TFQ)**

[TensorFlow Quantum](https://www.tensorflow.org/quantum) (TFQ) is a library for quantum machines created by Google to promote the development of hybrid quantum-classical ML models. Google also created[ Cirq](https://quantumai.google/cirq) an open-source quantum computing library written in Python. These libraries enable you to load data in a quantum state and build models (classical or quantum). ‌‌

![TensorFlow Quantum CNN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fnrendbbp5zqxkyg3lx.png "TensorFlow Quantum Convolutional Neural Network. Credit: TensorFlow")

Also, with TF Quantum, you can learn to build quantum convolutional neural networks, quantum reinforcement learning systems and so on. You can also create hybrid systems where quantum data is used with classical models of any kind.

---

### Conclusion
In this article, you learnt about machine learning systems, quantum computing, how quantum computing helps machine learning and tools that are available to help you get started with quantum machine learning.

Generally, hybrid quantum-classical ML models seem to be able to achieve better results when compared to quantum models. With the development of better quantum processors and algorithms through active research, quantum-based machine learning systems are expected to outdo current systems and speed up computation as is already done in other fields. I hope you enjoy exploring the world of quantum machine learning.

_All puns were intended._‌‌