microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
be82821236a00686b004bc7fe619ad16904f7997

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/OpenQASM/OpenQasmHelloWorld.qasm

25lines · modecode

1// OpenQASM Hello World sample
2//
3// This is one of the simplest OpenQASM programs that contains quantum part.
4// It uses one qubit, resets it and and immediately measures it.
5// Since the qubit is in |0〉 state after reset
6// such measurement will always yield `Zero`.
7
8// OpenQASM version identifier.
9OPENQASM 3;
10
11// Declares use of a single qubit and names it `q`.
12// All qubits must be declared in a global scope.
13qubit q;
14
15// Qubits are initially in an undefined state.
16// Reset is used here to initialize qubit to a |0〉 state.
17reset q;
18
19// Measures qubit and stores the result in a classical bit.
20// The qubit is in |0〉 state after reset, so the `b` will be 0.
21bit b = measure q;
22
23// Note, that the content of all classical variables
24// are reported to the user at the end of the program
25// unless explicit output declarations exist.
26