microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/multi_qubit_systems/examples/MultiQubitSystems.qs
33lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Diagnostics; |
| 3 | |
| 4 | @EntryPoint() |
| 5 | operation MultiQubitSystemsDemo () : Unit { |
| 6 | // This allocates an array of 2 qubits, each of them in state |0⟩. |
| 7 | // The overall state of the system is |00⟩. |
| 8 | use qs = Qubit[2]; |
| 9 | // X gate changes the first qubit into state |1⟩. |
| 10 | X(qs[0]); |
| 11 | Message("The system in now in state |10⟩:"); |
| 12 | DumpMachine(); |
| 13 | |
| 14 | // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩). |
| 15 | H(qs[1]); |
| 16 | Message("The system in now in state (1/sqrt(2))(|10⟩ + |11⟩):"); |
| 17 | DumpMachine(); |
| 18 | |
| 19 | // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩) |
| 20 | H(qs[0]); |
| 21 | Message("The system in now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):"); |
| 22 | DumpMachine(); |
| 23 | |
| 24 | // The next lines entangle the qubits (don't worry about what exactly they do for now). |
| 25 | H(qs[1]); |
| 26 | CNOT(qs[0], qs[1]); |
| 27 | Message("The system in now in entangled state 0.5(|00⟩ - |11⟩):"); |
| 28 | DumpMachine(); |
| 29 | |
| 30 | // This returns the system into state |00⟩. |
| 31 | ResetAll(qs); |
| 32 | } |
| 33 | } |