microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
samples/getting_started/QuantumHelloWorld.qs
20lines · modeblame
c97c05a1DmitryVasilevsky1 years ago | 1 | /// # Summary |
| 2 | /// Quantum Hello World sample | |
| 3 | /// | |
| 4 | /// # Description | |
| 5 | /// This is one of the simplest Q# programs that contains quantum part. | |
| 6 | /// This code prints the message then allocates a qubit and immediately measures it. | |
| 7 | /// Since the qubit starts in |0〉 state such measurement will always yield `Zero`. | |
| 8 | operation Main() : Result { | |
| 9 | // Print the message (when running on a simulator). | |
| 10 | Message("Hello world!"); | |
| 11 | | |
| 12 | // Allocate a qubit. Qubit is in |0〉 state after allocation. | |
| 13 | use qubit = Qubit(); | |
| 14 | | |
| 15 | // Measure then reset the qubit. Last statement returns result from `Main`. | |
| 16 | // Measurement result is `Zero` as the qubit is in |0〉 state. | |
| 17 | MResetZ(qubit) | |
| 18 | | |
| 19 | // Note, that `qubit` is automatically deallocated at the end of the block. | |
| 20 | } |