microsoft/qdk

Public

mirrored fromhttps://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/oracles/bit_pattern_oracle/Verification.qs

36lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Convert;
3 open Microsoft.Quantum.Katas;
4
5 operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {
6 ApplyControlledOnBitString(pattern, X, x, y);
7 }
8
9 // ------------------------------------------------------
10 @EntryPoint()
11 operation CheckSolution() : Bool {
12 for N in 1 .. 3 {
13 for k in 0 .. 2^N - 1 {
14 let pattern = IntAsBoolArray(k, N);
15
16 let sol = ApplyOracle(_, Kata.ArbitraryBitPattern_Oracle(_, _, pattern));
17 let ref = ApplyOracle(_, ArbitraryBitPattern_Oracle_Reference(_, _, pattern));
18 let isCorrect = CheckOperationsEquivalenceStrict(sol, ref, N + 1);
19
20 if not isCorrect {
21 Message("Incorrect.");
22 Message("Hint: examine how your solution transforms the given state and compare it with the expected " +
23 $"transformation for the {N}-bit oracle for the pattern {pattern}");
24 use initial = Qubit[N + 1];
25 PrepRandomState(initial[...N - 1]);
26 ShowQuantumStateComparison(initial, sol, ref);
27 ResetAll(initial);
28 return false;
29 }
30 }
31 }
32 Message("Correct!");
33 true
34 }
35
36}
37