microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/pythontelem

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/grovers_search/reflection_about_state/Verification.qs

39lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Math;
3 open Microsoft.Quantum.Katas;
4
5 operation ReflectionAboutState(
6 qs : Qubit[],
7 statePrep : Qubit[] => Unit is Adj + Ctl)
8 : Unit is Adj + Ctl {
9 within {
10 Adjoint statePrep(qs);
11 } apply {
12 ConditionalPhaseFlip(qs);
13 }
14 }
15
16 // You might find this helper operation from an earlier task useful.
17 operation ConditionalPhaseFlip(qs : Qubit[]) : Unit is Adj + Ctl {
18 within {
19 ApplyToEachA(X, qs);
20 } apply {
21 Controlled Z(qs[1 ...], qs[0]);
22 }
23 R(PauliI, 2.0 * PI(), qs[0]);
24 }
25
26 @EntryPoint()
27 operation CheckSolution() : Bool {
28 for (N, statePrep) in [(2, qs => I(qs[0])), (3, ApplyToEachCA(H, _)), (1, qs => Ry(0.5, qs[0]))] {
29 let sol = Kata.ReflectionAboutState(_, statePrep);
30 let ref = ReflectionAboutState(_, statePrep);
31 if not CheckOperationsAreEqualStrict(N, sol, ref) {
32 Message("Incorrect.");
33 return false;
34 }
35 }
36 Message("Correct!");
37 true
38 }
39}
40