microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/grovers_search/conditional_phase_flip/Verification.qs
28lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Katas; |
| 3 | open Microsoft.Quantum.Math; |
| 4 | operation ConditionalPhaseFlip(qs : Qubit[]) : Unit is Adj + Ctl { |
| 5 | within { |
| 6 | ApplyToEachA(X, qs); |
| 7 | } apply { |
| 8 | Controlled Z(qs[1 ...], qs[0]); |
| 9 | } |
| 10 | R(PauliI, 2.0 * PI(), qs[0]); |
| 11 | } |
| 12 | |
| 13 | @EntryPoint() |
| 14 | operation CheckSolution() : Bool { |
| 15 | for N in 2 .. 4 { |
| 16 | if not CheckOperationsAreEqualStrict(N, Kata.ConditionalPhaseFlip, ConditionalPhaseFlip) { |
| 17 | Message("Incorrect."); |
| 18 | Message("Hint: examine how your solution transforms the given state and compare it with the expected " + |
| 19 | $"transformation for the {N}-bit inputs"); |
| 20 | ShowQuantumStateComparison(N, PrepDemoState, Kata.ConditionalPhaseFlip, ConditionalPhaseFlip); |
| 21 | return false; |
| 22 | } |
| 23 | } |
| 24 | Message("Correct!"); |
| 25 | true |
| 26 | } |
| 27 | |
| 28 | } |
| 29 | |