forked from pouriya73/Quantum-computer-programming-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPauliZ.qs
More file actions
17 lines (16 loc) · 619 Bytes
/
PauliZ.qs
File metadata and controls
17 lines (16 loc) · 619 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@EntryPoint()
operation MeasureOneQubit() : Result {
// The following using block creates a fresh qubit and initializes it
// in the |0〉 state.
use qubit = Qubit();
// We apply a Hadamard operation H to the state, thereby preparing the
// state 1 / sqrt(2) (|0〉 + |1〉).
H(qubit);
// Now we measure the qubit in Z-basis.
let result = M(qubit);
// As the qubit is now in an eigenstate of the measurement operator,
// we reset the qubit before releasing it.
if result == One { X(qubit); }
// Finally, we return the result of the measurement.
return result;
}