Closed GTorlai closed 3 years ago
Design for quantum state fidelity:
"""
Quantum state fidelity between two wavefunctions.
F = |⟨ψ|ϕ⟩|²
"""
function fidelity(ψ::MPS, ϕ::MPS)
log_F̃ = 2.0 * real(loginner(ψ, ϕ))
log_K = 2.0 * (lognorm(ψ) + lognorm(ϕ))
fidelity = exp(log_F̃ - log_K)
return fidelity
end
"""
Quantum state fidelity between an MPS wavefunction and a
density operator.
F = ⟨ψ|ρ|ψ⟩
"""
function fidelity(ψ::MPS, ρ::MPO)
log_F̃ = log(abs(inner(ψ, ρ, ψ)))
log_K = 2 * lognorm(ψ) + log(real(tr(ρ)))
fidelity = exp(log_F̃ - log_K)
return fidelity
end
"""
Quantum state fidelity between an MPS wavefunction and a
LPDO density operator.
F = ⟨ψ|ϱ|ψ⟩=|X†|ψ⟩|²
"""
function fidelity(Ψ::MPS, ϱ::LPDO{MPO})
proj = bra(ϱ) * Ψ
return inner(proj,proj)
end
"""
Quantum state fidelity between two MPO density matrices.
F = (tr[√(√A B √A)])²
"""
fidelity(ρ::MPO, σ::MPO) = fidelity(prod(ρ), prod(σ))
"""
Quantum state fidelity between two LPDO density matrices.
F = (tr[√(√A B √A)])²
"""
fidelity(ρ::LPDO{MPO}, σ::LPDO{MPO}) = fidelity(MPO(ρ), MPO(σ))
# add this for consistency with `processtomography`
const statefidelity = fidelity
Design for quantum process fidelity. The function _choifidelity
should be replaced with the inner
between a MPS and MPO with two site indices.
"""
1. Quantum process fidelity between two MPO unitary operators.
F = |⟨⟨A|B⟩⟩|²
2. Quantum process fidelity bewteen a MPO unitary and MPO Choi matrix
F = ⟨⟨A|B|A⟩⟩
3. Quantum process fidelity bewteen two MPO Choi matrices
F = (Tr[√(√A B √A)])²
"""
function processfidelity(A::MPO, B::MPO)
# check whether a MPO is Choi or not (from number of site indices)
# 1: unitary - unitary
(!ischoi(A) && !ischoi(B)) && return fidelity(_UnitaryMPOtoChoiMPS(A), _UnitaryMPOtoChoiMPS(B))
# 2: unitary - Choi MPO
(!ischoi(A) && ischoi(B)) && return _choifidelity(_UnitaryMPOtoChoiMPS(A),B)
# 2reverse: Choi MPO - unitary
(ischoi(A) && !ischoi(B)) && return _choifidelity(B,_UnitaryMPOtoChoiMPS(A))
# : Choi MPO - Choi MPO
return fidelity(A,B)
end
"""
1. Quantum process fidelity between a unitary MPO and a Choi LPDO.
F = ⟨ψ|ϱ|ψ⟩=|X†|ψ⟩|²
2. Quantum process fidelity bewteen a Choi MPO and a Choi LPDO
"""
function processfidelity(A::MPO, Λ::LPDO{MPO})
#1: Choi MPO - Choi LPDO
(!ischoi(A)) && fidelity(_UnitaryMPOtoChoiMPS(A),Λ)#processfidelity(A, MPO(L))
return fidelity(A, MPO(Λ))
end
processfidelity(Λ::LPDO, A::MPO) = processfidelity(Λ, L)
"""
Quantum process fidelity between two LPDO Choi matrices
"""
processfidelity(A::LPDO{MPO}, B::LPDO{MPO}) = fidelity(MPO(A), MPO(B))
Extend the
inner
function to accommodate MPO and MPS with local tensors having two site indices.