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:

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.

Tell us what you think

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.

InfoQ Weekly Newsletter

Join a community of over 250 K senior developers by signing up for our newsletter. If you are based in the EEA, please contact us so we can provide you with the protections afforded to you under EEA protection laws.

Is your profile up-to-date? Please take a moment to review and update.

Email Address

Note: If updating/changing your email, a validation request will be sent

Company name:

Keep current company name

Update Company name to:

Company role:

Keep current company role

Update company role to:

Company size:

Keep current company Size

Update company size to:

Country/Zone:

Keep current country/zone

Update country/zone to:

State/Province/Region:

Keep current state/province/region

Update state/province/region to:

Subscribe to our newsletter?

Subscribe to our architect newsletter?

Subscribe to our industry email notices?

By subscribing to this email, we may send you content based on your previous topic interests. See our privacy notice for details.

You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.