-
Notifications
You must be signed in to change notification settings - Fork 1
/
non-unitary.jl
64 lines (58 loc) · 1.53 KB
/
non-unitary.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Yao
using Yao.ConstGate
using BitBasis
using LinearAlgebra
using Plots
struct unidecomp
coeff::ComplexF64
unit::Array{ComplexF64,2}
unidecomp(coeff,unit) = new(coeff,unit)
end
function run_()
f = 1.0
for i=1:10
reg |> g |> p0
f *= normalize_factor(reg)
reg |> normalize!
end
return f
end
#=
non-unitary probabilitistic gate
N:non-unitary gate, ϵ:parameter
return fidelity and probability
=#
function nonunitfidprob(N,ϵ)
m = exp([zeros(4,4) ϵ*N; -ϵ*N zeros(4,4)])
reg2 = rand_state(2)
reg = join(zero_state(1),reg2)
#println(statevec(reg))
p31 = put(3,3=>ConstGate.P0)
regt = copy(reg)
reg |> matblock(m)
p0 = probs(reg)[1]
reg |> matblock(m) |> p31 |> normalize!
#println(statevec(reg))
reg2 |> matblock(N) |> normalize!
return fidelity(reg,join(zero_state(1),reg2)), p0
end
function unitarydecomposition(N) #N = n1.coeff*n1.unit+n2.coeff*n2.unit
nfactor = opnorm(N)
N = N / nfactor
F = svd(N)
D = Diagonal(F.S) + im*sqrt.(I-Diagonal((F.S).^2))
return unidecomp(0.5*nfactor,F.U*D*F.Vt),unidecomp(0.5*nfactor,F.U*conj(D)*F.Vt)
end
function lcu(ntot,top,mid,bot,N)
ua,ub = unitarydecomposition(N)
chain(
ntot,
put(ntot, (top=>H)),
put(ntot, (top=>X)),
control(ntot,top,(mid,bot)=>matblock(ua.unit)),
put(ntot, (top=>X)),
control(ntot,top,(mid,bot)=>matblock(ub.unit)),
put(ntot, (top=>H)),
put(ntot,(top=>ConstGate.P0))
)
end