QFT with three qubits is implemented in Q#.
The last post was to initialize the original state (entangled over three qubits).
I feel the measurement part should be as this post (the last one is incorrect).
Formulation is;
https://dojo.qulacs.org/ja/latest/notebooks/2.3_quantum_Fourier_transform.html#
The result is;
|000>: 1000, others: 0.
This agrees with the result of the above site :)!
namespace QFT_naive {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
@EntryPoint()
operation SayHello() : Unit {
Message("Hello quantum world!");
mutable counts = new Int[8];
mutable nres0 = 0;
mutable nres1 = 0;
mutable nres2 = 0;
for(trian in 1..1000){
using ( (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]);
//CNOT(input[0], input[2]);
//CNOT(input[2], input[0]);
//CNOT(input[0], input[2]);
// Start Measuring
let res0 = M(input[0]);
let res1 = M(input[1]);
let res2 = M(input[2]);
if (res0 == Zero){
set nres0 = 0;
}else{
set nres0 = 1;
}
if (res1 == Zero){
set nres1 = 0;
}else{
set nres1 = 1;
}
if (res2 == Zero){
set nres2 = 0;
}else{
set nres2 = 1;
}
let bit = nres0 + nres1*2 + nres2*4;
set counts w/= bit <- counts[bit]+ 1;
ResetAll(input);
}
}
for (j in 0..7) {
Message(IntAsString(counts[j]));
}
}
}
0 件のコメント:
コメントを投稿