microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/qubit/examples/SingleQubitDumpMachineDemo.qs

47lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Diagnostics;
3
4 @EntryPoint()
5 operation RunExample() : Unit {
6 // This line allocates a qubit in state |0⟩.
7 use q = Qubit();
8 Message("State |0⟩:");
9
10 // This line prints out the state of the quantum computer.
11 // Since only one qubit is allocated, only its state is printed.
12 DumpMachine();
13
14 // This line changes the qubit from state |0⟩ to state |1⟩.
15 X(q);
16
17 Message("State |1⟩:");
18 DumpMachine();
19
20 // This line changes the qubit to state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩).
21 // That is, this puts the qubit into a superposition where the absolute
22 // value of the probability amplitudes is 1/sqrt(2), which is
23 // approximately 0.707107.
24 H(q);
25
26 Message("State |-⟩:");
27 DumpMachine();
28
29 // This line changes the qubit to state |-i⟩ = (1/sqrt(2))(|0⟩ - i|1⟩).
30 S(q);
31
32 Message("State |-i⟩:");
33 DumpMachine();
34
35 // This will put the qubit into an uneven superposition, where the
36 // amplitudes of |0⟩ and |1⟩ have different absolute values.
37 Rx(2.0, q);
38 Ry(1.0, q);
39
40 Message("Uneven superposition state:");
41 DumpMachine();
42
43 // This line returns the qubit to state |0⟩, which must be done before
44 // the qubit is released or otherwise a runtime error might occur.
45 Reset(q);
46 }
47}
48