Convert Figma logo to code with AI

microsoft logoQuantum

Microsoft Quantum Development Kit Samples

3,869
919
3,869
53

Top Related Projects

5,174

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

4,257

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.

1,403

A Python library for quantum programming using Quil.

1,671

QuTiP: Quantum Toolbox in Python

Quick Overview

Microsoft Quantum is an open-source project that provides a comprehensive quantum computing development kit. It includes Q#, a domain-specific programming language for quantum computing, along with libraries, tools, and documentation to help developers create quantum algorithms and applications.

Pros

  • Comprehensive ecosystem for quantum computing development
  • Strong integration with classical programming languages like Python and C#
  • Extensive documentation and learning resources
  • Supports both quantum simulation and execution on real quantum hardware

Cons

  • Steep learning curve for those new to quantum computing concepts
  • Limited availability of real quantum hardware for running programs
  • Performance constraints when simulating large quantum systems
  • Rapidly evolving field may lead to frequent updates and changes

Code Examples

  1. Creating a simple superposition:
operation CreateSuperposition() : Result {
    use q = Qubit();
    H(q);
    return M(q);
}
  1. Implementing a quantum teleportation protocol:
operation Teleport(msg : Qubit, target : Qubit) : Unit {
    use here = Qubit();
    H(here);
    CNOT(here, target);
    CNOT(msg, here);
    H(msg);
    let m1 = M(msg);
    let m2 = M(here);
    if (m1 == One) { Z(target); }
    if (m2 == One) { X(target); }
}
  1. Grover's search algorithm implementation:
operation GroverSearch(oracle : (Qubit[] => Unit is Adj), numQubits : Int, numIterations : Int) : Result[] {
    use qubits = Qubit[numQubits];
    ApplyToEach(H, qubits);
    for _ in 1..numIterations {
        oracle(qubits);
        ApplyToEach(H, qubits);
        ApplyToEach(X, qubits);
        Controlled Z(Most(qubits), Tail(qubits));
        ApplyToEach(X, qubits);
        ApplyToEach(H, qubits);
    }
    return MultiM(qubits);
}

Getting Started

  1. Install the Quantum Development Kit:
dotnet new -i Microsoft.Quantum.ProjectTemplates
  1. Create a new Q# project:
dotnet new console -lang Q# -o QuantumProject
cd QuantumProject
  1. Write your Q# code in the Program.qs file.

  2. Run your quantum program:

dotnet run

For more detailed instructions and advanced usage, refer to the official Microsoft Quantum documentation.

Competitor Comparisons

5,174

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

Pros of Qiskit

  • Larger and more active community, with more frequent updates and contributions
  • Broader support for various quantum hardware providers beyond IBM's own devices
  • More comprehensive documentation and educational resources for beginners

Cons of Qiskit

  • Steeper learning curve for users new to quantum computing
  • Less integration with classical computing frameworks compared to Q#

Code Comparison

Qiskit (Python):

from qiskit import QuantumCircuit, execute, Aer

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend, shots=1000)
result = job.result()
print(result.get_counts(qc))

Q# (Microsoft Quantum):

operation BellTest() : (Int, Int, Int, Int) {
    using (qubits = Qubit[2]) {
        H(qubits[0]);
        CNOT(qubits[0], qubits[1]);
        let res = MultiM(qubits);
        return (M(qubits[0]) == Zero ? 0 | 1,
                M(qubits[1]) == Zero ? 0 | 1,
                M(res[0]) == Zero ? 0 | 1,
                M(res[1]) == Zero ? 0 | 1);
    }
}

Both examples create a simple Bell state and measure the qubits. Qiskit uses Python and provides a more intuitive interface for classical programmers, while Q# offers a specialized language for quantum computing with tighter integration to the .NET ecosystem.

4,257

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

Pros of Cirq

  • More flexible and customizable, allowing for lower-level control of quantum circuits
  • Larger and more active community, with frequent updates and contributions
  • Better integration with other Google quantum computing tools and services

