Microsoft Quantum Katas Help Developers Discover Quantum Computing with Q#

| by Sergio De Simone Follow 14 Followers on Aug 09, 2018. Estimated reading time: 2 minutes |

Based on the idea of code katas, Microsoft has open-sourced a new project called Quantum Katas, that aims to help developers move their first steps in quantum computing using the Q# language. Quantum Katas are a set of programming exercises of growing complexity that provide immediate feedback to learners.

Currently, four katas are available, each covering a specific quantum topic:

  • How to use the basic quantum computing gates, using both single-qubit and multi-qubit gates.
  • Preparing states in superposition. Superposition is one of the most peculiar properties of quantum systems, along with entanglement, and enables the existence of multiple logical states at the same time in a given qubit.
  • Using measurements to extract classical information from a quantum experiment. The measurement step may destroy the coherence of a quantum system by bringing the qubit state out of superposition.
  • Writing quantum oracles that implement classical functions and the Deutsch–Jozsa algorithm, one of the first examples of a quantum algorithm that is exponentially faster than any possible deterministic classical algorithm.

A kata is organized as a set of coding tasks of growing complexity. Each task, along the lines of test driven programming, is associated with a unit test that initially fails. The developer fills in the code that makes the test pass with the help of available reference material, provided in the kata along with a reference solution.

The problems included in the katas come from the first Q# coding contest that Microsoft ran last July.

The following is an example of an almost trivial task, consisting in flipping the state of a qubit, and a more complex one, consisting in changing the qubit state based on its current state:

    // Part I. Single-Qubit Gates

    // Task 1.1. State flip: |0⟩ to |1⟩ and vice versa
    // Input: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
    // Goal:  Change the state of the qubit to α |1⟩ + β |0⟩.
    // Example: 
    //        If the qubit is in state |0⟩, change its state to |1⟩. 
    //        If the qubit is in state |1⟩, change its state to |0⟩. 
    // Note that this operation is self-adjoint: applying it for a second time 
    // returns the qubit to the original state.
    operation StateFlip (q : Qubit) : ()
            // The Pauli X gate will change the |0⟩ state to the |1⟩ state and vice versa.
            // Type X(q);
            // Then rebuild the project and rerun the tests - T11_StateFlip_Test should now pass!
            // ...
        adjoint self;

    // Task 1.6*. Phase change
    // Inputs: 
    //     1) A qubit in state β|0⟩ + γ|1⟩.
    //     2) Angle alpha, in radians, represented as Double
    // Goal:  Change the state of the qubit as follows:
    //        If the qubit is in state |0⟩, don't change its state.
    //        If the qubit is in state |1⟩, change its state to exp(i*alpha)|1⟩.
    //        If the qubit is in superposition, change its state according to the effect on basis vectors.
    operation PhaseChange (q : Qubit, alpha : Double) : ()
            // ...
        adjoint auto;

Taking Microsoft Quantum Katas requires installing the Quantum development Kit, which is available for Wnidows 10, macOS, and Linux. Each kata is located in its own directory with an associated Visual Studio solution. On macOS and Linux, you can run the katas using Visual Studio Code or the command line, provided you have installed the .NET Core SDK 2.0 or later.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

As complex as direct binary programming with paper tapes by Néstor Sánchez

This is a valuable effort in the right direction, but still only for system programmers. Someday I hope to see a higher level of abstraction framework, without any greek letter or scientist names, just clear operations (a semantic jump like was with SQL) to take advantage of the possibilities and none of the complex internal working physics of quantum computing.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you