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