This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
/
QuantumPhaseEstimationTests.qs
53 lines (43 loc) · 1.89 KB
/
QuantumPhaseEstimationTests.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
52
namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Oracles;
open Microsoft.Quantum.Characterization;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Diagnostics;
/// # Summary
/// Assert that the QuantumPhaseEstimation operation for the T gate
/// return 0000 in the controlRegister when targetState is 0 and
/// return 0010 when the targetState is 1
@Test("QuantumSimulator")
operation TestQuantumPhaseEstimation() : Unit {
let oracle = DiscreteOracle(ApplyTOracle);
use qPhase = Qubit[5];
let phase = BigEndian(qPhase[0 .. 3]);
let state = qPhase[4];
QuantumPhaseEstimation(oracle, [state], phase);
let complexOne = Complex(1.0, 0.0);
let complexZero = Complex(0.0, 0.0);
for idxPhase in 0 .. 4 {
AssertQubitIsInStateWithinTolerance((complexOne, complexZero), qPhase[idxPhase], 1E-06);
}
X(state);
QuantumPhaseEstimation(oracle, [state], phase);
AssertQubitIsInStateWithinTolerance((complexOne, complexZero), qPhase[0], 1E-06);
AssertQubitIsInStateWithinTolerance((complexOne, complexZero), qPhase[1], 1E-06);
AssertQubitIsInStateWithinTolerance((complexZero, complexOne), qPhase[2], 1E-06);
AssertQubitIsInStateWithinTolerance((complexOne, complexZero), qPhase[3], 1E-06);
AssertQubitIsInStateWithinTolerance((complexZero, complexOne), qPhase[4], 1E-06);
ResetAll(qPhase);
}
/// # Summary
/// Implementation of T-gate for Quantum Phase Estimation Oracle
internal operation ApplyTOracle (power : Int, target : Qubit[]) : Unit is Adj + Ctl {
for idxPower in 0 .. power - 1 {
T(Head(target));
}
}
}