DEV Community

Cover image for Getting Started with Machine Learning: The Quantum Edition
Fortune Adekogbe
Fortune Adekogbe

Posted on

Getting Started with Machine Learning: The Quantum Edition

We all want to automate the repetitive stuff and to take that to the next level, we need 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

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

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

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. 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, support vector machines and kernel methods, quantum reinforcement learning, quantum convolutional neural networks 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 (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 provides a cloud-based environment for carrying out quantum computing. It consists of the quantum composer a tool that enables you to build quantum circuits via a graphical interface, access quantum services like systems and simulators as well as a quantum lab. In the quantum lab, you can (without download or installation) program quantum circuits and take advantage of other functions of Qiskit (an open-source package for programming on quantum hardware or simulators).

IBM Quantum computer

Qiskit is described 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 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

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 for use on quantum hardware after which use will require a charge.

TensorFlow Quantum (TFQ)

TensorFlow 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 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

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.


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.‌‌

Top comments (7)

vicradon profile image
Osinachi Chukwujama

Checkout this game from IBM called Hello Quantum. It gives you hands on experience with interacting with Superposition and Entanglement.

plainsight16 profile image
Timilehin Bakare

This was a fantastic read 👏

enutrof profile image
Fortune Adekogbe


vicradon profile image
Osinachi Chukwujama

I have a basic idea of Machine Learning and Quantum Computing, but couldn't grasp how they come together. Could you go into more detail into how they integrate with each other?

enutrof profile image
Fortune Adekogbe • Edited

Most existing systems are built on and within the paradigm of classical computers. This includes Machine Learning as is popularly known. So models from the linear regressor to attention based models are built to process data on a system that works with regular (classical) bits.

Since we began exploring quantum computing, we created qubits and as such we needed a new processor (hence all the research that has been and is being done). This processor takes us a step away from the generalisation that we made with the regular bits (0 or 1).
However, this also means that systems built to take advantage of the classical bit have to be "corrected" to utilize the qubit.

So, data storage as we know it can now be optimized using qubits to store way more information in the new unit called the qubit. Machine learning as you may know involves the use and processing of large amounts of data so this is a plus. The model’s operation is optimized by the more efficient processing.

Still about processing, with qubits, information transfer is exponentially faster (refer to the Quantum Entanglement section). This means that the machine learning workflow as we know it becomes more efficient as we can process more in less time.

The fundamentals behind different algorithms will probably not change much but how they are implemented (to take advantage of this upgrade in the processor) will change. And new ones with no classical history will be created.

pleasant_balogun_b07d57f5 profile image
Pleasant Balogun

You the GOAT fam

enutrof profile image
Fortune Adekogbe

Thanks man.