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/multi_qubit_systems/common.qs

29lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Diagnostics;
3
4 operation AssertEqualOnZeroState(
5 testImpl : (Qubit[] => Unit is Ctl),
6 refImpl : (Qubit[] => Unit is Adj+Ctl)) : Bool {
7
8 use qs = Qubit[3];
9 within {
10 H(qs[0]);
11 }
12 apply {
13 // apply operation that needs to be tested
14 Controlled testImpl([qs[0]], qs[1..2]);
15
16 // apply adjoint reference operation
17 Adjoint Controlled refImpl([qs[0]], qs[1..2]);
18 }
19
20 // Implementation is correct when all qubits end up in |0⟩ state
21 let isCorrect = CheckAllZero(qs);
22 if not isCorrect {
23 Message("The prepared state is not the same as reference state.");
24 }
25 ResetAll(qs);
26 isCorrect
27 }
28
29}