Skip to content
Microsoft Quantum Development Kit Samples
Branch: master
Clone or download
cgranade Adapt samples to microsoft/QuantumLibraries#96. (#182)
* Begin updating samples for v0.6. (#172)

* Oracle function synthesis (#135)

* Oracle synthesis.

* Variant to uncompute oracle function.

* Update Q# version.

* Bool array signature to support functions with more than 5 variables.

* Apply suggestions from code review

Co-Authored-By: msoeken <>

* Updating package.

* Reference to Yates' method.

* Add one more example to Program.cs.

* Added assertions

from comment in #121

* Updated tomography sample. (#160)

* Updated tomography sample.

* Updated prose and version.

* Addressing feedback.

* Also removed Python interop from solution.

* Fixed parsing error in solution file.

* Began updating C# version of Teleport.

* Updating teleportation, simpleising to 0.6-beta syntax.

* Updated RLS sample to beta.

* IsingGenerators and AdiabaticIsing now run.

* HubbardSimulation now runs.

* Simplified Hubbard code w/ 0.6 features.

* IntFactorization runs.

* OrderFinding runs.

* IsingTrotter now runs.

* Measurement now runs.

* Bump versions to latest beta.

* Updated to latest beta.

* Cleaned up some open stmts.

* Updating a bit more code to 0.6.

* Updated OracleSynthesis.

* Updated bitflip code sample.

* Updated SimpleAlgorithms.

* Updated F# sample.

* Updated CHSH game.

* Updated C# part of DatabaseSearch.

* Removed workaround for a bug long since fixed.

* Updated IQ# notebook for database search sample.

* Updated OpenQasm sample.

* A few more updates to DatabaseSearch nb.

* Updated H2 cmd line sample.

* Updated H ₂ GUI.

* Updated Bayesian PE sample.

* Converted a few more samples to latest beta.

* Updated Samples/SampleTests.

* Updated UnitTesting sample.

* Started updating chemistry samples too.

* simulate hubbard hamiltonian builds

* molecular hydrogen builds

* lithium gui

* hydrogen gui

* Fixed problem with openqasm reader

* Removed Ext.Math in a few places.

* Update Newtonsoft.Json to 12.0.1. (#177)

* Update to use 0.65 syntax and latest beta. (#178)

* Updated 0.6 syntax to use 0.65 w/=.

* Ported more syntax over.

* Fixed a couple bugs in previous porting of syntax.

* Ported some C# code to use new QArray.

* Adapted some use of QArrays in run methods.

* Fixed one more cast to int64.

* Fixed a typo and ported some more syntax.

* Fixed issue in D–J test, updated syntax.

* Update to latest beta.

* Uncommented things that were commented by accident.

* Converted literals to literals.

* Fix bug in HubbardHalfFillingStatePrep.

* Going back to passing QArray into Run. (#179)

* Going back to passing QArray into Run.

* Ported a few more arrays back to QArray.

* Fixed one more qarray

* Continue migrating samples to Q# 0.6 (#180)

* Updated names to avoid warnings.

* Updated to latest beta.

* Updated Arithmetic sample.

* Adapted adiabaticising sample.

* Adapted DatabaseSearch.

* Adapted Hubbard simulation.

* Started adapting Shor, but did not finish.

* Began adapting H2SimCmdLine.

* Fixed Shor.

* Updated IQ# intro nb.

* Adapted IsingTrotter.

* Adapted OracleSynth and OrderFinding.

* Adapted UnitTesting sample.

* Fixed warnings in unit tests.

* Clean up unit testing sample using 0.6 features (#181)

* Cleaning up unit testing sample using 0.6 syntax.

* Addressing @bettinaheim's feedback.

* trivial change

* minor thing

* Adapt samples to microsoft/QuantumLibraries#96.

* Update to latest beta.

* Addressing feedback from @bettinaheim.
Latest commit 2b0978d May 18, 2019

Microsoft Quantum Development Kit Samples


These samples demonstrate the use of the Quantum Development Kit for a variety of different quantum computing tasks. Most samples are provided as a Visual Studio 2017 C# or F# project under the QsharpSamples.sln solution.

Each sample is self-contained in a folder. Most of the samples consist of a Q# source file with detailed comments explaining the sample and a short classical program (either Program.cs (C#), Program.fs (F#), or (Python)) that calls into the Q# operations and functions. There are some samples that are written as an interactive Jupyter notebook thus require no classical host.

A small number of the samples have additional installation requirements beyond those for the rest of the Quantum Development Kit. These are noted in the files for each sample, along with complete installation instructions.

You can find instructions on how to install the Quantum Development Kit in our online documentation, which also includes an introduction to quantum programming concepts. A Docker image definition is also provided for your convenience, see below for instructions on how to build and use it.

The samples are broken down into four broad categories, each of which is described below.

0. Introductory Samples

  • TeleportationSample: This sample documents how to write quantum programs with Q#, C#, and Visual Studio, using the development techniques covered in the main documentation. It also shows how to simulate the same algorithms from Python and Jupyter.
  • Measurement: This sample goes into more detail about how single- and multiple-qubit measurements are represented in Q#, and how to measure in interesting bases such as the Bell basis.
  • SimpleAlgorithms: This sample covers several different basic quantum algorithms, and how each can be written in Q#.
  • IntroToIQSharp: This samples explains how to create interactive notebooks using Jupyter and IQ#.

1. Algorithm Samples

  • DatabaseSearch: This sample demonstrates how to use Grover's algorithm to efficiently search a database represented as a quantum register.
  • IntegerFactorization: This sample demonstrates how to use Shor's algorithm to efficiently factor integers.
  • ReversibleLogicSynthesis: This sample demonstrates how to use reversible logic synthesis to solve the hidden shift problem.
  • CHSHGame: This sample demonstrates a famous nonlocal game which proves that no theory of local hidden variables can ever reproduce all the predictions of quantum mechanics.

2. Characterization and Testing Samples

  • UnitTesting: This sample demonstrates how to use the Quantum Development Kit together with the xUnit framework to check the correctness of quantum programs by testing the correctness and computing the metrics of various small quantum circuits.
  • BitFlipCode: This sample shows how to use a simple quantum error correcting code to protect against errors in a quantum device.
  • PhaseEstimation: This sample introduces iterative phase estimation, an important statistical problem in analyzing the output of quantum programs.

3. Hamiltonian Simulation Samples

  • H₂ Simulation
    • H2SimulationCmdLine: This sample walks through the simulation of molecular hydrogen using the Trotter–Suzuki decomposition.
    • H2SimulationGUI: This sample builds on H2SimulationCmdLine by using the Electron framework and the chart.js package to plot results asynchronously in a cross-platform application.
  • Ising Model Simulation
    • SimpleIsing: This sample walks through constructing the time-evolution operator for the Ising model.
    • IsingGenerators: This sample describes how Hamiltonians may be represented using Microsoft.Quantum.Canon functions.
    • AdiabaticIsing: This sample converts a representation of a Hamiltonian using library data types into unitary time-evolution by the Hamiltonian on qubits.
    • IsingPhaseEstimation: This sample adiabatically prepares the ground state of the Ising model Hamiltonian, and then perform phase estimation to obtain an estimate of the ground state energy.
    • IsingTrotterEvolution: This sample walks through constructing the time-evolution operator for the Ising model using the Trotterization library feature.
  • HubbardSimulation: This sample walks through constructing the time-evolution operator for the 1D Hubbard Simulation model.

4. Interoperability

  • PythonInterop (Windows-only preview): This sample walks through using Python to perform quantum process tomography on an operation written in Q#.

5. Qasm (Quantum Assembler Language)

  • OpenQasm: This sample shows that one can output a subset of the quantum operations of a Q# application in OpenQASM.
  • Qiskit: This sample shows that one can run the quantum operations of a Q# application by using the OpenQASM output on the IBMQuantumExperience by changing the driver.
  • OpenQasmReader: This sample shows that one can convert OpenQasm 2.0 specifications to Q# methods. This allows one to import algorithms written in OpenQasm 2.0 to be used on the Microsoft Q# Simulator. Apart of the barrier gate (which has no meaning in Q#) all gates are converted to Q# constructions.

Docker image

You can use the included Dockerfile to create a docker image with all the necessary libraries to use the Quantum Development Kit to build quantum applications in C#, Python or Jupyter.

Once you have installed Docker, you can use the following commands to get you started:

To build the docker image and tag it iqsharp:

docker build -t iqsharp .

To run the image in the container named iqsharp-container with interactive command-line and redirect container port 8888 to local port 8888 (needed to run jupyter):

docker run -it --name iqsharp-container -p 8888:8888 iqsharp /bin/bash

From the corresponding container command line, you can run the C# version of the Teleportation sample using:

cd ~/Samples/src/Teleportation && dotnet run

Similarly, you can run the Python version of the Teleportation sample using:

cd ~/Samples/src/Teleportation && python

Finally, to start jupyter notebook within the image for the Teleportation sample, use:

cd ~/Samples/src/Teleportation && jupyter notebook --ip= --no-browser 

Once Jupyter has started, you can open in your browser the Teleportation notebook (you will need a token generated by jupyter when it started on the previous step):


Once you're done, to remove container named iqsharp-container:

docker rm --force iqsharp-container
You can’t perform that action at this time.