Cons of Cirq

  • Steeper learning curve, especially for beginners in quantum computing
  • Less comprehensive documentation compared to Quantum
  • Primarily focused on gate-based quantum computing, with limited support for other paradigms

Code Comparison

Cirq example:

import cirq

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
    cirq.H(q0),
    cirq.CNOT(q0, q1),
    cirq.measure(q0, q1, key='result')
)

Quantum example:

operation BellState() : (Result, Result) {
    use (q0, q1) = (Qubit(), Qubit());
    H(q0);
    CNOT(q0, q1);
    return (M(q0), M(q1));
}

Both examples create a simple Bell state, but Cirq uses a more Python-centric approach, while Quantum uses Q# for a more quantum-specific language.

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.

Pros of PennyLane

  • More flexible and hardware-agnostic, supporting multiple quantum computing platforms
  • Stronger focus on quantum machine learning and variational quantum algorithms
  • Active community with frequent updates and contributions

Cons of PennyLane

  • Less comprehensive documentation compared to Quantum Development Kit
  • Steeper learning curve for beginners in quantum computing
  • Smaller ecosystem of tools and resources

Code Comparison

PennyLane:

import pennylane as qml

dev = qml.device('default.qubit', wires=2)

@qml.qnode(dev)
def circuit(params):
    qml.RX(params[0], wires=0)
    qml.RY(params[1], wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0))

Quantum:

operation SimpleCircuit(params : (Double, Double)) : Result {
    use q = Qubit[2];
    Rx(params[0], q[0]);
    Ry(params[1], q[1]);
    CNOT(q[0], q[1]);
    return M(q[0]);
}

Both repositories offer powerful tools for quantum computing, with PennyLane focusing on cross-platform compatibility and quantum machine learning, while Quantum provides a more comprehensive ecosystem for Q# development. The choice between them depends on specific project requirements and familiarity with quantum computing concepts.

1,403

A Python library for quantum programming using Quil.

Pros of pyquil

  • Focused on real quantum hardware integration, particularly with Rigetti's quantum processors
  • More lightweight and specialized for quantum circuit construction and execution
  • Provides lower-level control over quantum operations and hardware-specific optimizations

Cons of pyquil

  • Limited to Rigetti's ecosystem and hardware
  • Smaller community and fewer resources compared to Microsoft's broader quantum development kit
  • Less comprehensive documentation and tutorials for beginners

Code Comparison

pyquil:

from pyquil import Program
from pyquil.gates import H, CNOT

p = Program()
p += H(0)
p += CNOT(0, 1)

Quantum:

using Microsoft.Quantum.Intrinsic;

operation BellPair(q1 : Qubit, q2 : Qubit) : Unit {
    H(q1);
    CNOT(q1, q2);
}

Both examples create a simple Bell pair, demonstrating the syntax differences between the two frameworks. pyquil uses a more procedural approach, while Quantum employs a more structured, operation-based model.

1,671

QuTiP: Quantum Toolbox in Python

Pros of QuTiP

  • More mature and established project with a larger community
  • Broader focus on quantum optics and open quantum systems
  • Extensive documentation and tutorials available

Cons of QuTiP

  • Less integration with cloud services and quantum hardware
  • Primarily focused on simulation rather than full-stack quantum computing
  • Steeper learning curve for beginners in quantum computing

Code Comparison

QuTiP example:

import qutip as qt
q = qt.Qobj([[1], [0]])  # Create a qubit in the |0⟩ state
H = qt.sigmaz()  # Hamiltonian
result = qt.sesolve(H, q, [0, 1, 2])  # Time evolution

Quantum example:

operation PrepareAndMeasure() : Result {
    use q = Qubit();
    H(q);
    return M(q);
}

QuTiP focuses on numerical simulations and provides a more physics-oriented approach, while Quantum emphasizes Q# programming for quantum algorithms and hardware integration. QuTiP offers more flexibility for custom quantum systems, whereas Quantum provides a more structured environment for quantum circuit design and execution on various backends.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

