microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/algorithms/Entanglement.qs
32lines · modecode
| 1 | /// # Sample |
| 2 | /// Entanglement |
| 3 | /// |
| 4 | /// # Description |
| 5 | /// Qubits are said to be entangled when the state of each one of them cannot be |
| 6 | /// described independently from the state of the others. |
| 7 | /// |
| 8 | /// This Q# program entangles two qubits. |
| 9 | namespace Sample { |
| 10 | open Microsoft.Quantum.Diagnostics; |
| 11 | |
| 12 | @EntryPoint() |
| 13 | operation EntangleQubits() : (Result, Result) { |
| 14 | // Allocate the two qubits that will be entangled. |
| 15 | use (q1, q2) = (Qubit(), Qubit()); |
| 16 | |
| 17 | // Set the first qubit in superposition by calling the `H` operation, |
| 18 | // which applies a Hadamard transformation to the qubit. |
| 19 | // Then, entangle the two qubits using the `CNOT` operation. |
| 20 | H(q1); |
| 21 | CNOT(q1, q2); |
| 22 | |
| 23 | // Show the entangled state using the `DumpMachine` function. |
| 24 | DumpMachine(); |
| 25 | |
| 26 | // Measurements of entangled qubits are always correlated. |
| 27 | let (m1, m2) = (M(q1), M(q2)); |
| 28 | Reset(q1); |
| 29 | Reset(q2); |
| 30 | return (m1, m2); |
| 31 | } |
| 32 | } |