Skip to content

Commit

Permalink
Merge branch 'master' into pg/dimfix
Browse files Browse the repository at this point in the history
  • Loading branch information
pgawron committed Aug 16, 2019
2 parents 04fcec4 + 4c92c9f commit bac0913
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumInformation"
uuid = "3c0b384b-479c-5684-b2ef-9d7a46dd931e"
authors = ["Dariusz Kurzyk <dkurzyk@iitis.pl>", "Łukasz Pawela <lpawela@iitis.pl>", "Piotr Gawron <gawron@iitis.pl>", "Marcin Przewięźlikowski <m.przewie@gmail.com>"]
version = "0.4.4"
version = "0.4.5"

[compat]
julia = "0.7, 1.0, 1.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![DOI](https://zenodo.org/badge/23916883.svg)](https://zenodo.org/badge/latestdoi/23916883)
# QuantumInformation

A Julia package for numerical computation in quantum information theory.
A Julia package for numerical computation in quantum information theory. [Published in PLoS ONE](https://doi.org/10.1371/journal.pone.0209358).

Numerical investigations are prevalent in quantum information theory. Numerical experiments can be used to find counter examples for theorems, to test hypotheses or to gain insight about quantum objects and operations.

Expand Down
26 changes: 13 additions & 13 deletions src/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct SuperOperator{T<:AbstractMatrix{<:Number}} <: AbstractQuantumOperation{T}
throw(ArgumentError("Superoperator matrix has bad dimensions"))
end
odim, idim = sr, sc
new{T1}(T1(m), idim, odim)
new{T1}(convert(T1, m), idim, odim)
end
end

Expand Down Expand Up @@ -98,7 +98,7 @@ struct DynamicalMatrix{T<:AbstractMatrix{<:Number}} <: AbstractQuantumOperation{
if r!=c || r!=idim*odim
throw(ArgumentError("DynamicalMatrix matrix has bad dimensions"))
end
new(T1(m), idim, odim)
new(convert(T1, m), idim, odim)
end
end

Expand Down Expand Up @@ -129,13 +129,13 @@ struct UnitaryChannel{T<:AbstractMatrix{<:Number}} <: AbstractQuantumOperation{T
function UnitaryChannel{T1}(m::T2) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
odim, idim = size(m)
idim == odim ? () : throw(ArgumentError("UnitaryChannel matrix has to be square"))
new{T1}(T1(m), idim, odim)
new{T1}(convert(T1,m), idim, odim)
end
end

function UnitaryChannel{T1}(m::T2, idim::Int, odim::Int) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
(odim, idim) == size(m) ? () : throw(ArgumentError("Matrix size and operator dimensions mismatch"))
UnitaryChannel{T1}(T1(m))
UnitaryChannel{T1}(convert(T1,m))
end

"""
Expand Down Expand Up @@ -191,7 +191,7 @@ struct PostSelectionMeasurement{T<:AbstractMatrix{<:Number}} <: AbstractQuantumO
odim::Int
function PostSelectionMeasurement{T1}(m::T2) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
odim, idim = size(m)
new{T1}(T1(m), idim, odim)
new{T1}(convert(T1,m), idim, odim)
end
end

Expand Down Expand Up @@ -286,7 +286,7 @@ Transforms list of Kraus operators into super-operator matrix.
"""
function Base.convert(::Type{SuperOperator{T1}}, Φ::KrausOperators{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
m = sum(k(conj.(k)) for k in Φ.matrices)
SuperOperator{T1}(T1(m), Φ.idim, Φ.odim)
SuperOperator{T1}(convert(T1,m), Φ.idim, Φ.odim)
end

"""
Expand All @@ -300,7 +300,7 @@ function Base.convert(::Type{Stinespring{T1}}, Φ::KrausOperators{T2}) where {T1
ko = orthogonalize(Φ)
# TODO: improvement: transform to stacking
m = sum(k ket(i, ko.idim*ko.odim) for (i, k) in enumerate(ko.matrices))
Stinespring{T1}(T1(m), ko.idim, ko.odim)
Stinespring{T1}(convert(T1,m), ko.idim, ko.odim)
end

"""
Expand All @@ -312,7 +312,7 @@ Transforms list of Kraus operators into dynamical matrix.
"""
function Base.convert(::Type{DynamicalMatrix{T1}}, Φ::KrausOperators{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
m = sum(res(k) * res(k)' for k in Φ.matrices)
DynamicalMatrix{T1}(T1(m), Φ.idim, Φ.odim)
DynamicalMatrix{T1}(convert(T1,m), Φ.idim, Φ.odim)
end

"""
Expand All @@ -335,7 +335,7 @@ Transforms super-operator matrix into dynamical matrix.
"""
function Base.convert(::Type{DynamicalMatrix{T1}}, Φ::SuperOperator{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
m = reshuffle.matrix, [Φ.odim Φ.odim; Φ.idim Φ.idim])
DynamicalMatrix{T1}(T1(m), Φ.idim, Φ.odim)
DynamicalMatrix{T1}(convert(T1,m), Φ.idim, Φ.odim)
end

"""
Expand Down Expand Up @@ -396,11 +396,11 @@ Transforms dynamical matrix into super-operator matrix.
"""
function Base.convert(::Type{SuperOperator{T1}}, Φ::DynamicalMatrix{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
m = reshuffle.matrix, [Φ.odim Φ.idim; Φ.odim Φ.idim])
SuperOperator{T1}(T1(m), Φ.idim, Φ.odim)
SuperOperator{T1}(convert(T1,m), Φ.idim, Φ.odim)
end

function Base.convert(::Type{KrausOperators{T1}}, Φ::UnitaryChannel{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
KrausOperators{T1}(T1[T1(Φ.matrix)], Φ.idim, Φ.odim)
KrausOperators{T1}(T1[convert(T1,Φ.matrix)], Φ.idim, Φ.odim)
end

function Base.convert(::Type{KrausOperators{T1}}, Φ::IdentityChannel{T2}) where {T1<:AbstractMatrix{N1}, T2<:AbstractMatrix{N2}} where {N1<:Number, N2<:Number}
Expand All @@ -417,14 +417,14 @@ function Base.convert(::Type{KrausOperators{T1}}, Φ::POVMMeasurement{T2}) where
for (i, p) in enumerate.matrices)
sqrtp = sqrt(p)
k = ket(i, Φ.odim)*sum(bra(j, Φ.idim)*sqrtp for j in 1:Φ.idim)
push!(v, T1(k))
push!(v, convert(T1,k))
end
KrausOperators{T1}(v, Φ.idim, Φ.odim)
end

function Base.convert(::Type{KrausOperators{T1}}, Φ::PostSelectionMeasurement{T2}) where {T1<:AbstractMatrix{<:Number}, T2<:AbstractMatrix{<:Number}}
m = Φ.matrix
v = T1[T1(m)]
v = T1[convert(T1,m)]
KrausOperators{T1}(v, Φ.idim, Φ.odim)
end

Expand Down
3 changes: 3 additions & 0 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ end
@testset "UnitaryChannel" begin
@test_throws ArgumentError UnitaryChannel(ones(4, 5))
@test_throws ArgumentError UnitaryChannel(ones(4, 4), 4, 5)

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

@testset "POVMMeasurement" begin
Expand Down

0 comments on commit bac0913

Please sign in to comment.