forked from microsoft/Quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.qs
51 lines (44 loc) · 1.35 KB
/
Utils.qs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// This file includes some utility functions to set and
// verify |+> and |-> quantum states.
namespace Microsoft.Quantum.Samples.Teleportation {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;
/// # Summary
/// Sets the qubit's state to |+⟩.
operation SetToPlus(q: Qubit) : Unit {
Reset(q);
H(q);
}
/// # Summary
/// Sets the qubit's state to |−⟩.
operation SetToMinus(q: Qubit) : Unit {
Reset(q);
X(q);
H(q);
}
/// # Summary
/// Returns true if qubit is |+> (assumes qubit is either |+> or |->)
operation IsPlus(q: Qubit) : Bool {
return (Measure([PauliX], [q]) == Zero);
}
/// # Summary
/// Returns true if qubit is |-> (assumes qubit is either |+> or |->)
operation IsMinus(q: Qubit) : Bool {
return (Measure([PauliX], [q]) == One);
}
/// # Summary
/// Randomly prepares the qubit into |+> or |->
operation PrepareRandomMessage(q: Qubit) : Unit {
let choice = RandomInt(2);
if (choice == 0) {
Message("Sending |->");
SetToMinus(q);
} else {
Message("Sending |+>");
SetToPlus(q);
}
}
}