-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_not.qs
37 lines (31 loc) · 1.31 KB
/
root_not.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
namespace RootNot {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Math; // Include this line
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Measurement;
operation ApplyRootOfNot(qubit: Qubit) : Unit {
// First root-of-not gate
H(qubit);
Rz(-PI() / 2.0, qubit); // Corrected line
H(qubit);
// Quantum barrier is not necessary in Q# as it's mostly a hardware consideration for optimization
// Second root-of-not gate (repeating the operation)
H(qubit);
Rz(-PI() / 2.0, qubit); // Corrected line
H(qubit);
// Again, no need for a barrier in Q#
}
@EntryPoint()
operation DemonstrateRootOfNot() : Result {
use qubit = Qubit();
// Initialize the qubit to |0⟩ state (Reset is implicit on allocation in Q#)
ApplyRootOfNot(qubit);
// Normally, you would measure the qubit here if you wanted to observe its state.
// For state vector simulation to see the effects, you would use the DumpMachine() function in simulation.
// Measurement and resetting for cleanliness, though not strictly needed for demonstration
let result = M(qubit);
Message($"Measurement result: {result}");
Reset(qubit);
return result;
}
}