microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/replace-qsharp-with-qdk-python-tests

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/key_distribution/measure_qubits/Verification.qs

31lines · modecode

1namespace Kata.Verification {
2 import Std.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 PrepareQubits_Reference(qs, bases, bits);
10 let res = Kata.MeasureQubits(qs, bases);
11 ResetAll(qs);
12
13 if Length(res) != N {
14 Message($"The returned array should have length {N}, same as the inputs, and it had length {Length(res)}.");
15 return false;
16 }
17
18 for i in 0..N - 1 {
19 if res[i] != bits[i] {
20 Message($"Qubit qs[{i}] measured in incorrect basis.");
21 Message($"When measuring state {StateToString(bases[i], bits[i])} in the {BasisToString(bases[i])} basis, " +
22 $"expected result is {bits[i]}, got {res[i]}.");
23 return false;
24 }
25 }
26 }
27
28 Message("Correct!");
29 true
30 }
31}
32