microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/OpenQASM/Teleportation.qasm
51lines ยท modecode
| 1 | // OpenQASM simple quantum teleportation sample |
| 2 | // |
| 3 | // This OpenQASM program demonstrates how to teleport quantum state |
| 4 | // by communicating two classical bits and using previously entangled qubits. |
| 5 | // This code teleports one specific state, but any state can be teleported. |
| 6 | |
| 7 | OPENQASM 3.0; |
| 8 | include "stdgates.inc"; |
| 9 | |
| 10 | // Allocate `qAlice`, `qBob` qubits |
| 11 | qubit qAlice; |
| 12 | qubit qBob; |
| 13 | |
| 14 | // Reset and entangle `qAlice`, `qBob` qubits |
| 15 | reset qAlice; |
| 16 | reset qBob; |
| 17 | h qAlice; |
| 18 | cx qAlice, qBob; |
| 19 | |
| 20 | // From now on qubits `qAlice` and `qBob` will not interact directly. |
| 21 | |
| 22 | // Allocate `qToTeleport` qubit and prepare it to be |๐โฉโ0.9394|0โฉโ0.3429๐|1โฉ |
| 23 | qubit qToTeleport; |
| 24 | reset qToTeleport; |
| 25 | rx(0.7) qToTeleport; |
| 26 | |
| 27 | // Prepare the message by entangling `qToTeleport` and `qAlice` qubits |
| 28 | cx qToTeleport, qAlice; |
| 29 | h qToTeleport; |
| 30 | |
| 31 | // Obtain classical measurement results b1 and b2 at Alice's site. |
| 32 | bit b1 = measure qToTeleport; |
| 33 | bit b2 = measure qAlice; |
| 34 | |
| 35 | // At this point classical bits b1 and b2 are "sent" to the Bob's site. |
| 36 | |
| 37 | // Decode the message by applying adjustments based on classical data b1 and b2. |
| 38 | if (b1) { |
| 39 | z qBob; |
| 40 | } |
| 41 | if (b2) { |
| 42 | x qBob; |
| 43 | } |
| 44 | |
| 45 | // Obtained messages should be |๐โฉโ0.9394|0โฉโ0.3429๐|1โฉ |
| 46 | // Rotate back to |0โฉ state and measure |
| 47 | rx(-0.7) qBob; |
| 48 | output bit shouldBeZero; |
| 49 | shouldBeZero = measure qBob; |
| 50 | |
| 51 | // Each execution of this program should result in Zero. |
| 52 | |