Closed Roger-luo closed 4 years ago
using NiLang, YaoLang
using YaoArrayRegister
Base.:(~)(c::YaoLang.GenericCircuit) = NiLang.Inv(c)
Base.adjoint(c::Circuit{:shift}) = shift(-c.free[2])
Base.adjoint(c::PrimitiveCircuit{:H}) = c
@i @device function qft(n::Int)
1 => H
for k in 2:n
@ctrl k 1=>shift(2π/2^k)
end
end
@device function iqft3(n::Int)
@ctrl 4 1=>shift(-2π/2^4)
@ctrl 3 1=>shift(-2π/2^3)
@ctrl 2 1=>shift(-2π/2^2)
1 => H
end
r = rand_state(4)
r1 = copy(r) |> iqft3(4)
r2 = copy(r) |> (~qft)(4)
r1 ≈ r2
@code_yao (~qft)(4)
fix #19 and fix #22