microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/replace-qsharp-with-qdk-python-tests

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/key_distribution/Common.qs

33lines · modecode

1namespace Kata.Verification {
2 import Std.Arrays.*;
3 import Std.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 // ∣+⟩ / ∣-⟩
16 return bit ? "|-⟩" | "|+⟩";
17 } else {
18 // ∣0⟩ / ∣1⟩
19 return bit ? "|1⟩" | "|0⟩";
20 }
21 }
22
23 operation PrepareQubits_Reference(qs : Qubit[], bases : Bool[], bits : Bool[]) : Unit is Adj {
24 for i in 0..Length(qs) - 1 {
25 if bits[i] {
26 X(qs[i]);
27 }
28 if bases[i] {
29 H(qs[i]);
30 }
31 }
32 }
33}
34