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

support expectation #29

Open Roger-luo opened 4 years ago

Roger-luo commented 4 years ago

expectation semantic can be useful in compiling differentiable programs

function vqe(theta)
    1 => Rx(theta)
    2 => Rx(theta)
    @expect 1:3 <op>
end

the @expect should be semantically equivalent to multiple @measure statements

Roger-luo commented 4 years ago

suggested by @GiggleLiu , a better way to support this is via a primitive expect, which is equivalent to

ob = 0
for _ in 1:nshots
   ob += @measure 1:3 op
end
ob/nshots

in concept, but will be handled specially under different contexts.