The Q# Libraries

The Quantum Development Kit (QDK) provides additional domain-specific functionality through NuGet packages that can be added to your Q# projects.

Q# Library NuGet package Notes
Q# standard libraries Microsoft.Quantum.Standard Included by default
Quantum chemistry library Microsoft.Quantum.Chemistry
Quantum machine learning library Microsoft.Quantum.MachineLearning
Quantum numerics library Microsoft.Quantum.Numerics

Standard Libraries

The Microsoft.Quantum.Sdk NuGet package installed during installation and validation automatically provides the Q# standard library. The standard libraries provide a set of essential and very useful functions and operations that can be used when writing quantum programs in Q#.

The functionality of the standard libraries includes classical mathematics, type conversions between various Q# data types, diagnostic of mistakes and errors in quantum programs, quantum error correction, characterization of the effects of operations in order to develop useful quantum algorithms, and many more features.

For more information, see Standard Libraries.

Quantum Chemistry Library

Simulation of physical systems has long played a central role in quantum computing. This is because quantum dynamics are widely believed to be intractable to simulate on classical computers, meaning that the complexity of simulating the system scales exponentially with the size of the quantum system in question. 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. It would also allow us to simulate correlated electronic materials such as high-temperature superconductors. The list of applications in this space is vast.

The documentation of the quantum chemistry library for the Quantum Development Kit provides an introduction and several examples to simulating electronic structure problems on quantum computers in order to help the reader understand the role that many aspects of the Hamiltonian simulation library play within the space. For more information, see Quantum Chemistry Library.

The quantum chemistry library for the Quantum Development Kit is designed to work well with computational chemistry packages, most notably the NWChem computational chemistry platform developed by the Environmental Molecular Sciences Laboratory (EMSL) at Pacific Northwest National Laboratory. For more information, see Installation of quantum chemistry library.

Quantum Machine Learning Library

The Quantum Machine Learning Library is an API, written in Q#, that gives you the ability to run hybrid quantum/classical machine learning experiments. The library gives you the ability to:

  • Load your own data to classify with quantum simulators
  • Use samples and tutorials to get introduced to the field of quantum machine learning

You can expect low performance compared to current classical machine learning frameworks (remember that everything is running on top of the simulation of a quantum device that is already computationally expensive). The model implemented in this library is based on the quantum-classical training scheme presented in Circuit-centric quantum classifiers.

The quantum machine learning library documentation provides an implementation of the sequential classifiers that take advantage of quantum computing to understand data. In this documentation you will find:

Quantum Numerics Library

Many quantum algorithms rely on oracles that evaluate mathematical functions on a superposition of inputs. The main component of Shor's algorithm, for example, evaluates $f(x) = a^x\operatorname{mod} N$ for a fixed $a$, the number to factor $N$, and $x$ a $2n$-qubit integer in a uniform superposition over all $2n$-bit strings.

To run Shor's algorithm on an actual quantum computer, this function has to be written in terms of the native operations of the target machine. Using the binary representation of $x$ with $x_i$ denoting the $i$-th bit counting from the least-significant bit, $f(x)$ can be written as $f(x) = a^{\sum_{i=0}^{2n-1} x_i 2^i} \operatorname{mod} N$.

In turn, this can be written as a product (mod N) of terms $a^{2^i x_i}=(a^{2^i})^{x_i}$. The function $f(x)$ can thus be implemented using a sequence of $2n$ (modular) multiplications by $a^{2^i}$ conditional on $x_i$ being nonzero. The constants $a^{2^i}$ can be precomputed and reduced modulo N before running the algorithm.

This sequence of controlled modular multiplications can be simplified further: Each multiplication can be performed using a sequence of $n$ controlled modular additions; and each modular addition can be built from a regular addition and a comparator.

Given that so many steps are necessary to arrive at an actual implementation, it would be extremely helpful to have such functionality available from the start. This is why the Quantum Development Kit provides support for a wide range of numerics functionality.

Besides the integer arithmetic mentioned thus far, the numerics library provides:

  • (Un)signed integer functionality (multiply, square, division with remainder, inversion, ...) with one or two quantum integer numbers as input.
  • Fixed-point functionality (add / subtract, multiply, square, 1/x, polynomial evaluation) with one or two quantum fixed-point numbers as input.


Once you have installed the Quantum Development Kit for use with your preferred environment and host language, you can easily add libraries to individual Q# projects without any further installation.


Some Q# libraries may work well with additional tools that work alongside your Q# programs, or that integrate with your host applications. For example, the chemistry library installation instructions describe how to use the Microsoft.Quantum.Chemistry package together with the NWChem computational chemistry platform, and how to install the qdk-chem command-line tools for working with quantum chemistry data.

Command prompt or Visual Studio Code: Using the command prompt on its own or from within Visual Studio Code, you can use the dotnet command to add a NuGet package reference to your project. For example, to add the Microsoft.Quantum.Numerics package, run the following command:

dotnet add package Microsoft.Quantum.Numerics

Visual Studio: If you are using Visual Studio 2022 or later, you can add additional Q# packages using the NuGet Package Manager. To load a package:

  1. With a project open in Visual Studio, select Manage NuGet Packages... from the Project menu.

  2. Click Browse, select Include prerelease and search for the package name "Microsoft.Quantum.Numerics". This will list the packages available for download.

  3. Hover over Microsoft.Quantum.Numerics and click the downward-pointing arrow to the right of the version number to install the numerics package.

For more details, see the Package Manager UI guide.

Alternatively, you can use the Package Manager Console to add the numerics library to your project via the command line interface.

Use the Package Manager Console from the command prompt

From the Package Manager Console, run the following:

Install-Package Microsoft.Quantum.Numerics

For more details, see the Package Manager Console guide.

Next Steps

Sources of the libraries as well as code samples can be obtained from GitHub. See Licensing for further information. Note that package references ("binaries") are available also for the libraries and offer another way of including the libraries in projects.