QuantumBFS / YaoQASM.jl

Bidirectional transformation between Yao IR and QASM.
Apache License 2.0
11 stars 4 forks source link

Developer note: Quantum Fourier transformations #2

Open GiggleLiu opened 5 years ago

GiggleLiu commented 5 years ago

Yao

using Yao

CRk(i::Int, j::Int, k::Int) = control([i, ], j=>shift(2π/(1<<k)))
CRot(n::Int, i::Int) = chain(n, i==j ? kron(i=>H) : CRk(j, i, j-i+1) for j = i:n)
QFTCircuit(n::Int) = chain(n, CRot(n, i) for i = 1:n)

open qasm

OPENQASM 2.0;

qreg q[4];
creg c[4];

h q[0];
cphase(π/2) q[1], q[0];
cphase(π/4) q[2], q[0];
cphase(π/8) q[3], q[0];

h q[1];
cphase(π/2) q[2], q[1];
cphase(π/4) q[3], q[1];

h q[2];
cphase(π/2) q[3], q[2];

h q[3];

measure q -> c;

pyquil

H 0
CPHASE(1.5707963267948966) 1 0
CPHASE(0.7853981633974483) 2 0
CPHASE(0.39269908169872414) 3 0
H 1
CPHASE(1.5707963267948966) 2 1
CPHASE(0.7853981633974483) 3 1
H 2
CPHASE(1.5707963267948966) 3 2
H 3
MEASURE 0 1 2 3