Getting started with Quantum Computing using Q# -Part 1

Madhur Dheer
TheTeamMavericks
Published in
16 min readApr 30, 2020
Magical power of Quantum Computing

In my time of 4 years in college, I have heard about Quantum computing a lot(mostly in movies). I always used to wonder whether Quantum computing has some applications or not? Whether Quantum Computing has some future scope or Is it going to be the next big thing in Industry? After a careful examination over several kinds of research done by Tech giants of the world, it made me realize that Quantum Computing as a lot of possibilities to explore and a lot of stones to be unturned.

This blog will be addressing what Quantum Computing is, What are the possible applications associated with it, Why companies find it worth investing. I will also be covering some topics to get yourself started with developing using Quantum Computing. I will be using Microsoft’s Quantum Development Kit(QDK) for development purposes. I will not use some complex mathematical equations to understand the Quantum phenomena rather I will use some real-time applications for better understanding. I will end this blog with the implementation of several Quantum Computing Phenomena and will provide necessary links to explore further.

Prerequisites

To understand Quantum computing, it is first important to analyze what was the reason behind the discovery of the same. Hence, it is first important to understand what classical computing is and what were its limitations which lead scientists and developers across the world thought to explore new methods of computing.

What is Classical Computing?

Figure 1. Classical computing explained using a simple light switch

The computers, laptops which we use in our daily lives follow a conventional method of computing known as Classical computing. Classical computing is often substituted as Binary computing. This means that it uses bits to store the information. A single bit logically can have only two states i.e. either 0(OFFstate) or 1(ON state). We can understand this behavior using the operation of a simple light switch mentioned in Figure 1. As you can see from the GIF, the light switch has only two state i.e. Either the switch can be ON or the switch can be OFF.

This conventional method of computing is the most popular method for solving the desired problem with the estimated time complexities. Algorithms of searching, sorting and many others are there to tackle daily life problems and are efficiently controlled over time and space with respect to different approaches. For example, Linear Search has a time complexity of O(n), Binary Search has O(nlog2n). These all give a boom to software industries and other IT sectors to work for the welfare of the world.

Limitations in the current method of computing

By the logic I mentioned above, we can conclude that computing power doubles as the number of bits increases. Thus to have a power of 18x we will be requiring 9bits of information. There are a lot of domains in the industry which require high computation power to solve their problems. This in terms of classical computing means that it requires more amount of bits to process the information. Thus, at high power computer like (128x or maybe 1024x) classical computing faces a lot of challenges like :

  1. Becomes to expensive
  2. The total amount of hardware to manage increases thus resulting in a high amount of maintenance
  3. It will also increase the operational cost

Thus scientists and developers across the world have to come up with a new approach of computing to resolve these limitations and provide an economically viable solution for faster computing required in several industrial applications. This lead to the discovery of Quantum Computing.

What is Quantum Computing?

Quantum computing is the use of quantum-mechanical phenomena. Computers that perform quantum computation are known as a quantum computers. Quantum computers can process massive and complex datasets more efficiently than classical computers. They use the fundamentals of quantum mechanics to speed up the process of solving complex computations.

Quantum computers could offer a huge efficiency advantage for solving certain types of computations that stump today’s computers — and would continue to stump them even if Moore’s Law were to carry on indefinitely.

For starters, think about a phone book, and then imagine you have a specific number to look up in that phone book. A classical computer will search each line of the phone book until it finds and returns the match. In theory, a quantum computer could search the entire phone book instantaneously, assessing each line simultaneously and returning the result much faster than a classical computer.

These problems, which require the best combination of variables and solutions, are often called optimization problems. They are some of the most complex problems in the world, with potentially game-changing benefits.

Applications of Quantum Computing

In industry, there are a lot of optimization problems that have a high number of variables/factors to consider. Quantum computing can help in this area to find optimal solutions faster with high accuracy and high precision. Some of these domains where Qunatums computing can benefit a lot are:-

  1. Construction Management

Imagine you are building the world’s tallest skyscraper, and you have a budget for the construction equipment, raw materials, and labor, as well as compliance requirements. The problem you need to solve is how to determine the optimum combination of equipment, materials, and labor, etc. to maximize your investment. Quantum computing could help factor in all these variables to help us most efficiently plan for massive projects.

2. Drug Simulation

In the medical industry, while finding a cure for any disease there are a lot of complex chemical equations involved. While developing a drug, simulation of these chemical equations are required to assess several factors before realizing out for human-phase testing. With a classical computer, these simulations may take months or even years. Quantum computing could help here to solve such complex multi-variate equations faster and could help to develop the drugs faster.

3. Financial Market

