microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/OpenQASM/BellPair.qasm
31lines · modecode
| 1 | // OpenQASM Bell Pair sample |
| 2 | // |
| 3 | // Bell pairs are specific quantum states of two qubits that represent |
| 4 | // the simplest (and maximal) examples of quantum entanglement. This sample |
| 5 | // prepares |Φ⁺⟩ = (|00⟩+|11⟩)/√2. |
| 6 | // |
| 7 | // See [Bell state](https://en.wikipedia.org/wiki/Bell_state) |
| 8 | |
| 9 | OPENQASM 3; |
| 10 | include "stdgates.inc"; |
| 11 | |
| 12 | // Declares use of qubits `q1` and `q2`. |
| 13 | qubit q1; |
| 14 | qubit q2; |
| 15 | |
| 16 | // Qubits are initially in an undefined state. |
| 17 | // Reset is used here to initialize qubits to |0⟩ state. |
| 18 | reset q1; |
| 19 | reset q2; |
| 20 | |
| 21 | // Set qubit `q1` in superposition of |0⟩ and |1⟩ by applying a Hadamard gate. |
| 22 | h q1; |
| 23 | // Entangle the two qubits `q1` and `q2` using the `cx` gate. |
| 24 | cx q1, q2; |
| 25 | |
| 26 | // Measure the two qubits and store results in classical variables `r1` and `r2`. |
| 27 | bit r1 = measure q1; |
| 28 | bit r2 = measure q2; |
| 29 | |
| 30 | // Note, that the reported result (r1, r2) |
| 31 | // will always be either (Zero, Zero) or (One, One). |
| 32 | |