Everything you should know about the Quantum Development Kit, but were afraid to ask

Avatar

Andrés

Microsoft’s Quantum Development Kit (QDK) is a set of open-source tools designed to help developers write quantum programs at scale.

The most recognizable element of the QDK is Q#, a high level programming language designed for quantum programs, however the QDK is comprised of much more than that. Today, I’ll provide a comprehensive list of all the elements we ship as part of the QDK and the details of what they do, where is their source code and how they are distributed.

TL;DR

ComponentSourceBinary Distribution
Q# compilermicrosoft/qsharp-compilerMicrosoft.Quantum.Compiler
Q# to C# code genmicrosoft/qsharp-runtimeMicrosoft.Quantum.CsharpGeneration
Q# language servermicrosoft/qsharp-compilerbundled with vsix extensions
Visual Studio 2019 extensionmicrosoft/qsharp-compilerMicrosoft Quantum Development Kit
VS Code extensionmicrosoft/qsharp-compilerMicrosoft Quantum Development Kit for Visual Studio Code
.NET Core CLI integrationmicrosoft/qsharp-compilerMicrosoft.Quantum.ProjectTemplates
Simulation frameworkmicrosoft/qsharp-runtimeMicrosoft.Quantum.Simulators
IQ#microsoft/iqsharpMicrosoft.Quantum.IQSharp
Python packagemicrosoft/iqsharpqsharp PyPI
Standard Librarymicrosoft/QuantumLibrariesMicrosoft.Quantum.Standard
Numerics Librarymicrosoft/QuantumLibrariesMicrosoft.Quantum.Numerics
Chemistry Librarymicrosoft/QuantumLibrariesMicrosoft.Quantum.Chemistry
DocumentationMicrosoftDocs/quantum-docs-prOnline Docs
Samplesmicrosoft/Quantum
Katasmicrosoft/QuantumKatas

The Q# Compiler

The Q# compiler, of course, compiles Q# code from .qs files. Among other things it parses the files, add references and performs syntax and semantics validations, makes any transformations necessary and if successful creates a syntax tree that represents the code to execute. The compiler is also responsible for parsing Q# inline documentation and generate it’s corresponding YAML files.

The source of the compiler can be found in GitHub in the microsoft/qsharp-compiler repo, under the src/QsCompiler folder.

The compiler is distributed as a library in binary format via the Microsoft.Quantum.Compiler NuGet package. Adding a reference to this package allows you to invoke the compiler programmatically from .NET Core applications. In the source repository, there is a command line tool that allows you to invoke the Q# compiler, but this tool is currently not distributed in binary format.

The Q# to C# Code Generation

To simulate the execution of Q# programs, for each Q# operation we generate a corresponding C# class that can be executed using Q#’s simulation framework and then use the C# compiler to generate a dll that can be reference by other .NET Core applications.

The source of the Q# code generator can be found in GitHub in the microsoft/qsharp-runtime repo under the src/Simulation/CsharpGeneration folder. This code generator is distributed as a library via the Microsoft.Quantum.CsharpGeneration NuGet package.

Built on top of the Q# compiler and the code generation library there is a command line tool that takes the Q# files, compiles them and generate their corresponding C# classes and API documentation. The source of this tool is also under the microsoft/qsharp-runtime repo, under the src/Simulation/CsharpGeneration.App folder. This command line tool is bundled with the Microsoft.Quantum.Development.Kit NuGet package. This package also bundles the .props and .target files needed by MSBuild to automatically invoke the tool when building a project. The source of the nuspec for the Microsoft.Quantum.Developement.Kit package is in microsoft/qsharp-runtime.

The Q# Language Server

The Q# Language Server provides the interface for editors to collect information about Q# code from the compiler and provide advanced editing capabilities like Intellisense, rename and other code actions. For this reason, the language server is tightly coupled with the compiler and resides in the same GitHub repository: the microsoft/qsharp-compiler repo, in the src/QsCompiler/LanguageServerfolder.

The Language Server itself is not distributed stand-alone in binary format, it is bundled with the Visual Studio and VS Code extensions.

The Visual Studio 2019 Extension

We provide a Visual Studio 2019 extension to enable advanced editing capabilities for Q# files. The extension itself is not needed to build Q# projects (for this, all that is required is to add a reference to the Microsoft.Quantum.Development.Kit NuGet package), but it enables syntax highlighting, Intellisense and the rest of the functionality exposed by the language server. Bundled with the extension are also templates to create new Q# libraries, programs and tests projects.

The source of the Visual Studio extension can be found in GitHub in the microsoft/qsharp-compiler repo, under the src/VisualStudioExtension folder. It is distributed in the Visual Studio Marketplace as the Microsoft Quantum Development Kit extension.

The VS Code Extension

We provide a similar extension for VS Code; as its Visual Studio counterpart it enables syntax highlighting, Intellisense and the rest of the functionality exposed by the language server. Unique to this extension is that it is written using TypeScript since, as most of VS Code extensions, it is built on top of node.js.

The source of the extension can be found in GitHub in the microsoft/qsharp-compiler repo, under the src/VSCodeExtension folder. It is distributed in the Visual Studio Marketplace as the Microsoft Quantum Development Kit for Visual Studio Code extension.

The .NET Core CLI integration

The Microsoft.Quantum.ProjectTemplates is the NuGet package that extends the .NET Core’s command line interface (dotnet)  to add support to create new projects using the Q# language. The source code for this package is in microsoft/qsharp-compiler repo in the src/ProjectTemplates folder.

The Simulation Framework

The QDK provides a robust simulation framework to simulate, debug, and estimate the resources consumed by quantum programs written in Q#. The source code for this framework is found in the the microsoft/qsharp-runtime repository in the src/Simulation folder.

Notice most of the framework is implemented using C# with the noticeable exception of the full-state simulator, which is written in C++.

All simulators (full-state, toffoli and tracer) are distributed as part of the Microsoft.Quantum.Simulators NuGet package so they can be added as reference of .NET Core projects.

IQ#

IQ# is the Jupyter kernel for Q#. It allows the creation of Jupyter notebooks that support Q# natively. It leverages the compiler and the simulation framework to compile Q# code in cells and simulate them using custom magic commands.

The source code can be found in GitHub in the microsoft/iqsharp repo, under the src/ folder. It is binary distributed using two different NuGet packages:

  • The Microsoft.Quantum.IQSharp package, provides a .NET Core CLI tool that can be invoked from the command line to install or start the Jupyter kernel.
  • The Microsoft.Quantum.IQSharp.Core package, provides IQ# as a library and it is used mainly to create extensions that adds new %magic commands (like %kata).

We also offer the mcr.microsoft.com/quantum/iqsharp-base image, available from the Microsoft Container Registry, as a fully functional Docker image capable of executing Jupyter notebooks with the IQ# kernel. The Dockerfile for this image can be found in the microsoft/iqsharp repo at images/iqsharp-base/Dockerfile.

The qsharp Python Package

We provide the ability to execute Q# code from Python using the qsharp package. Internally, this package starts the IQ# Jupyter kernel and send commands to compile and execute the Q# operations. It exposes this functionality in the qsharp module using standard Python idioms.

The source code can be found in GitHub in the microsoft/iqsharp repo, under the src/Python folder. It is binary distributed as the qsharp wheel that gets uploaded to PyPI and that can be installed using pip install qsharp.

The Standard Library

The Standard library provides a large set of Q# functions, operations and user-defined types of common functionality that can be used with different target machines and that ease the development of quantum programs. Operations like ForEach or QuantumPhaseEstimation are available through this library.

The source code can be found in GitHub in the microsoft/QuantumLibraries repo, under the Standard folder. It is binary distributed as the Microsoft.Quantum.Standard NuGet package.

The Numerics Library

Quantum programs work very differently so all the core functionality that we take for granted when writing conventional programs like basic integer operations (add, subtract, multiply) needs to be re-implemented using reversible quantum gates. The Quantum Numerics Library provides efficient implementations of basic and high-level integer arithmetic and fixed-points operations in Q# so it can be used in other programs like Shor’s integer factorization algorithm.

The source code can be found in GitHub in the microsoft/QuantumLibraries repo, under the Numerics folder. It is binary distributed as the Microsoft.Quantum.Numerics NuGet package.

The Chemistry Library

Simulating problems in chemistry and material science remains perhaps the most evocative application of quantum computing and would allow us to probe chemical reaction mechanisms that hitherto were beyond our ability to measure or simulate. The QDK provides a Quantum Chemistry Library that can load the description of a molecule from a file and the Q# operations needed to simulate the Hamiltonian evolution of such molecule in a quantum computer. It is true that trying to execute such simulation on a classical computer or current quantum hardware is not possible, however using the ResourcesEstimator from the QDK you can easily calculate how many resources and how long it would take to perform such simulation on a quantum computer.

The source code can be found in GitHub in the microsoft/QuantumLibraries repo, under the Chemistry folder. It is binary distributed as the Microsoft.Quantum.Chemistry NuGet package.

Documentation

Quantum computing is an exciting new technology that people are eager to learn; the QDK provide extensive documentation not only explaining Q#’s available APIs and instructions on how to get started with Q#, but also conceptual guides that explain what is quantum computing and its potential.

The source of our documentation is also in GitHub; you can find all the conceptual guides and API docs in the MicrosoftDocs/quantum-docs-pr repo; however notice that the Q#’s API documentation is auto-generated from source, so any changes in this repo get overwritten during the build.

Q# Quantum Samples Library

Probably the most useful technique to learn a new programming language is to read existing code. For this reason, we have created a vast library of samples that showcase how to write quantum programs using Q#.

The samples can be found in GitHub in the microsoft/quantum repo.

There is no binary distribution of the samples, however we offer the mcr.microsoft.com/quantum/samples image, available from the Microsoft Container Registry, as a fully functional Docker image with all the pre-reqs needed to build any of the samples. The Dockerfile for this image can be found in the same microsoft/quantum repo at Build/images/samples/Dockerfile.

The Quantum Katas and Tutorials

Last but not least is our Quantum Katas and Tutorials repository.

It is typically difficult to fully grasp and learn a new concept like quantum computing simply by reading or learning how to write Q# code; for this reason we created the Quantum Katas that allows developers to learn quantum computing by completing a list of step-by-step exercises designed to teach students about quantum concepts and operations.

There are C# and Jupyter notebook version of most of the Katas and their source code is in the microsoft/QuantumKatas repo. The Jupyter notebook version of the Katas can be executed online with no installation using Binder.

Conclusion

The QDK provides a large set of tools to develop quantum programs, and it’s still growing: we’re currently working on building a new Quantum Machine Learning library as well as developing the clients to connect to our new Azure Quantum Service which will allow developers to execute their quantum programs and quantum inspired optimizations on the cloud with different hardware and different partners.

We are always looking for contributions! There are many ways you may get involved and contribute to our community. Please read Contributing to the Quantum Development Kit in our documentation for more information and next steps.

This post is part of the Q# Advent Calendar 2019. Follow the calendar for other great posts!

Avatar
Andrés Paz

Principal Software Enginner, Quantum Platform

Follow Andrés   

0 comments

    Leave a comment