Business analytics and market trend predictions are considered to be one of the biggest domains in the world where huge amounts of investment are poured to achieve the predictions with better accuracy and at a faster amount of time. Quantum Computing can help here to achieve these future trends in the market with high accuracy and high precision.

Quantum computing can help a lot in risk assessment of the financial markets. Several large investment firms often carry out a risk assessment by taking several other unconventional parameters into the picture like an epidemic, floods, earthquake, etc. Quantum Computing can help to achieve these trends with high precision.

4. And much more …..

Optimization problems are faced across industries including software design, logistics, web search, genomics, and more. While the toughest optimization problems in these industries stump classical computers, they are well-suited for being solved on a quantum machine.

Qubits: A basic unit for processing information in a quantum computer

Figure 2. A dimmable switch to understand Qubit

Let us understand how dimmable switch works. A dimmable switch can be in more than two states i.e. It can be slightly ON(or slightly OFF). This suggests that a switch can have a state between ON and OFF. (Can be observed from Figure 2).

Based on this analogy Qubits was discovered. In mathematical terms, Qubits can be any value from 0 to 1 or have properties of both of these values simultaneously. Right away, there are a whole lot more possibilities for performing computations.

Qubits are the basic units for processing information in a quantum computer.

What makes Qubits better than Classical bits?

A comparison between Classical computer and Quantum counter on how the Computational power increase when the number of bits increase (left side — Classical computer, Right side — Quantum Computer)

As mentioned earlier, classical bits can help to improve the performance of computing 2x time with every addition of a bit. Thus if we require computational power of 128x we need around 64 bits.

In the case of quantum computing with every addition of the Qubit, computational power will increase exponentially. This means with fewer number Qubits we can achieve higher computational power. Thus the problem which is faced by classical computing will be resolved.

Getting started with Microsoft’s Quantum Development Kit

Getting Started with QDK

Microsoft has developed a service known as QDK or Quantum Development Kit to help the developers providing a platform to understand and simulate Quantum Computing associated phenomena and algorithms locally in our desktop. To work with QDK installation is Microsoft Visual Studio code is required. After that you can follow these guidelines to install the dependencies associated with QDK.

QDK has three major components to understand. These components are :

  1. Q#: It is the coding language developed from scratch by the Microsoft team to write algorithms related to Quantum Computing. The syntax is familiar to C#, if you have a background of C# it would be great but if you want to learn the basics you can follow this channel.
  2. Quantum Simulator: Quantum Simulator is a simulation system designed to run the codes locally on your desktop. The ability to process the number of Qubits by the Quantum simulator depends on how powerful your computer is (it can go as high as 15 and as low as 3).
  3. Extensive Docs, Sample Project: Usually the biggest problem associated with learning a new technology is finding enough documentations and implemented projects. Well as for the case of QDK Microsoft has provided extensive documentation, GitHub links of several projects so that the developer can utilize it to learn faster and better.

We will the using Microsoft’s QDK to analyze three basic Quantum Phenomena, these are :

  1. Superposition
  2. Entanglement
  3. Teleportation

Before jumping ahead and start writing codes let us first understand briefly what these phenomena mean.

I won’t be showing complex mathematical equations associated with each phenomenon, rather I will use real-time scenarios to get your understanding of the mentioned phenomena better.

Understanding of Superposition Principle

Recall the previous example of dimmer light used to explain what a Qubit is. A Qubit can have state 0 or 1 or it can be both. This both states of the Qubit is what Superposition is all about.

Real-World Example

Figure 3. A Sample Sound Wave

Let us take sound waves as an example to understand the Superposition principle. A sound wave, which we hear all the time is the composition of multiple sounds waves.

A single sound wave that we hear can comprise two or more than two sounds wave to create the voice we hear. These sound waves together can either create constructive interference or destructive interference. But till the time we haven’t measured it we cannot say which type of interference has occurred. Thus we can state that the given sound wave is a superposition state. This is what the superposition principle is all about.

In scientific terms, it states that xof an object which until not measured can be considered at a superposition state.

What makes Superposition principle so important in the Quantum World?

You may wonder why this principle is important in the world of Quantum computing. The answer is probability. It basically means that when the superposition state of the property of an object collapse it is likely to achieve the state having the highest probability. Seems a little tricky to understand right? Let us take another example to understand this.

Figure 4. An electron

Let us taken an electron as mentioned in figure 4 as an example. There are a lot of properties of electrons to measure like spin, mass, etc. Let us take the spin for example. An electron has to capability to spin either Up or Down(not in literal terms just for understanding purposes). Unless and until the property is not measured it can be considered that it is neither at Upstate nor at Down state i.e. Superposition state. But once the property it measures, the likely outcome is going to be the one having a higher probability to occur. This probability is calculated using the various external factor (let us ignore the mathematical explanation behind for a while).