## DEPRECATION NOTICE

This repository is deprecated.

For the Modern QDK repository, please visit Microsoft/qsharp.

For samples that use the Azure Quantum Python package, please visit the Azure Quantum Python repository.

You can also try out the Modern QDK in VS Code for Web at vscode.dev/quantum.

For more information about the Modern QDK and Azure Quantum, visit https://aka.ms/AQ/Documentation.

Classic QDK

Binder

These samples demonstrate the use of the Quantum Development Kit for a variety of different quantum computing tasks.

Each sample is self-contained in a folder, and demonstrates how to use Q# to develop quantum applications.

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 README.md files for each sample, along with complete installation instructions.

Getting started

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.

For a quick guide on how to set up a development environment from scratch using Visual Studio Code or GitHub Codespaces, see here.

A Docker image definition is also provided for your convenience, see here for instructions on how to build and use it.

First samples

If you're new to quantum or to the Quantum Development Kit, we recommend starting with the Getting Started samples.

After setting up your development environment using one of the options above, try to browse to samples/getting-started/teleportation via the terminal and run dotnet run. You should see something like the following:

Round 1: Sent False, got False.
Teleportation successful!
Round 2: Sent True, got True.
Teleportation successful!
Round 3: Sent False, got False.
Teleportation successful!
Round 4: Sent False, got False.
Teleportation successful!
Round 5: Sent False, got False.
Teleportation successful!
Round 6: Sent False, got False.
Teleportation successful!
Round 7: Sent True, got True.
Teleportation successful!
Round 8: Sent False, got False.
Teleportation successful!

Congratulations, you can now start quantum programming!

Going further

As you go further with quantum development, we provide several different categories of samples for you to explore:

  • Algorithms: These samples demonstrate various quantum algorithms, such as database search and integer factorization.
  • Arithmetic: These samples show how to coherently transform arithmetic data.
  • Characterization: These samples demonstrate how to learn properties of quantum systems from classical data.
  • Chemistry: These samples demonstrate the use of the Quantum Chemistry library.
  • Diagnostics: These samples show how to diagnose and test Q# applications.
  • Error Correction: These samples show how to work with quantum error correcting codes in Q# programs.
  • Interoperability: These samples show how to use Q# with different host languages.
  • Machine Learning: These samples demonstrate how to train simple sequential models on half-moons and wine datasets.
  • Numerics: The samples in this folder show how to use the numerics library.
  • Runtime: These samples show how to work with the Q# simulation runtime.
  • Simulation: These samples show how to simulate evolution under different Hamiltonians.

We also encourage taking a look at the unit tests used to check the correctness of the Quantum Development Kit samples.

Setting up your development environment

This repo contains several configuration files that will make it easy to get started with coding. Below we lay out some instructions for getting started with VSCode or with Jupyter notebooks.

Visual Studio Code

If you prefer to develop code locally, we recommend to install an editor such as Visual Studio Code. Make sure to install the .NET Core SDK 3.1 or later on your local machine. For more detailed instructions on how to set up VS Code for development with the QDK, go to our docs here.

Once you have installed VS Code and the .NET Core SDK, download this repository to your computer and open the folder in VS Code. The editor will automatically recognize the files in the .vscode folder and request you to install the recommended extension. This includes the Microsoft Quantum Development Kit for Visual Studio Code extension, which is the fastest way to get started with the QDK.

Open a terminal to start running your first samples (see here).

Running a Jupyter Notebook with Docker

Another way to quickly start developing in Q# is to use Docker and launch a Jupyter notebook on your local machine. 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/getting-started/teleportation && dotnet run

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

cd ~/samples/getting-started/teleportation && python host.py

Finally, to start Jupyter Notebook within the image for the Teleportation sample, use:

cd ~/samples/getting-started/teleportation && jupyter notebook --ip=0.0.0.0 --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):

http://localhost:8888/notebooks/Notebook.ipynb

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

docker rm --force iqsharp-container