2021年3月7日日曜日

QFT part 3. With ResultArrayAsInt and MultiM.

Still playing around QFFT. Improved the last one with ResultArrayAsInt and MultiM.
Those allow me to shorten the code a bit, and may allow me to go the 4 qubit case.

One thing I am not quite sure is, which end is the LSB?
I suspect 0 is the LSB, but no clue.

namespace QFT_naive {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;

@EntryPoint()
operation SayHello() : Unit {
Message("qFFT");
mutable counts = new Int[8];

for trian in 1..1000 {
use input = Qubit[3] {
// 1/sqrt(8) (|000> + |001> + ,,, + |111>)
H(input[0]);
H(input[1]);
H(input[2]);

// Star QFT
// R1 = Z, R2=S, R3=T
H(input[0]);
(Controlled S)([input[1]],input[0]);
(Controlled T)([input[2]],input[0]);

H(input[1]);
(Controlled S)([input[2]],input[1]);

H(input[2]);

SWAP(input[2],input[0]);

let res = MultiM(input);
let bit = ResultArrayAsInt(res);
set counts w/= bit <- counts[bit]+ 1;
ResetAll(input);
}
}
for j in 0..7 {
Message(IntAsString(counts[j]));
}
}
}



I think 0 is LSB because when I modify the code as follows; 5th element (namely 100=4) of "count" has "1000"

mutable res = MultiM(input);
set res w/= 2 <- One;
let bit = ResultArrayAsInt(res);

0 件のコメント:

コメントを投稿