microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/pythontelem

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/key_distribution/Common.qs

31lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Arrays;
3 open Microsoft.Quantum.Random;
4
5 operation RandomArray(N : Int) : Bool[] {
6 ForEach(x => DrawRandomInt(0, 1) == 0, [0, size = N])
7 }
8
9 operation BasisToString(base : Bool) : String {
10 base ? "Hadamard" | "computational"
11 }
12
13 operation StateToString(base : Bool, bit : Bool) : String {
14 if base { // ∣+⟩ / ∣-⟩
15 return bit ? "|-⟩" | "|+⟩";
16 } else { // ∣0⟩ / ∣1⟩
17 return bit ? "|1⟩" | "|0⟩";
18 }
19 }
20
21 operation PrepareQubits_Reference(qs : Qubit[], bases : Bool[], bits : Bool[]) : Unit is Adj {
22 for i in 0 .. Length(qs) - 1 {
23 if bits[i] {
24 X(qs[i]);
25 }
26 if bases[i] {
27 H(qs[i]);
28 }
29 }
30 }
31}
32