Help with the implementation of Deutsch Algorithm using Yao.jl

Need help implementing the oracle from Deutsch’s Algorithm in Yao.jl
Anyone has any ideas on how to do this? Any type of help will be appreciated

1 Like

Deutsch–Josza or just Deutsch as its special case?

Just the Deutsch algorithm!

using Yao, YaoExtensions, YaoPlots, StatsBase
circuit0 = chain(2)
circuit1 = chain(2, control(1, 2=>X))
circuit2 = chain(2, control(1, 2=>X), put(2=>X))
circuit3 = chain(2, put(2=>X))
circuit = [circuit0 circuit1 circuit2 circuit3]
ra = rand(1:4)
result = ArrayReg(bit"10") |> chain(2,repeat(H,1:2), put(1:2=>circuit[ra]),put(1=>H)) |> r->measure(r, 1, nshots=1000)
res = fit(Histogram, Int.(result), 0:2)
answer = res.weights[1]==0 ? “Balanced” : “Constant”

Better implementations are welcome as answer!:slightly_smiling_face:

1 Like