# A hands-on look at quantum computing

### While we wait for the quantum cloud services, let’s explore the Microsoft Quantum Development Kit and IBM Q and Qiskit SDKs

Quantum computing, which was proposed in the 1980s, is just beginning to become available, albeit with small numbers of qubits, high decay rates, and significant amounts of noise. As we’ll discuss, IBM and Microsoft are beginning to offer quantum computer and quantum simulator access in their clouds.

Elsewhere, Google has demonstrated quantum computing capabilities (and claimed quantum supremacy) in its labs, but hasn’t announced public access. Intel is also working on quantum chips and systems, but hasn’t announced commercial availability.

## Quantum computing definitions

Qubits are quantum bits. Classical bits have two possible values, 0 and 1. Quantum bits can take on an infinite number of values, all of which are combinations or superpositions of the two classical states. Any two-dimensional column vector of real or complex numbers with norm 1 represents a possible quantum state held by a qubit.

You can picture that in 3D as vectors lying anywhere on the surface of a unit sphere, called a Bloch sphere (see image below). When you measure a qubit in a superposed state, the quantum state will randomly resolve to one of the two classical states. You can also explicitly set a qubit to a classical value (0 or 1). Measuring a qubit that has a classical value does *not* affect its state.

Three quantum mechanical properties — superposition, entanglement, and interference — are used to manipulate qubits. Superposition is the combination of the classical states, essentially allowing them to both exist at the same time until they are measured. Entanglement is the behavior that Einstein famously called “spooky action at a distance.” Two entangled qubits always have the same state when measured. Interference can be constructive or destructive. Constructive quantum interference is used in quantum computers to amplify signals leading to the right answer, and destructive quantum interference is used to cancel signals leading to the wrong answer.

The subject of quantum gates, or single-qubit operators, gets technical rather quickly. If you’ve taken complex analysis, linear algebra, and quantum mechanics, you should be able to follow this discussion. If not, please take it as given that there are single-qubit operators, including the basic set of Hadamard gates and T-gates, which can be combined into a larger set called Clifford gates. Multiple qubits can be entangled; this is essential for a number of quantum protocols including quantum teleportation and quantum error correction.

## Quantum algorithms

Several quantum algorithms have been proposed that should be faster than classical algorithms if we ever have quantum computers with enough qubits, with long-enough coherence times, and low-enough error rates. For example Grover’s algorithm, devised by Lov Grover in 1996, finds the inverse of a function in O(√N) steps; it can also be used to search an unordered list. It provides a quadratic speedup over classical methods, which need O(N) steps.

Shor’s algorithm, devised by Peter Shor in 1994, finds the prime factors of an integer. It runs in polynomial time in log(N), making it exponentially faster than the classical general number field sieve. This exponential speedup promises to eventually break public-key cryptography schemes, such as RSA, when there are quantum computers with “enough” qubits (the exact number would depend on the size of the integer being factored) in the absence of quantum noise and other quantum-decoherence phenomena.

## Quantum supremacy

Quantum supremacy is the condition where a quantum computer can perform a meaningful operation quickly that would take a classical computer a very long time. Google claimed quantum supremacy in October 2019 for a randomness calculation; IBM countered that a classical supercomputer could perform the same calculation in a few days, not the 10,000 years that Google estimated. In any case, what Google demonstrated, however impressive, was not a general-purpose quantum computation, and people using RSA encryption have nothing to worry about, at least for now.

## Microsoft Q#, Quantum Development Kit, and Azure Quantum

The Microsoft Quantum Development Kit (QDK) consists of the Q# programming language, a set of libraries that abstract complex functionality in Q#, APIs for Python and .NET languages (C#, F#, and VB.NET) for running quantum programs written in Q#, and tools to facilitate your development. You can install Q# for C#, Q# for Python, and/or Q# for Jupyter Notebooks on Windows, Linux, and macOS.

When you run Q# on your own computer, you’ll have to use a quantum simulator. If you run it on Azure, you’ll eventually be able to connect to an actual quantum computer built from cryogenically cooled nanowires (see photograph below). Microsoft says that quantum access previews will be rolling out sometime in 2020.

The “Hello, World” program for Q# generates random integers. Essentially, it works by setting a qubit through a Hadamard gate to a quantum superposition that has equal probably of returning 0 or 1 when measured (called a Bell state), and then repeating these “H” and “M” operations as many times as needed to generate an integer in the desired range. In Q#, the quantum operation code for generating a random bit looks like the following:

namespace Qrng {

open Microsoft.Quantum.Intrinsic;

operation SampleQuantumRandomNumberGenerator() : Result {

using (q = Qubit()) { // Allocate a qubit.

H(q); // Put the qubit to superposition. It now has a 50% chance of being 0 or 1.

let r = M(q); // Measure the qubit value.

Reset(q);

return r;

}

}

}

You can call this Q# code to run on a quantum computer (or you will be able to eventually) or quantum simulator (now) from Python or from a .NET language such as C#.

## IBM Q and the IBM Qiskit SDK

The IBM Q Experience (see screenshot below) offers two ways to create quantum circuits: Circuit Composer, which is a graphical drag-and-drop environment, and Qiskit Notebooks, which use Python and Jupyter Notebooks to create the circuits in code. Both methods wind up the same, although you can also run Qiskit notebooks on your own machine if you install the Qiskit SDK on Windows, Ubuntu, or macOS.

IBM’s “Hello, World” circuit uses a Hadamard gate (H) to set qubit 0 into a superposed Bell state, and a CNOT gate (CX) to entangle qubits 0 and 1. Then it measures both qubits many times. The expected answers should be roughly half [0,0] and half [1,1], and nearly no [0,1] and [1,0].

If you go the Qiskit route with a simulator back end, the experiment looks like the screenshot below:

You can start with the circuit diagram in the online IBM Quantum Experience and drag four gates into the diagram to accomplish the same thing.

Here, however, you can choose back ends graphically and the number of times to run the circuit changing code.

Running on the simulator, we measure only [0,0] and [1,1] states. This is perfect, but doesn’t represent real-life quantum circuit noise.

Let’s try to run the same circuit at IBM Q Armonk.

It didn’t transpile. Why? Oops: That quantum computer only has one qubit, and we need two qubits. No wonder there was no queue to use it.

Let’s try IBM Q Burlington, which has five qubits.

Now we’re seeing real-life behavior: Quantum errors have given us about 20% unentangled results. Note that we haven’t saved any time by using a real quantum computer for this small circuit: Not only did we have to wait in the queue for almost two minutes, we also used 10 seconds of runtime, where on the simulator we waited in the queue for a second and used 4 milliseconds of runtime.

That kind of sums up where we are with quantum computing now: The existing quantum computers to which the public has access have small numbers of qubits and significant error rates. People are working hard to implement quantum error correction and longer decay times for qubit states, but both are difficult.

I’ll be interested to experiment with Microsoft’s Azure Quantum when it is opened for trials. According to Microsoft, its superconducting nanowire topological qubits, which create Majorana particles at the ends of the wires, should have inherently lower error rates than IBM’s Josephson junction qubits.

Copyright © 2020 IDG Communications, Inc.

```
```