microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
logo

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/getting_started/Superposition.qs

22lines · modepreview

/// # Summary
/// Superposition sample
///
/// # Description
/// This Q# program sets a qubit in a superposition of the computational basis
/// states |0〉 and |1〉 by applying a Hadamard transformation.
operation Main() : Result {
    // Allocate a qubit. Qubit is in |0〉 state after allocation.
    use qubit = Qubit();
    // Qubits are only accessible for the duration of the scope where they
    // are allocated and are automatically released at the end of the scope.

    // Set the qubit in superposition by applying a Hadamard transformation.
    H(qubit);

    // Show the quantum state (when running on a simulator).
    Std.Diagnostics.DumpMachine();

    // Measure then reset the qubit. Return the result.
    // There is a 50% probability of measuring either `Zero` or `One`.
    MResetZ(qubit)
}