microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/key_distribution/prepare_qubits/Verification.qs
26lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Diagnostics; |
| 3 | |
| 4 | @EntryPoint() |
| 5 | operation CheckSolution() : Bool { |
| 6 | for N in 2 .. 10 { |
| 7 | let (bases, bits) = (RandomArray(N), RandomArray(N)); |
| 8 | use qs = Qubit[N]; |
| 9 | Kata.PrepareQubits(qs, bases, bits); |
| 10 | Adjoint PrepareQubits_Reference(qs, bases, bits); |
| 11 | for i in 0 .. N - 1 { |
| 12 | if not CheckZero(qs[i]) { |
| 13 | Message($"Qubit qs[{i}] prepared in incorrect state."); |
| 14 | Message($"Expected state {StateToString(bases[i], bits[i])}; actual state"); |
| 15 | PrepareQubits_Reference([qs[i]], [bases[i]], [bits[i]]); |
| 16 | DumpRegister([qs[i]]); |
| 17 | ResetAll(qs); |
| 18 | return false; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | Message("Correct!"); |
| 24 | true |
| 25 | } |
| 26 | } |
| 27 | |