Microsoft is making a big bet on a quantum computing future. Hereโs how you are going to write code that uses those new machines
The future of the computer isnโt silicon; weโre already at the limits of Mooreโs Law in terms of the performance we can get from traditional transistors. Weโre also working on much bigger problems, especially when it comes to cryptography and in mathematical modeling; problems that require days of compute time even on the largest supercomputers.
So where do we go from here? Microsoft Research, like Google and IBM, has been investing heavily in quantum computing. Much of its research has been in basic physics, working with universities around the world to produce efficient low-temperature environments and stable quantum computing environments. But creating a qubitโthe probabilistic quantum bit that essentially replaces the 0โs and 1โs of a traditional bitโis only part of the story. Whatโs also needed is a way to program a quantum computer and interpret the qubitsโ probabilistic state.
Constructing quantum computers
The architecture of a quantum program is relatively simple: A traditional program gets values from user input or from other code. It then passes those values to a quantum application that sets the qubits in a quantum processor, using one of many quantum algorithms, before passing the results back to the parent application.
Itโs a process very similar to the one I used at my first programming job, writing Fortran finite-element analysis code that used a vector processor attached to a supercomputer to handle matrix algebra. The vector libraries I used to build and solve my 3D electromagnetic models worked on both that specialized hardware or on a math coprocessor in a desktop workstation, so I could test my code before using expensive supercomputer time.
Microsoft recently released its Quantum Development Kit, built around its new Q# language. Designed to use familiar constructs to help program applications that interact with qubits, it takes a similar approach to working with coprocessors, providing libraries that handle the actual quantum programming and interpretation, so you can write code that hands qubit operations over to one Microsoftโs quantum computers.
Bridging the classical and quantum computing worlds isnโt easy, so donโt expect Q# to be like Visual Basic. It is more like using that set of Fortran mathematics libraries, with the same underlying assumption: that you understand the theory behind what youโre doing.
One element of the Quantum Development Kit is a quantum computing primer, which explores issues around using simulators, as well as providing a primer in linear algebra. If youโre going to be programming in Q#, an understanding of key linear algebra concepts around vectors and matrices is essentialโespecially eigenvalues and eigenvectors, which are key elements of many quantum algorithms.
Getting started with Q#
The development kit downloads as a Visual Studio extension, so you can use it with all versions of Microsoftโs main development environment, including the free Community edition. The installer includes the Q# language, a local quantum simulator, and libraries that support embedding Q# modules in your .Net code. Once installed, you can connect to Microsoftโs Q# Github repository to clone and download sample code and additional libraries. Itโs a quick process; the installer takes a couple of minutes to download and run on a reasonably powerful development PC. The libraries are hosted on Nuget, so you can quickly update to the latest versions.
With a working quantum computer still a few years away, the Quantum Development Kit is limited to working with simulated quantum computers. Microsoftโs research systems have yet to produce a working topological qubit, but results have been promising. So, until there are published results and Azure gets its quantum coprocessors, youโre limited to experimenting with local- and cloud-hosted simulators. Because theyโre limited to using traditional programming techniques, theyโre not going to handle the full range of complex mathematical operations that quantum computing promises. But they do give a feel for what a small number of qubits can do.
Much of the work you need to do in building a quantum program is in constructing a quantum computer out of qubit transformations. The Q# language handles the process for you, because it includes expressions for many quantum gate structures, as well as common quantum algorithms. The language itself will feel familiar to .Net developers, with a structure thatโs somewhere between C# and F#.
IDG
A test run of a quantum teleportation app on a simulator running in Visual Studio.
Quantum programming basics
Youโll find most Q# programs relatively simple, because what youโre doing is setting up arrays of qubits and applying mathematical transformations to them. Although the underlying problem is complex (or at least likely to take a lot of compute time using traditional compute resources), youโre relying on the quantum computer to handle the work for you, and its quantum algorithms mean you can use a small number of connected qubits to solve your problem.
One important thing to note is that some quantum languages, like the one used by DWave in its quantum computers, are designed to work with quantum annealing, not the gate model used in Microsoftโs quantum hardware.
Where the Q# language differs from the familiar is in its support for quantum algorithms. This starts with types: Q# is a strongly typed language, adding new types that represent qubits and groups of qubits. Another key difference is between Q# operations and functions. Operations contain quantum operations, while functions are purely for classical code, though they can work with the results from a quantum operation.
Quantum algorithms and libraries
Q# also includes specific operation types that work with quantum algorithms, including those that calculate the adjoint results of a matrix of qubits, and others that help construct qubit circuits, triggered only if control qubits are correctly set.
Itโs important to remember that where Q# uses Zero and One in results as variables to handle qubits, theyโre not the same as binary 0 and 1. Instead theyโre representations of the eigenvalues of the vectors stored in the qubits.
You use the Q# standard libraries to build and construct your quantum applications. These include a set of quantum primitives that define the gates youโre building out of your qubits, as well as applying quantum operators and measuring the results. The libraries are divided into two parts: the prelude for setting up your quantum computer, and the canon for operating the machine. Itโs important to understand the differences between these two parts of the libraries, because they need to kept separate in your code. Using the canon operators runs the quantum machine, with operators that handle specific quantum algorithms; for example, applying a Quantum Fourier Transform or finding common divisors of two numbers.
Q# isnโt a language for beginners. Although it simplifies some quantum operations, it does depend on having a knowledge of how a quantum computer operates, as well as understanding the basics of quantum computation. If youโve worked with linear algebra and probabilities, youโll have a head start, but itโs still worth spending time first with Microsoftโs tutorials and samples.


