QuantumBFS / YaoLang.jl

YaoLang: The next DSL for Yao and quantum programs.
https://yaoquantum.org/YaoLang.jl/dev/
Apache License 2.0
31 stars 6 forks source link

fix default value & support callables #27

Closed Roger-luo closed 4 years ago

Roger-luo commented 4 years ago

fix #19 and fix #22

Roger-luo commented 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)