Skip to content

Commit

Permalink
channel basis iterator finished
Browse files Browse the repository at this point in the history
  • Loading branch information
plewandowska777 committed Aug 23, 2019
1 parent 3ec4536 commit 7aad859
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/matrixbases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ abstract type AbstractMatrixBasisIterator{T<:AbstractMatrix} end
struct ChannelBasisIterator{T} <: AbstractMatrixBasisIterator{T}
idim::Int
odim::Int
hitr::HermitianBasisIterator{T}
function ChannelBasisIterator{T}(idim::Int, odim::Int) where T<:AbstractMatrix{<:Number}
new(idim, odim, HermitianBasisIterator{T}(idim))
end
end

abstract type AbstractChannelBasis{T} <: AbstractMatrixBasis{T} end
struct ChannelBasis{T} <: AbstractMatrixBasis{T}
iterator::ChannelBasisIterator{T}
Expand All @@ -81,34 +86,35 @@ channelbasis(T::Type{<:AbstractMatrix{<:Number}}, idim::Int, odim::Int=idim) = C
channelbasis(idim::Int, odim::Int=idim) = channelbasis(Matrix{ComplexF64}, idim, odim)

function iterate(itr::ChannelBasisIterator{T}, state=(1,1,1,1)) where T<:AbstractMatrix{<:Number}
idim=itr.idim
odim=itr.odim
(a,c,b,d)=state
idim = itr.idim
odim = itr.odim
hitr = itr.hitr
(a, c, b, d) = state
(a == odim && c == odim && d == 2) && return nothing

Tn = eltype(T)
if a > c
x = (ketbra(T,a,c,odim) ketbra(T,b,d,idim) + ketbra(T,c,a,odim) ketbra(T,d,b,idim))/sqrt(Tn(2))
elseif a < c
x = (im * ketbra(T,a,c,odim) ketbra(T,b,d,idim) - im *ketbra(T,c,a,odim) ketbra(T,d,b,idim))/sqrt(Tn(2))
x = (ketbra(T, a, c, odim) ketbra(T, b, d, idim) + ketbra(T, c, a, odim) ketbra(T, d, b, idim)) / sqrt(Tn(2))
elseif a < c
x = (im * ketbra(T, a, c, odim) ketbra(T, b, d, idim) - im * ketbra(T, c, a, odim) ketbra(T, d, b, idim)) / sqrt(Tn(2))
elseif a < odim
H = iterate(HermitianBasisIterator{T}(idim),(b,d))[1]
x = (diagm(0 => vcat(ones(Tn, a), Tn[-a], zeros(Tn, odim-a-1))) H) /sqrt(Tn(a+a^2))
H = iterate(hitr, (b, d))[1]
x = (diagm(0 => vcat(ones(Tn, a), Tn[-a], zeros(Tn, odim-a-1))) H) / sqrt(Tn(a+a^2))
else
x = Matrix{Tn}(I, idim*odim, idim*odim)/sqrt(Tn(idim*odim))
x = Matrix{Tn}(I, idim * odim, idim * odim) / sqrt(Tn(idim * odim))
end
if d < idim
newstate = (a,c,b, d+1)
newstate = (a, c, b, d+1)
elseif d == idim && b < idim
newstate = (a,c,b+1,1)
newstate = (a, c, b+1, 1)
elseif d == idim && b == idim && c < odim
newstate = (a,c+1,1,1)
newstate = (a, c+1, 1, 1)
else
newstate = (a+1,1,1,1)
newstate = (a+1, 1, 1, 1)
end
return x, newstate
end
length(itr::ChannelBasisIterator) = itr.idim^2*itr.odim^2-itr.idim^2+1
length(itr::ChannelBasisIterator) = itr.idim^2 * itr.odim^2 - itr.idim^2 + 1

function represent(basis::ChannelBasis{T1}, Φ::AbstractQuantumOperation{T2}) where T1<:AbstractMatrix{<:Number} where T2<: AbstractMatrix{<:Number}
J = convert(DynamicalMatrix{T2}, Φ)
Expand All @@ -117,6 +123,5 @@ end

function combine(basis::ChannelBasis{T}, v::Vector{<:Number}) where T<:AbstractMatrix
m = sum(basis.iterator .* v)
@show 1
DynamicalMatrix{T}(m, basis.iterator.idim, basis.iterator.odim)
end

0 comments on commit 7aad859

Please sign in to comment.