It this idea of the probability that gives a Qubit therefore a quantum computer an incredible power. If a Qubit is at a superposition state and you perform some serious of operations on it or you can say calculations. When you measure the Qubit thus collapsing its superposition state, the result is the most probable answer. Most of the famous Quantum algorithms are build around this logic some of which we are going to discuss are entanglement, Teleportation. You can explore some complex algorithms associated with this idea such as Shor’s algorithm.

Now that we have understood what superposition is let us understand these algorithms entanglement and teleportation which is a derivative of this principle.

Understanding of Entanglement in Quantum Computing

Real-World Example

Figure 5. Understanding of QunatumEntanglement using two dials

Let us take a real-world example by considering two dials (Dial A and Dial B). Dial A and Dial B perform the operation independently of each other. This means that the change in the sate of anyone dial is uncorrelated to the other. What if we assume that they are not only correlated but somehow linked to each other(not physically). This means that both the dials will always be exactly at the same state meaning that they are entangled to each other. Thus, if the position of dial A is changed, automatically the position dial B will change and be equal to that of dial A.

Do you think it is wise to consider that without any physical connection state sharing between these two dials is possible? We yes it sounds little spooky and it is. It is practically impossible to find a mathematically explained solution to this use-case. But in the quantum world state sharing (i.e. entanglement) between two or more qubits exists.

What makes Entanglement possible in the Quantum World?

Figure 6. Quantum Entanglement explained using 2 Qubits

Let us take the example as mentioned by the video in Figure 6. Let us consider two Qubits Qubit A and Qubit B. Let us assume that both are independent of each other, this means that measurement or any kind of action upon one won't affect the other.

To entangle these Qunartum particles and removed the independence, the two quantum particles first needs to enter in a superposition state.

In this example we will consider two quantum particles to have color as a property in the superposition state. With two Quantum particles in superposition state we will not know the color of either one.

To entangle the Quantum particle we need to perform an operation in any one of them. IN our use case this operation will be to change the color of the Quantum particle. But as stated before both the Quantum particles are in superposition state i.e. its is either red or blue but we are not aware of the fact what is the Quantum particle.

The question arises here is that without knowing the color of the quantum particle how can we change the color? Is it possible to change the state of the Quantum particle without even knowing to which state it initially belong? In other words, an operation to perform a change in the state of Quantum particle when it is in superposition state is possible or not?

It turns out that in the Quantum world you can perform such operation. To be more precise enough you can perform the change in state operation on a quantum particle without knowing it. As soon as this operation is performed, the state of Quantum particles A and B becomes dependent on each other. This means that we cannot describe the state of one quantum particle without describing the state of the other quantum particle therefore they are the same.

This is the formal definition of quantum entanglement. When two or more quantum particle can not have their state described independently, entanglement of the quantum particles has occurred.

There are few properties of Quantum entanglement worth noting:-

  1. To perform quantum entanglement between the Quantum particles, they need to be in close proximity.
  2. After quantum entanglement occurs the state of the Quantum particle (in our case color) will always be dependent on each other regardless of the distance.

This instantaneous state transfer according to property number 2 seemed very spooky because Albert Einstein had proved that nothing can be greater than the speed of the light. But how it is possible that after quantum entanglement if the quantum particles are kept lightyears apart the changes in the state of One particle will instantly change the state of the other particle? It turns out then even to this day there is not a mathematical explanation to support the existence of this property.

What makes Quantum Entanglement so important in the Quantum World?

Recall the previous example where we explored how much the computational power varies when we increase classical bits as opposed to quantum bits. We learned that with the introduction of Qubits, the quantum computer had the capability to increase the computational power exponentially. The reason was that Qubit is capable to store more than two state i.e. Superposition state. When we introduce Quantum entanglement to this, it helps in finding sync between the Qubits in the quantum computer.

Thus, the change in the state of one Quantum particle will change the state of all the other particles and all the particles will have the same state instantaneously. This can help in solving problems like total time to refresh a quantum computer, to perform parity or complement operations, etc.

Now that we got a clear picture of what Quantum entanglement is, let us move to understand Quantum teleportation.

Understanding of Teleportation in Quantum Computing

Before going into the details, one thing to note here is that teleoperation doesn't mean any kind of futuristic technology which is showed in Star trek or Doraemon.

Alice and Bob Problem

Figure 7. Alice and Bob at two ends of the Solar System

Let use understand Teleportation by taking a use case which although seems far-fetched (consider it as possible for the time being).

