microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/test_cases/apply_x/Verification.qs
33lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | namespace Kata.Verification { |
| 5 | open Microsoft.Quantum.Diagnostics; |
| 6 | open Microsoft.Quantum.Intrinsic; |
| 7 | |
| 8 | operation CheckSolution() : Bool { |
| 9 | VerifySingleQubitOperation(Kata.ApplyX, ApplyX) |
| 10 | } |
| 11 | |
| 12 | operation ApplyX(q : Qubit) : Unit is Adj + Ctl { |
| 13 | X(q); |
| 14 | } |
| 15 | |
| 16 | operation VerifySingleQubitOperation( |
| 17 | op : (Qubit => Unit is Adj + Ctl), |
| 18 | reference : (Qubit => Unit is Adj + Ctl)) |
| 19 | : Bool { |
| 20 | use (control, target) = (Qubit(), Qubit()); |
| 21 | within { |
| 22 | H(control); |
| 23 | } |
| 24 | apply { |
| 25 | Controlled op([control], target); |
| 26 | Adjoint Controlled reference([control], target); |
| 27 | } |
| 28 | let isCorrect = CheckAllZero([control, target]); |
| 29 | ResetAll([control, target]); |
| 30 | |
| 31 | isCorrect |
| 32 | } |
| 33 | } |