Introduction to Q#: Microsoft Quantum Computing

Microsoft released its Microsoft Quantum Development Kit, that lets you perform calculations using Qubits, that can even be done on your local computer, via a simulator. Krysta Svore goes through a video demo, showing some basics of the language and concepts.

In this post, I will go through the demo, in the Microsoft Quantum Development Kit; Introduction and step-by-step demo. I wanted to write this to give more information around each point discussed, for those, like me, who don’t have a deep knowledge of quantum computing.

Introduction

Before we even begin, it is highly recommended you know at least the basics of quantum mechanics, such as the two basic principles of Superposition and Entanglement. (These are nice easy to understand videos, for beginners). I suggest you read up on these first, if you don’t already know them.

Q# will look familiar to .NET developers, with concepts taken from F# and C#.

In thinking of how to call your quantum code, you can think of quantum processing as being similar to a co-processor, much like a GPU. You call the quantum processor, through your CPU, In this case, you can use C# to call Q#.

Qubits

Register is used to store Quantum information. A register is a Qubit, and you can create qubits like an array.

using (register = Qubit[2])

X operator is analogous to a NOT in classical logic. It is flipping it’s state. This code is flipping the Qubit.

X(register[0]);

Then we teleport the message between the Qubits. In the sample it goes to another operation, called Teleport. First they register another qubit and apply the H operator to it. H is the Hadamard gate and is creating a superposition.

using (register = Qubit[1]) {

    let here = register[0];

    H(here);

As a note that might help you here. All of these gates are similar to classical gates. e.g. XOR, AND, NAND etc. However these gates are for quantum states.

Hadamard and CNOT Gates

The Hadamard gate, acts on a single qubit, and it represents a certain rotation on the X and Y axis. But rotating what, on what axis? This is where you want to look at the Bloch sphere. The Bloch sphere is a geometrical representation of the pure state space of a two-level quantum mechanical system (qubit).

Pure state space, corresponds to vectors in Hilbert Space, with each observable quantity is associated with a mathematical operator. e.g. wavefunction. Hilbert space is generalizing the notion of Euclidean space. This means extending methods to add finite or infinite dimensions to 3D space. Euclidean space is at simple level, the X, Y, and Z axis.

Reversing this backwards.

Euclidean space (x,y,x) => Hilbert Space (dimensions) => Pure State Space (vectors in dimensions) => Bloch Sphere (geometrical representation of pure state space) => Qubit is a vector in this space.

But what does this even mean. While classical computers are 1s or 0s, a qubit can be a 1 or 0 or anything in between. These are its super positions. The Hadamard gate, places the qubit into a superposition, meaning, when it is measured, it has equal probability to produce a 1 or 0. Applying a Hadamard gate twice, will always result it in giving the same value as the initial input.

CNOT gate is short for Controlled Gate, and this one is a little easier to understand. It takes 2 qubits. If the first one is 1, then it will flip the second one. If the first one is 0, then it does nothing to the second qubit.

CNOT(here, there);

Doing a Hadamard gate and a CNOT gate, has now entangled the here and there variables. If you do something to the first one, it changes the second one, and vice versa.

Now, we are going to insert the msg into the existing entangled pair by applying a CNOT gate and a Hadamard gate with the msg and here.

CNOT(msg, here);

H(msg);

Pauli Gates

Now we want to measure the qubit, and translate to a classical state. This is done via the M operator, and will output a One or Zero depending upon its value. Moving on, we apply the Z and X operations to the ‘there’ qubit, depending upon the result.

if (M(msg) == One) { Z(there); }

if (M(here) == One) { X(there); }

The X and Z operations are Pauli gates. The Pauli X gate is easily mapped to a NOT gate in classical computing. a Pauli Z gate, is a type of phase shift gate, where it leaves a basis state of |0> and maps |1> to a -|1>

If you want to know what |x> means. It is called a Ket, and the mathematical representation of a qubit. x, being a 0 or 1.

Summary

Going through this example, it is clear you need to know fundamentals of quantum mechanics, in order to understand what is going on. Hopefully I provided enough information, for a very basic understanding of how this fits together.

Microsoft MVP | Xamarin MVP | Xamarin Forms Developer | Melbourne, Australia

Leave A Comment?