Problem Statement: Alice and Bob are two scientists exploring to find a way to communicate with each other at long distances within a short interval of time. To do the same, they took two spaceships and traveled across two ends of the solar system. Can they build an effective mechanism to communicate at such a larger distance within a short interval of time? According to NASA, it will take 27 hours to communicate a message from one end to the other of the solar system. Can this time be reduced by Alice or bob?

How can we help Alice and Bob for their research?

Figure 8. Alice and Bob at two ends of the Solar System each having an entangled Quantum particle

From the previous phenomenon we studied, this can be possible using Quantum entanglement. All slice and bob have to do are take two quantum particles, perform entanglement, and take with them in their spaceships. The state transfer is instantaneous, thus any kind of operation performed by Alice will be received by bob instantaneously or vice-versa.

But there is one problem associated with it. Although the message received is instantaneous, it needs to be decoded by bob almost instantaneously. The question arises here is how does bob will get to know when to decode the message? If bob decode’s the message early then it is still not transmitted while if the bob decode’s the message late then he runs a risk of interference thus collapsing their superposition state resulting in collapsing of entanglement. In scientific terms, it means that:-

Once quantum entanglement is achieved between two or more quantum particles, it is important to ensure that while measuring the state of Quantum particle, the time at which measurement is carried out needs to be at the exact time when the change in the state of a Qunatum particle occurs. If not then qunatum particle runs a risk of losing Qunatum entanglement hence it's superposition state.

To resolve this issue we need to understand what the Bell States means.

When two qunatum particles are entangled it can have either of four different types of entanglement states. The entanglement states are called Bell states.

The reason of introducing Bell states is that, while decoding the message received by Bob it is important for him to know what is the Bell state existing between the two qunatum particles. This actually helped us in solving one big spooky question raised while addressing Qunatum entanglement.

According to Qunatum entanglement, the change in the state of one Quantum particle is transferred almost instantaneously thus being faster than the speed of light. But for the second Quantum particle to decode what the message is, it needs to have the bell state. It is important to note that Bell states can only be transferred using classical means. This means that the time taken to receive the message will be slower than the speed of light, making Einstein’s theory correct.

Figure 9. Alice and Bob need a classical means to transfer the message

To resolve the Bob and Alice’s research. Alice along with the encoded message on Qunatum particle, it is required to send the Bell State by classical means. This means that for them to achieve communication faster than 27hours is not possible using Quantum Teleportation.

We can conclude that Quantum Teleportation cannot be greater than the speed of light. Does it mean that Quantum Teleportation has no importance? Is there any use case where it can be beneficial to use it rather than using the existing communication technologies?

Why is Quantum Telecommunication Important?

There is one application where it is being heavily researched, which is Qunatum Communication.

Quantum Communication is transmission of information via secure means using Quantum Phenomena like Teleportation.

While teleportation cannot be used to communicate faster than the speed of light, it can be used to communicate securely. The communication across the globe will be secure as the only parameter that is required apart from the encoded message is the Bell state. A heavy amount of research is being carried out in this area to make to communication across the work more secure.

What next?

This is a wrap up for this blog. This blog was aimed to provide you a headstart with an understanding of there major Qunatum Phenomena which are:-

  1. Superposition
  2. Entanglement
  3. Teleportation

Apart from this we also carried out a comparative study between a classical computer and Qunatum computer.

With so much theory in this, it is important for us to understand how these phenomena are implemented using QDK.

Part-2 of Understaidingg Qunatum Computing will be a coding exercise where we will be developing algorithms for Quantum computing phenomena from scratch and understand the line-by-line implementation of it using QDK and Python.

References

There are a lot of youtube channels out there having classes about Qunatum computing, according to me I found that can give a good understanding of Qunatum Computing:-

  1. A beginner’s guide to quantum computing | Shohini Ghose
  2. Quantum Computers Explained — Limits of Human Technology

There are some of the courses in Course-era, EDX, etc which can also very beneficial, some of these are:-

  1. https://www.edx.org/professional-certificate/delftx-quantum-computing-and-quantum-internet
  2. https://www.edx.org/course/architecture-algorithms-quantum-computer-internet
  3. https://www.coursera.org/learn/quantum-computing-algorithms

The most help which I got was from the documentation and extensive coding examples provided by the Microsoft team to explore Quantum computing using QDK. The links for the same are :

  1. https://docs.microsoft.com/en-us/quantum/overview/what-is-quantum-computing
  2. https://docs.microsoft.com/en-us/quantum/concepts/

That's a wrap up from my side, I hope this blog would have helped you to get deeper understanding of Qunatum Computing with fascinating Real-Worl examples.

Happy Learning!

--

--

Madhur Dheer
TheTeamMavericks

ECE Engineer with keen interests in AWS|ML|Image Processing|Docker|Software Development|Electronics|Product Development|Python|Java|Learning New Technologies