• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iitis / QuantumInformation.jl / 4861454641

pending completion
4861454641

Pull #103

github

GitHub
Merge 817c8b246 into 7644f36f9
Pull Request #103: Bloch vector

6 of 6 new or added lines in 1 file covered. (100.0%)

546 of 723 relevant lines covered (75.52%)

64.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/ptranspose.jl
1
export ptranspose
2
"""
3
$(SIGNATURES)
4
- `ρ`: quantum state.
5
- `idims`: dimensins of subsystems.
6
- `isystems`: transposed subsystems.
7

8
Return [partial transposition](http://en.wikipedia.org/wiki/Peres-Horodecki_criterion) of matrix `ρ` over the subsystems determined by `isystems`.
9
"""
10
function ptranspose(ρ::AbstractMatrix, idims::Vector{Int}, isystems::Vector{Int})
14✔
11
    dims = reverse(idims)
14✔
12
    systems = length(idims) .- isystems .+ 1
28✔
13

14
    if size(ρ,1)!=size(ρ,2)
14✔
15
        throw(ArgumentError("Non square matrix passed to ptrace"))
1✔
16
    end
17
    if prod(dims)!=size(ρ,1)
26✔
18
        throw(ArgumentError("Product of dimensions do not match shape of matrix."))
1✔
19
    end
20
    if maximum(systems) > length(dims) ||  minimum(systems) < 1
24✔
21
        throw(ArgumentError("System index out of range"))
1✔
22
    end
23

24
    offset = length(dims)
11✔
25
    tensor = reshape(ρ, [dims; dims]...)
11✔
26
    perm = collect(1:(2offset))
44✔
27
    for s in systems
11✔
28
        idx1 = findfirst(x->x==s, perm)
35✔
29
        idx2 = findfirst(x->x==(s + offset), perm)
79✔
30
        perm[idx1], perm[idx2] = perm[idx2], perm[idx1]
11✔
31
    end
22✔
32
    tensor = permutedims(tensor, invperm(perm))
11✔
33
    reshape(tensor, size(ρ))
11✔
34
end
35

36
"""
37
$(SIGNATURES)
38
- `ρ`: quantum state.
39
- `idims`: dimensins of subsystems.
40
- `sys`: transposed subsystem.
41
"""
42
ptranspose(ρ::AbstractMatrix, idims::Vector{Int}, sys::Int) = ptranspose(ρ, idims, [sys])
12✔
43

44
function _ptranspose(ρ::AbstractMatrix{<:Number}, idims::Vector{Int}, isystems::Vector{Int})
×
45
    ns = length(idims)
×
46

47
    ex1 = Expr(:ref, :x)
×
48
    ex2 = Expr(:ref, ρ)
×
49

50
    I = Expr(:tuple, [gensym() for _=1:ns]...)
×
51
    J = Expr(:tuple, [gensym() for _=1:ns]...)
×
52

53
    K = copy(I)
×
54
    L = copy(J)
×
55

56
    r = Expr(:tuple)
×
57
    for (k, (i, j)) in enumerate(zip(K.args, L.args))
×
58
        push!(r.args, :($i:$(idims[k])), :($j:$(idims[k])))
×
59
    end
×
60
    for s in isystems
×
61
        K.args[s], L.args[s] = L.args[s], K.args[s]
×
62
    end
×
63
    push!(ex1.args, I, J)
×
64
    push!(ex2.args, L, K)
×
65

66
    ex = Expr(:(:=), ex1, ex2)
×
67
    ex, r
×
68
    @eval @cast $ex $r
×
69
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc