Everything you should know about the Quantum Development Kit, but were afraid to ask
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.
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 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-compiler repo under the src/QsCompiler/CSharpGeneration folder. This code generator is distributed as a library via the Microsoft.Quantum.CsharpGeneration NuGet package.
(updated in July 2021) The Q# compiler and the code generation library are invoked together by the Quantum Development Kit that adds precompilation steps to a .csproj file in order to take Q# files, compile them and generate their corresponding C# classes and API documentation. The set of steps used by this custom SDK are defined in .props and .target files needed by MSBuild to automatically trigger Q# compilation. The source of the nuspec for the Microsoft.Quantum.Sdk package is in microsoft/qsharp-compiler.
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
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++.
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 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
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.
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 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 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 (now deprecated and replaced by the Azure Quantum Resource Estimator) you can easily calculate how many resources and how long it would take to perform such simulation on a quantum computer.
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.
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!