2021年3月14日日曜日

QFT part 4: Using R1 gate, instead of S and T.

Since I do want to extend the number of qubits from three to more, I have re-written the code with R1 gate, in stead of S and T.

Lessons learned: Functions and operations can be defined. Here a function which returns Double is created. Operations might be used for qubits. Not sure now.

namespace QFT_naive {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
@EntryPoint()
operation SayHello() : Unit {
mutable counts = new Int[8];

let theta_1 = calcTheta(1.0);
let theta_2 = calcTheta(2.0);
let theta_3 = calcTheta(3.0);

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]);
(Controlled R1)([input[1]],(theta_2,input[0]));
(Controlled R1)([input[2]],(theta_3,input[0]));

H(input[1]);
//(Controlled S)([input[2]],input[1]);
(Controlled R1)([input[2]],(theta_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]));
}
}
function calcTheta(l : Double) : Double {
return 2.0*PI()/(PowD(2.0,l));
}
}


 

0 件のコメント:

コメントを投稿