Skip to content

Commit

Permalink
testing matrixbasis without number types
Browse files Browse the repository at this point in the history
  • Loading branch information
plewandowska777 committed Aug 23, 2019
1 parent 7aad859 commit 5e18081
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/matrixbases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function iterate(itr::ChannelBasisIterator{T}, state=(1,1,1,1)) where T<:Abstrac
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(hitr, (b, d))[1]
x = (diagm(0 => vcat(ones(Tn, a), Tn[-a], zeros(Tn, odim-a-1))) H) / sqrt(Tn(a+a^2))
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))
end
Expand All @@ -116,7 +116,7 @@ function iterate(itr::ChannelBasisIterator{T}, state=(1,1,1,1)) where T<:Abstrac
end
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}
function represent(basis::ChannelBasis{T1}, Φ::AbstractQuantumOperation{T2}) where T1<:AbstractMatrix{<:Number} where T2<:AbstractMatrix{<:Number}
J = convert(DynamicalMatrix{T2}, Φ)
represent(basis, J.matrix)
end
Expand Down
37 changes: 0 additions & 37 deletions test/channelbases.jl

This file was deleted.

40 changes: 40 additions & 0 deletions test/matrixbases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
@test [tr(m[i]' * m[j]) for i=1:d, j=1:d] Matrix{Float64}(I, d, d)
end

@testset "ChannelBasisIterator" begin
d1 = 2
d2 = 2
d = d1^2 * d2^2 - d1^2 + 1
m = collect(ChannelBasisIterator{Matrix{ComplexF64}}(d1,d2))
@test [tr(m[i]' * m[j]) for i=1:d, j=1:d] Matrix{Float64}(I, d, d)
end

@testset "represent, combine" begin
d = 4
A = reshape(collect(1:16), d, d) + reshape(collect(1:16), d, d)'
Expand All @@ -27,9 +35,41 @@ end
@test length(vC) == prod(size(C))
end

@testset "represent, combine" begin
d1 = 2
d2 = 4
A = reshape(collect(1:16), d1 * d2, d1) * reshape(collect(1:16), d1 * d2, d1)'
B = Matrix{Float64}(I, d2, d2) (ptrace(A, [d2, d1], 1))^(-1/2)
A = B * A * B'
vA = represent(ChannelBasis{Matrix{ComplexF64}}(d1, d2), A)
Ap = combine(ChannelBasis{Matrix{ComplexF64}}(d1, d2), vA)
@test A Ap.matrix

A = reshape(collect(1:64), d1 * d2, d1 * d2) * reshape(collect(1:64), d1 * d2, d1 * d2)' + Matrix{Float64}(I, d1 * d2, d1 * d2)
B = Matrix{Float64}(I, d1, d1) (ptrace(A, [d1, d2], 1))^(-1/2)
B = B * A * B'
vB = represent(ChannelBasis{Matrix{ComplexF64}}(d2, d1), B)
Bp = combine(ChannelBasis{Matrix{ComplexF64}}(d2, d1), vB)
@test B Bp.matrix

#vB = represent(ChannelBasis{Matrix{ComplexF32}}(d1,d2), B)
#@test eltype(vB) == Float32

# C = Float16[1 2; 3 4]
# C += C'
# vC = represent(ChannelBasis, C)
# @test eltype(vC) == eltype(C)
# @test length(vC) == prod(size(C))
end

@testset "hermitainbasis" begin
@test hermitianbasis(Matrix{Float32}, 2) == HermitianBasisIterator{Matrix{Float32}}(2)
@test hermitianbasis(2) == HermitianBasisIterator{Matrix{ComplexF64}}(2)
end

# @testset "channelbasis" begin
# @test channelbasis(Matrix{Float32}, 2,2) == ChannelBasisIterator{Matrix{Float32}}(2,2)
# @test channelbasis(2,2) == ChannelBasisIterator{Matrix{ComplexF64}}(2,2)
# end

end
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using Test
my_tests = ["utils.jl", "base.jl", "ptrace.jl", "ptranspose.jl", "reshuffle.jl",
"channels.jl", "functionals.jl", "gates.jl", "matrixbases.jl",
"permute_systems.jl", "randomqobjects.jl", "convex.jl"]

for my_test in my_tests
include(my_test)
end

0 comments on commit 5e18081

Please sign in to comment.