microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dmitryv/select-updated

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/getting_started/flip_qubit/Verification.qs

29lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Intrinsic;
3 open Microsoft.Quantum.Katas;
4
5 operation FlipQubit(q : Qubit) : Unit is Adj + Ctl {
6 X(q);
7 }
8
9 operation CheckSolution() : Bool {
10 let solution = register => Kata.FlipQubit(register[0]);
11 let reference = register => FlipQubit(register[0]);
12 let isCorrect = CheckOperationsEquivalence(solution, reference, 1);
13
14 // Output different feedback to the user depending on whether the solution was correct.
15 if isCorrect {
16 Message("Correct!");
17 Message("Congratulations! You have solved your first exercise.");
18 } else {
19 Message("Incorrect.");
20 Message("Look out for hints when your solution is incorrect.");
21 Message("Hint: examine the effect your solution has on the |0〉 state and compare it with the effect it " +
22 "is expected to have.");
23 use target = Qubit[1]; // |0〉
24 ShowQuantumStateComparison(target, solution, reference);
25 ResetAll(target);
26 }
27 isCorrect
28 }
29}
30