Install the Microsoft Quantum Development Kit (QDK)

Learn how to install the Microsoft Quantum Development Kit (QDK), so that you can get started with quantum programming. The QDK consists of:

  • the Q# programming language
  • a set of libraries that abstract complex functionality in Q#
  • a host application (written in Python or a .NET language) that runs quantum operations written in Q#
  • tools to facilitate your development

Depending on your chosen development environment, there are different installation steps. Choose your environment from the sections below.

Develop with Python

The qsharp package for Python makes it easy to simulate Q# operations and functions from within Python. IQ# (pronounced i-q-sharp) is an extension primarily used by Jupyter and Python that provides the core functionality for compiling and simulating Q# operations.

  1. Pre-requisites

  2. Install the qsharp package

    pip install qsharp
    
  3. Install the iqsharp package

    dotnet tool install -g Microsoft.Quantum.IQSharp
    dotnet iqsharp install
    
  4. Verify the installation by creating a Hello World application

    • Create a minimal Q# operation, by creating a file called Operation.qs, and adding the following code to it:

      namespace HelloWorld
      {
          open Microsoft.Quantum.Intrinsic;
          open Microsoft.Quantum.Canon;
      
          operation SayHello() : Result {
              Message("Hello from quantum world!");
              return Zero;
          }
      }
      
    • Create a Python program called hello_world.py to call the Q# SayHello() operation:

      import qsharp
      
      from HelloWorld import SayHello
      
      SayHello.simulate()
      
    • Run the program:

      python hello_world.py
      
    • Verify the output. Your program should output the following lines:

      Hello from quantum world!
      0
      

Develop with Jupyter notebooks

A favorite of academic settings, scientific labs, and online-based collaborative programming, Jupyter Notebooks offer in-place code execution—now including Q# code—along with instructions, notes, and other content. Here's what you need to do to start creating your own Q# notebooks.

IQ# (pronounced i-q-sharp) is an extension primarily used by Jupyter and Python to the .NET Core SDK that provides the core functionality for compiling and simulating Q# operations.

  1. Pre-requisites

  2. Install the iqsharp package

    dotnet tool install -g Microsoft.Quantum.IQSharp
    dotnet iqsharp install
    
  3. Verify the installation by creating a Hello World application

    • Run the following command to start the notebook server:

      jupyter notebook
      
    • Browse to the URL shown on the command line. For example: [http://localhost:8888/?token=c790a52ba54f0cf77465c3c8983d776348285b0280d91b85]

    • Create a Jupyter notebook with a Q# kernel, and add the following code to the first notebook cell:

      operation SayHello () : Unit {
          Message("Hello from quantum world!");
      }
      
    • Run this cell of the notebook:

      Jupyter notebook cell with Q# code

      You should see SayHello in the output of the cell. When running in jupyter notebooks, the Q# code is compiled, and the notebook outputs the name of the operation(s) that it finds.

    • In a new cell, simulate the execution in a quantum computer of the operation you just created by using the %simulate magic:

      Jupyter notebook cell with %simulate magic

      You should see the message printed on the screen along with the result of the operation you invoked (in this case, empty).

Develop with C# on Windows, using Visual Studio

Visual Studio offers a rich environment for developing Q# programs, offering great features like code completion and syntax highlighting that guide the developer in building their applications. The Q# Visual Studio extension contains templates for Q# files and projects as well as syntax highlighting and IntelliSense support.

  1. Pre-requisites

    • Visual Studio 16.3, with the .NET Core cross-platform development workload enabled
  2. Install the Q# Visual Studio extension

  3. Verify the installation by creating a Hello World application

    • Create a new Q# application

      • Go to File -> New -> Project
      • Type Q# in the search box
      • Select Q# Application
      • Select Next
      • Choose a name and location for your application
      • Select Create
    • Inspect the project

      You should see that two files have been created: Driver.cs, which is the C# host application; and Operation.qs, which is a Q# program that defines a simple operation to print a message to the console.

    • Run the application

      • Select Debug -> Start Without Debugging
      • You should see the text Hello quantum world! printed to a console window.

Note

  • If you have multiple projects within one Visual Studio solution, all projects contained in the solution need to be in the same folder as the solution, or in one of its subfolders.

Develop with C#, using Visual Studio Code

Visual Studio Code (VS Code) offers a rich environment for developing Q# programs across many multiple computer environments, including Windows, Linux and Mac, offering great features like code completion and syntax highlighting that guide the developer in building their applications. The Q# VS Code extension contains syntax highlighting, and Q# code snippets.

  1. Pre-requisites

  2. Install the Quantum VS Code extension

  3. Install the Quantum project templates:

    • Go to View -> Command Palette
    • Select Q#: Install project templates

    You now have the Quantum Development Kit installed and ready to use in your own applications and libraries.

  4. Verify the installation by creating a Hello World application

    • Create a new project:

      • Go to View -> Command Palette
      • Select Q#: Create New Project
      • Navigate to the location on the file system where you would like to create the application
      • Click on the Open new project... button, once the project has been created
    • Run the application:

      • Go to Debug -> Start Without Debugging
      • You should see the following text in the output window Hello quantum world!

Note

    • Workspaces with multiple root folders are not currently supported by the Visual Studio Code extension. If you have multiple projects within one VS Code workspace, all projects need to be contained within the same root folder.

Develop with C#, using the dotnet command-line tool

Of course, you can also build and run Q# programs from the command line by simply installing the .NET Core SDK and the QDK project templates.

  1. Pre-requisites

  2. Install the Quantum project templates for .NET

    dotnet new -i Microsoft.Quantum.ProjectTemplates
    

    You now have the Quantum Development Kit installed and ready to use in your own applications and libraries.

  3. Verify the installation by creating a Hello World application

    • Create a new application

      dotnet new console -lang Q# -o runSayHello
      
    • Navigate to the new application directory

      cd runSayHello
      

    You should see that two files have been created, along with the project files of the application: a Q# file (Operation.qs) and a C# host file (Driver.cs).

    • Run the application

      dotnet run
      

      You should see the following output: Hello quantum world!

What's next?

Now that you have installed the Quantum Development Kit in your preferred environment, you can write and run your first quantum program.