forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeleportationSample.qs
More file actions
129 lines (105 loc) · 5.15 KB
/
TeleportationSample.qs
File metadata and controls
129 lines (105 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Examples.Teleportation {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;
//////////////////////////////////////////////////////////////////////////
// Introduction //////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Quantum teleportation provides a way of moving a quantum state from one
// location to another without having to move physical particle(s) along
// with it. This is done with the help of previously shared quantum
// entanglement between the sending and the receiving locations and
// classical communication.
//////////////////////////////////////////////////////////////////////////
// Teleportation /////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// We approach teleportation in two steps. First, we define how to
// teleport the state of a qubit to another qubit. To do so, we define
// teleportation as an operation, one of the fundamental building blocks
// of a Q# program.
// Most operations which act on qubits to modify their state in some way
// will not return any useful information to the caller. We represent this
// by a return value of (), meaning the empty tuple. Since all operations
// take a tuple and return a tuple, that represents that the return value
// is unimportant.
/// # Summary
/// Sends the state of one qubit to a target qubit by using
/// teleportation.
///
/// # Input
/// ## msg
/// A qubit whose state we wish to send.
/// ## there
/// A qubit initially in the |0〉 state that we want to send
/// the state of msg to.
operation Teleport(msg : Qubit, there : Qubit) : () {
body {
using (register = Qubit[1]) {
// Ask for an auxillary qubit that we can use to prepare
// for teleportation.
let here = register[0];
// Create some entanglement that we can use to send our message.
H(here);
CNOT(here, there);
// Move our message into the entangled pair.
CNOT(msg, here);
H(msg);
// Measure out the entanglement.
if (M(msg) == One) { Z(there); }
if (M(here) == One) { X(there); }
// Reset our "here" qubit before releasing it.
Reset(here);
}
}
}
// One can use quantum teleportation circuit to send an unobserved
// (unknown) classical message from source qubit to target qubit
// by sending specific (known) classical information from source
// to target.
/// # Summary
/// Uses teleportation to send a classical message from one qubit
/// to another.
///
/// # Input
/// ## message
/// If `true`, the source qubit (`here`) is prepared in the
/// |1〉 state, otherwise the source qubit is prepared in |0〉.
///
/// ## Output
/// The result of a Z-basis measurement on the teleported qubit,
/// represented as a Bool.
operation TeleportClassicalMessage(message : Bool) : Bool {
body {
mutable measurement = false;
using (register = Qubit[2]) {
// Ask for some qubits that we can use to teleport.
let msg = register[0];
let there = register[1];
// Encode the message we want to send.
if (message) { X(msg); }
// Use the operation we defined above.
Teleport(msg, there);
// Check what message was sent.
if (M(there) == One) { set measurement = true; }
// Reset all of the qubits that we used before releasing
// them.
ResetAll(register);
}
return measurement;
}
}
//////////////////////////////////////////////////////////////////////////
// Other teleportation scenarios not illustrated here
//////////////////////////////////////////////////////////////////////////
//
// ● Teleport a rotation. Rotate a basis state by a certain angle φ ∈ [0, 2π),
// for example by preparing Rₓ(φ) |0〉, and teleport the rotated state to the target qubit.
// When successful, the target qubit captures the angle φ [although, on course one does
// not have classical access to its value].
// ● "Super dense coding". Given an EPR state |β〉 shared between the source and target
// qubits, the source can encode two classical bits a,b by applying Z^b X^a to its half
// of |β〉. Both bits can be recovered on the target by measurement in the Bell basis.
// For details refer to discussion and code in Unit Testing Sample, in file SuperdenseCoding.qs.
//////////////////////////////////////////////////////////////////////////
}