microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/multi_qubit_gates/compound_gate/Verification.qs

33lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Katas;
3 open Microsoft.Quantum.Math;
4
5 operation CompoundGate (qs : Qubit[]) : Unit is Adj + Ctl {
6 S(qs[0]);
7 I(qs[1]); // this line can be omitted, since it doesn't change the qubit state
8 Y(qs[2]);
9 }
10
11 operation CheckSolution() : Bool {
12 let solution = Kata.CompoundGate;
13 let reference = CompoundGate;
14 let isCorrect = CheckOperationsEquivalenceStrict(solution, reference, 3);
15
16 // Output different feedback to the user depending on whether the solution was correct.
17 if isCorrect {
18 Message("Correct!");
19 } else {
20 Message("Incorrect.");
21 Message("Hint: examine how your solution transforms the given state and compare it with the expected " +
22 "transformation");
23 use initial = Qubit[3]; // |000〉
24 Ry(ArcTan2(0.8, 0.6) * 2.0, initial[0]);
25 Ry(ArcTan2(0.7, 0.4) * 2.0, initial[1]);
26 Ry(ArcTan2(0.6, 0.5) * 2.0, initial[2]);
27 ShowQuantumStateComparison(initial, solution, reference);
28 ResetAll(initial);
29 }
30
31 isCorrect
32 }
33}