Skip to content

Commit

Permalink
Hadamard operation H
Browse files Browse the repository at this point in the history
A simple example is the following program, which allocates one qubit in the  | 0 ⟩  state, then applies a Hadamard operation H to it and measures the result in the PauliZ basis.
  • Loading branch information
pouriya73 authored Apr 2, 2022
1 parent 5108f5c commit 4d00cb2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions PauliZ.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;

}

0 comments on commit 4d00cb2

Please sign in to comment.