2021年3月21日日曜日

QFT part 5: adjustable number of qubits

As continued from QFT part 4 , the number of qubits is now adjustable.

NQubit = 3 and 4 are working correctly.

I think I made a mistake and updated on 1st of May, 2021.

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 {
let nQubit = 4;
let maxNum = PowI(2,nQubit);
mutable counts = new Int[maxNum];
mutable theta = new Double[maxNum];

for iQubit in 0..(nQubit-1){
set theta w/= iQubit <- calcTheta(IntAsDouble(iQubit+1));
}

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

// Star QFT
for iQubit in 0..(nQubit-1){
H(input[iQubit]);
for jQubit in 1..(nQubit-1-iQubit){
(Controlled R1)([input[jQubit+iQubit]],(theta[jQubit],input[iQubit]));
}
}
//H(input[0]);
//(Controlled R1)([input[1]],(theta[1],input[0]));
//(Controlled R1)([input[2]],(theta[2],input[0]));
//H(input[1]);
//(Controlled R1)([input[2]],(theta[1],input[1]));

//H(input[2]);

let numLoopSwap = Floor(IntAsDouble(nQubit)*0.5);


for iQubit in 0..(numLoopSwap-1) {
SWAP(input[iQubit],input[nQubit-1-iQubit]);
}
//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..(maxNum-1) {
Message(IntAsString(counts[j]));
}
}
function calcTheta(l : Double) : Double {
return 2.0*PI()/(PowD(2.0,l));
}
}


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));
}
}


 

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);

2021年3月4日木曜日

DOI for my newly published paper

 I have just notified that my newly published paper got a DOI.
https://doi.org/10.1142/S0219876221500274

Actually, I got the notification from ORCID, not from the journal. Things are getting well organized, but feel some skew.