/
measure.jl
72 lines (66 loc) · 1.97 KB
/
measure.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
export measure
"""
Computes the outcome probabilities for a quantum measurement. The conditional
probabilities are determined by the Born rule, ``P(i|j) = \\text{Tr}[\\Pi_i \\rho_j]``,
where ``\\Pi_j`` is a POVM element and ``\\rho_j`` is a density matrix.
Measurement of a single `Ket` or `State`:
measure(Π :: POVM, ρ :: State) :: Probabilities
measure(Π :: POVM, ψ :: Ket) :: Probabilities
measure(Π :: PVM, ρ :: State) :: Probabilities
measure(Π :: PVM, ψ :: Ket) :: Probabilities
Measurement of an ensemble of `Ket` or `State` types:
measure(Π :: POVM, ρ_states :: Vector{<:State}) :: Conditionals
measure(Π :: POVM, ψ_kets :: Vector{<:Ket}) :: Conditionals
measure(Π :: PVM, ρ_states :: Vector{<:State}) :: Conditionals
measure(Π :: PVM, ψ_kets :: Vector{<:Ket}) :: Conditionals
"""
function measure(
Π :: POVM,
ρ :: State
) :: Probabilities
Probabilities( real.(map(Π_el -> tr(Π_el * ρ), Π)) )
end
function measure(
Π :: PVM,
ρ :: State
) :: Probabilities
Probabilities( real.(map(Π_el -> Π_el' * ρ * Π_el, Π)))
end
function measure(
Π :: POVM,
states :: Vector{<:State}
) :: Conditionals
Conditionals( real.(tr.(transpose(states * transpose(Π))) ))
end
function measure(
Π :: PVM,
states :: Vector{<:State}
) :: Conditionals
Conditionals(
real.(hcat(map( ρ -> map(Π_el -> Π_el' * ρ * Π_el, Π), states)...))
)
end
function measure(
Π :: POVM,
ψ :: Ket
) :: Probabilities
Probabilities( real.(map( Π_el -> ψ' * Π_el * ψ, Π)) )
end
function measure(
Π :: PVM,
ψ :: Ket
) :: Probabilities
Probabilities( map( Π_el -> norm(Π_el' * ψ)^2, Π) )
end
function measure(
Π :: POVM,
ψ_kets :: Vector{<:Ket}
) :: Conditionals
measure(Π, pure_state.(ψ_kets))
end
function measure(
Π :: PVM,
ψ_kets :: Vector{<:Ket}
) :: Conditionals
Conditionals( hcat(map( ψ -> map(Π_el -> norm(Π_el' * ψ)^2, Π), ψ_kets)...) )
end