microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
be82821236a00686b004bc7fe619ad16904f7997

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
7OPENQASM 3.0;
8include "stdgates.inc";
9
10// Allocate `qAlice`, `qBob` qubits
11qubit qAlice;
12qubit qBob;
13
14// Reset and entangle `qAlice`, `qBob` qubits
15reset qAlice;
16reset qBob;
17h qAlice;
18cx 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โŸฉ
23qubit qToTeleport;
24reset qToTeleport;
25rx(0.7) qToTeleport;
26
27// Prepare the message by entangling `qToTeleport` and `qAlice` qubits
28cx qToTeleport, qAlice;
29h qToTeleport;
30
31// Obtain classical measurement results b1 and b2 at Alice's site.
32bit b1 = measure qToTeleport;
33bit 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.
38if (b1) {
39 z qBob;
40}
41if (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
47rx(-0.7) qBob;
48output bit shouldBeZero;
49shouldBeZero = measure qBob;
50
51// Each execution of this program should result in Zero.
52