365 Architect

Q# — Microsoft's Quantum Language

Definition

Q# (pronounced "Q sharp") is Microsoft's domain-specific programming language for quantum algorithm development. Developed alongside the Quantum Development Kit (QDK) and first released in 2017, Q# takes a high-level, hardware-agnostic approach — developers focus on algorithm logic while the compiler and runtime handle mapping to target hardware. Q# is deeply integrated with Visual Studio, VS Code, and Azure Quantum, enabling hybrid quantum-classical workflows that span cloud and local environments.

Usage and Benefits

Usage

Q# is a standalone language with an F#-like syntax. It is typically called from a classical host program written in C#, Python, or .NET. Quantum operations are expressed as operation blocks; qubits are allocated and automatically released.

Basic example — Bell state measurement:

namespace Bell {
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Measurement;

    @EntryPoint()
    operation MeasureBell() : (Result, Result) {
        use (q0, q1) = (Qubit(), Qubit());
        H(q0);
        CNOT(q0, q1);
        let m0 = MResetZ(q0);
        let m1 = MResetZ(q1);
        return (m0, m1);
    }
}

Run from Python:

import qsharp
from Bell import MeasureBell

result = MeasureBell()
print(result)  # (One, One) or (Zero, Zero)

Benefits

  • Hardware-agnostic — Same Q# code can target Azure Quantum simulators, IonQ traps, Quantinuum trapped ions, and Rigetti superconducting processors.
  • Resource estimationMicrosoft.Quantum.ResourceEstimation estimates logical and physical qubit counts, T-gate counts, and runtime before running on hardware.
  • Type-safe and functor-drivenAdjoint and Controlled functors automatically generate inverse and controlled versions of operations.
  • IDE integration — Full IntelliSense, debugging, and quantum trace visualisation in Visual Studio and VS Code.
  • Classical host flexibility — Orchestrate quantum operations from C#, Python, or standalone Q# scripts.

Functor Example

operation PrepareState(q : Qubit) : Unit {
    H(q);
    T(q);
}

operation PrepareStateAdjoint(q : Qubit) : Unit {
    Adjoint PrepareState(q);
}

The Adjoint functor automatically inverts the operation — no manual implementation needed.

Use Cases

Domain Application Why Q#
Chemistry Hamiltonian simulation High-level Trotter decomposition libraries
Resource estimation Fault-tolerant cost analysis Built-in resource estimator
Cryptanalysis Shor's algorithm, Grover's search Type-safe oracles + functors
Optimisation QUBO solvers on Azure Quantum Multi-provider backend switching
Education Quantum computing courses Clean syntax, strong typing, great IDE support

How to Use Q#

Installation (VS Code)

  1. Install the Azure Quantum Development Kit extension from the VS Code marketplace.
  2. Create a .qs file and start writing Q#.
  3. Use the built-in simulator to run and debug locally.

Installation (Python)

pip install qsharp

Connecting to Azure Quantum

import qsharp
from azure.quantum import Workspace

workspace = Workspace(
    subscription_id="...",
    resource_group="...",
    name="...",
    location="...",
)

qsharp.init(workspace=workspace)
qsharp.evaluate("MeasureBell()")

Resource Estimation

open Microsoft.Quantum.ResourceEstimation;

operation EstimateShorsAlgorithm() : Unit {
    use qubits = Qubit[2048];
    // ...
    let estimates = ResourceEstimator.Estimate(ShorsAlgorithm());
    Message($"T gates: {estimates.tCount}");
}

Resources and References

Share on LinkedIn