microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/second-api-refactor

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/deutsch_algo/implement_algo/Verification.qs

33lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Katas;
3 open Microsoft.Quantum.Math;
4
5 operation CheckSolution() : Bool {
6 for (oracle, expected, name) in [(I, true, "f(x) = 0"),
7 (R(PauliI, 2.0 * PI(), _), true, "f(x) = 1"),
8 (Z, false, "f(x) = x"),
9 (PhaseOracle_OneMinusX, false, "f(x) = 1 - x")] {
10
11 let actual = Kata.DeutschAlgorithm(oracle);
12 if actual != expected {
13 Message("Incorrect.");
14 let actualStr = ConstantOrVariable(actual);
15 let expectedStr = ConstantOrVariable(expected);
16 Message($"{name} identified as {actualStr} but it is {expectedStr}.");
17 return false;
18 }
19 }
20
21 Message("Correct!");
22 true
23 }
24
25 function ConstantOrVariable (value : Bool) : String {
26 return value ? "constant" | "variable";
27 }
28
29 operation PhaseOracle_OneMinusX(x : Qubit) : Unit is Adj + Ctl {
30 Z(x);
31 R(PauliI, 2.0 * PI(), x);
32 }
33}
34