microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/getting_started/BellPair.qs
34lines · modecode
| 1 | /// # Summary |
| 2 | /// Bell Pair sample |
| 3 | /// |
| 4 | /// # Description |
| 5 | /// Bell pairs are specific quantum states of two qubits that represent |
| 6 | /// the simplest (and maximal) examples of quantum entanglement. This sample |
| 7 | /// prepares |Φ⁺⟩ = (|00⟩+|11⟩)/√2. For other Bell states see BellStates.qs |
| 8 | /// |
| 9 | /// # References |
| 10 | /// - [Bell state](https://en.wikipedia.org/wiki/Bell_state) |
| 11 | operation Main() : (Result, Result) { |
| 12 | // Allocate the two qubits that will be used to create a Bell pair. |
| 13 | use (q1, q2) = (Qubit(), Qubit()); |
| 14 | |
| 15 | // Create Bell pair by calling `PrepareBellPair` operation defined below. |
| 16 | PrepareBellPair(q1, q2); |
| 17 | |
| 18 | // Show the state of qubits using the `DumpMachine` function. |
| 19 | Std.Diagnostics.DumpMachine(); |
| 20 | |
| 21 | // Measure the two qubits and reset them. Return measurement results. |
| 22 | (MResetZ(q1), MResetZ(q2)) |
| 23 | } |
| 24 | |
| 25 | /// # Summary |
| 26 | /// Prepare Bell pair |Φ⁺⟩ = (|00⟩+|11⟩)/√2 on two qubits. |
| 27 | /// Qubits are assumed to be in |00⟩ state. |
| 28 | operation PrepareBellPair(q1 : Qubit, q2 : Qubit) : Unit { |
| 29 | // Set qubit `q1` in superposition of |0⟩ and |1⟩ by applying a Hadamard gate. |
| 30 | H(q1); |
| 31 | |
| 32 | // Entangle the two qubits `q1` and `q2` using the `CNOT` gate. |
| 33 | CNOT(q1, q2); |
| 34 | } |
| 35 | |