microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
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. |
| 9 | OPENQASM 3; |
| 10 | |
| 11 | // Declares use of a single qubit and names it `q`. |
| 12 | // All qubits must be declared in a global scope. |
| 13 | qubit q; |
| 14 | |
| 15 | // Qubits are initially in an undefined state. |
| 16 | // Reset is used here to initialize qubit to a |0〉 state. |
| 17 | reset 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. |
| 21 | bit 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 | |