microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billt/revert-mimalloc

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/qubit/learn_single_qubit_state/Verification.qs

34lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Intrinsic;
3 open Microsoft.Quantum.Math;
4
5 @EntryPoint()
6 operation CheckSolution() : Bool {
7 use q = Qubit();
8
9 // Prepare the state that will be passed to the solution.
10 let angle = 0.5;
11 Ry(angle, q);
12
13 // Call the solution and get the answer.
14 let (a, b) = Kata.LearnSingleQubitState(q);
15
16 // Calculate the expected values based on the rotation angle.
17 let (a_exp, b_exp) = (Cos(0.5 * angle), Sin(0.5 * angle));
18
19 Reset(q);
20
21 let isCorrect =
22 (AbsD(a - a_exp) <= 0.001) and
23 (AbsD(b - b_exp) <= 0.001);
24
25 // Output different feedback to the user depending on whether the exercise was correct.
26 if isCorrect {
27 Message("Correct!");
28 } else {
29 Message("At least one of the amplitudes was too far from the expected value.");
30 }
31
32 isCorrect
33 }
34}
35