simon_bisson
Contributor

Quantum katas teach you how to do quantum programming in Q#

analysis
Jul 31, 20185 mins
Development ToolsSoftware Development

Quantum computing needs new skills, and Microsoft Research now has a way to teach those skills

ibm 16 qubit processor
Credit: IBM Research

Upending the entire structure of modern computing isn’t easy. First, you need to invent technologies that can chill things to temperatures colder than anything else in the universe, then you need to find a particle that’s its own antiparticle, before braiding them into stable quantum computing engines. Then, of course, you need to program them.

A while back I took a first look at Q#, Microsoft’s experimental quantum computing programming language. It takes familiar computing constructs and patterns, using them to build low-level quantum circuits that embody the problem we’re trying to solve. If you’ve written code using functional programming languages like F# or systems programming languages like Go, you’ll find much of Q# familiar—until it starts to veer off in the direction of silicon-design languages like Verilog.

The QDK: the foundation of programming Microsoft’s quantum computers

So how can developers start using Q#? For the foreseeable future, it will work only on local and Azure-based simulators, because we’re still some way away from a publicly accessible topological qubit, and from machines that can use enough qubits to ensure what scientists call “quantum supremacy.” That’s the point where a quantum computer becomes more efficient than a traditional silicon machine, solving problems almost instantly that would normally take hundreds, if not thousands, of years of processor time.

Microsoft has already shipped its Quantum Development Kit (QDK) that plugs into both Visual Studio and Visual Studio Code, with a local quantum simulator for small problems and access to a larger one on Azure for more complex work. Microsoft has also developed new algorithms that reduce the processing overhead for larger numbers of simulated qubits, making it easier to explore those more complicated quantum algorithms.

Of course, nothing compares to having an actual quantum computer to work with, but the QDK does give you somewhere to start while we wait for the experimental physics teams at Microsoft Research and its associated universities to deliver their first usable qubits.

But QDK isn’t enough. Quantum computing concepts are so very different from the familiar world of CPUs and high-level programming languages that developers need a set of primers to walk you through the initial concepts, teaching you to think differently while giving you the skills you need to build your first quantum circuits.

Katas: coding contests as a learning tool

Modern development tools make it a lot easier to deliver effective coding tutorials, offering scratchpads to try out code and integration points for testing tools to help evaluate your progress. Source-control platforms like GitHub also make it easier to share and distribute code frameworks and training exercises; they also allow community members to make changes or submit new exercises. The same techniques also support coding contests, encouraging developers to learn new skills by offering prizes for the best and the fastest solutions to problems.

For quantum development, Microsoft is using a concept called the kata, which takes its name from Japanese martial art practice forms. Katas are self-paced learning exercises that can be taken again and again, letting you to refine your programming skills by developing increasingly optimized solutions to a specific problem. Each pass through a problem lets you pick up new skills and techniques, much like learning a martial art.

Microsoft recently released a series of quantum katas based on the problems it set in a recent Q# coding contest. The complete set of contest tasks was made up of 15 problems, and the winner solved them all in less than two and a half hours.

Getting started with Q# in quantum katas

Available on GitHub, the quantum katas cover four basic topics, starting with creating your first quantum gates. Each topic adds more fundamental quantum computing concepts, and takes you through increasingly complex exercises.

You’ll need to have QDK installed, before cloning the Quantum Katas repository from GitHub (if you don’t use Git, you can download a Zip file of the code you need).

Once you’ve downloaded the katas, you need to open the project solution file for the coding tutorial you want to use. Each tutorial has the same basic structure, with instructions, a task file that contains the code you write, and a set of tests, as well as a test runner that will host your Q# code and the tutorial tests. Finally, there’s a reference implementation of the kata solution, so you can see how the Microsoft Research quantum computing team solved the problem.

You can run the tests on the task file, to see how they work, but without any code they’ll fail. Each task in the kata has its own unit test, so you can track your progress as you complete each step. Once you’ve written your code, compile it with the Q# compiler, and run the unit tests using the testing tools built into both Visual Studios.

Perfecting your style in katas

Each of the four katas builds on the previous one. So, for example, the second kata explores using quantum superposition to solve problems, using the basic quantum logic circuits you developed in the first. As you progress, you learn how to measure quantum states and how to find ways of discriminating among different states. Some tasks require reading additional reference materials, including scientific papers on certain aspects of quantum computing. That’s not surprising: Even using tools like Q#, you’re working right on the edges of both modern computer science and experimental physics.

You must go back to first principles to learn quantum computing, because the techniques it requires are as new as the first day you wrote a Basic program or tweaked some JavaScript. That’s what the katas let you do. The kata approach helps you quickly move from the absolute basics to complex concepts.

simon_bisson
Contributor

Author of InfoWorld's Enterprise Microsoft blog, Simon BIsson prefers to think of "career" as a verb rather than a noun, having worked in academic and telecoms research, as well as having been the CTO of a startup, running the technical side of UK Online (the first national ISP with content as well as connections), before moving into consultancy and technology strategy. He’s built plenty of large-scale web applications, designed architectures for multi-terabyte online image stores, implemented B2B information hubs, and come up with next generation mobile network architectures and knowledge management solutions. In between doing all that, he’s been a freelance journalist since the early days of the web and writes about everything from enterprise architecture down to gadgets.

More from this author