1
0

sample.qsharp.txt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Run this cell using Ctrl+Enter (⌘+Enter on Mac)
  2. // Then run the next cell to see the output
  3. open Microsoft.Quantum.Diagnostics;
  4. operation QubitsDemo () : Unit {
  5. // This line allocates a qubit in state |0⟩
  6. use q = Qubit();
  7. Message("State |0⟩:");
  8. // This line prints out the state of the quantum computer
  9. // Since only one qubit is allocated, only its state is printed
  10. DumpMachine();
  11. // This line changes the qubit from state |0⟩ to state |1⟩
  12. X(q);
  13. Message("State |1⟩:");
  14. DumpMachine();
  15. // This line changes the qubit to state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)
  16. // That is, this puts the qubit into a superposition
  17. // 1/sqrt(2) is approximately 0.707107
  18. H(q);
  19. Message("State |-⟩:");
  20. DumpMachine();
  21. // This line changes the qubit to state |-i⟩ = (1/sqrt(2))(|0⟩ - i|1⟩)
  22. S(q);
  23. Message("State |-i⟩:");
  24. DumpMachine();
  25. // This will put the qubit into an uneven superposition,
  26. // where the amplitudes of |0⟩ and |1⟩ have different moduli
  27. Rx(2.0, q);
  28. Ry(1.0, q);
  29. Message("Uneven superposition state:");
  30. DumpMachine();
  31. // This line returns the qubit to state |0⟩
  32. Reset(q);
  33. }