BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Microsoft Quantum Katas Help Developers Discover Quantum Computing with Q#

Microsoft Quantum Katas Help Developers Discover Quantum Computing with Q#

This item in japanese

Bookmarks

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) : ()
    {
        body
        {
            // 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) : ()
    {
        body
        {
            // ...
        }
        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
Style

BT