Skip to content

Commit

Permalink
fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Gawron committed Sep 3, 2019
1 parent 54a8e75 commit 2cf8521
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/channels/compositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ function compose(::Type{T}, Φ1::T1, Φ2::T2) where {T<:AbstractQuantumOperation
convert(T, so)
end

function compose(Φ1::UnitaryChannel{M1}, Φ2::UnitaryChannel{M2}) where {M1<:AbstractMatrix{<:Number}, M2<:AbstractMatrix{<:Number}}
M = promote_type(M1, M2)
compose(UnitaryChannel{M}, Φ1, Φ2)
end

function compose(::Type{UnitaryChannel{M}}, Φ1::UnitaryChannel{M1}, Φ2::UnitaryChannel{M2}) where {M<:AbstractMatrix{<:Number}, M1<:AbstractMatrix{<:Number}, M2<:AbstractMatrix{<:Number}}
Φ1.odim == Φ2.idim ? () : throw(ArgumentError("Unitaries are incompatible"))

um1 = Φ1.matrix
um2 = Φ2.matrix
um = um2 * um1
UnitaryChannel{M}(convert(M, um), Φ1.idim, Φ2.odim)
end

function compose(Φ1::T, Φ2::T) where {T<:AbstractQuantumOperation{<:Number}}
compose(T, Φ1, Φ2)
end
Expand Down
7 changes: 7 additions & 0 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ end

c = UnitaryChannel(Diagonal(ComplexF64[1 -1.0im]))
@test c isa UnitaryChannel{<:Diagonal}

u1 = UnitaryChannel([cos(1) sin(1); -sin(1) cos(1)])
u2 = UnitaryChannel([cos(2) sin(2); -sin(2) cos(2)])
@test compose(u1, u2).matrix u2.matrix * u1.matrix
@test compose(UnitaryChannel{Array{Float64,2}}, u1, u2).matrix u2.matrix * u1.matrix

@test kron(u1, u2).matrix kron(u1.matrix, u2.matrix)
end

@testset "POVMMeasurement" begin
Expand Down

0 comments on commit 2cf8521

Please sign in to comment.