microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/qubit/examples/MultiQubitDumpMachineDemo.qs
30lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Diagnostics; |
| 3 | |
| 4 | @EntryPoint() |
| 5 | operation MultiQubitDumpMachineDemo() : Unit { |
| 6 | // This line allocates two qubits in state |00⟩. |
| 7 | use qs = Qubit[2]; |
| 8 | Message("State |00⟩:"); |
| 9 | |
| 10 | // This line prints out the state of the quantum system. |
| 11 | DumpMachine(); |
| 12 | |
| 13 | // X gate changes the second qubit into state |1⟩. |
| 14 | // The entire system is now in state |01⟩, or, in little-endian notation, |2⟩. |
| 15 | X(qs[1]); |
| 16 | Message("State |01⟩:"); |
| 17 | DumpMachine(); |
| 18 | |
| 19 | CNOT(qs[1], qs[0]); |
| 20 | Rx(1.0, qs[0]); |
| 21 | Ry(2.0, qs[1]); |
| 22 | Rz(3.0, qs[1]); |
| 23 | |
| 24 | Message("Uneven superposition state:"); |
| 25 | DumpMachine(); |
| 26 | |
| 27 | // This line returns the qubits to state |0⟩ before releasing them. |
| 28 | ResetAll(qs); |
| 29 | } |
| 30 | } |