Skip to content

Commit

Permalink
Extend method for ptrace and entanglement
Browse files Browse the repository at this point in the history
  • Loading branch information
ytdHuang committed Mar 19, 2024
1 parent cd0bfa6 commit 5c7911c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/general_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function ptrace(QO::QuantumObject{<:AbstractArray{T1},OpType}, sel::Vector{T2})
return QuantumObject(ρtr, dims=dkeep)
end
end
ptrace(QO::QuantumObject, sel::Int) = ptrace(QO, [sel])

@doc raw"""
entropy_vn(ρ::QuantumObject; base::Int=0, tol::Real=1e-15)
Expand Down Expand Up @@ -241,6 +242,7 @@ function entanglement(QO::QuantumObject{<:AbstractArray{T},OpType}, sel::Vector{
entropy = entropy_vn(ρ_tr)
return (entropy > 0) * entropy
end
entanglement(QO::QuantumObject, sel::Int) = entanglement(QO, [sel])

@doc raw"""
expect(O::QuantumObject, ψ::QuantumObject)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end
sol_me = mesolve(H, psi0, t_l, c_ops, e_ops=[sp1 * sm1, sp2 * sm2], progress=false)
sol_mc = mcsolve(H, psi0, t_l, c_ops, n_traj=500, e_ops=[sp1 * sm1, sp2 * sm2], progress=false)
@test sum(abs.(sol_mc.expect[1:2, :] .- sol_me.expect[1:2, :])) / length(t_l) < 0.1
@test expect(sp1 * sm1, sol_me.states[end]) expect(sigmap() * sigmam(), ptrace(sol_me.states[end], [1]))
@test expect(sp1 * sm1, sol_me.states[end]) expect(sigmap() * sigmam(), ptrace(sol_me.states[end], 1))
end

@testset "Dynamical Fock Dimension mesolve" begin
Expand Down Expand Up @@ -560,7 +560,7 @@ end
e = fock(2, 0)
state = normalize(kron(g, e) + kron(e, g))
rho = state * state'
@test entanglement(state, [1]) / log(2) 1
@test entanglement(state, 1) / log(2) 1
end

@testset "Wigner" begin
Expand Down

0 comments on commit 5c7911c

Please sign in to comment.