Skip to content

Commit c5d8b68

Browse files
committed
minor changes
1 parent c540cef commit c5d8b68

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/entropy.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,10 @@ Here, ``S`` is the [Von Neumann entropy](https://en.wikipedia.org/wiki/Von_Neuma
150150
"""
151151
function entropy_mutual(
152152
ρAB::QuantumObject{ObjType,<:AbstractDimensions{N}},
153-
selA::AType,
154-
selB::BType;
153+
selA::Union{Int,AbstractVector{Int},Tuple},
154+
selB::Union{Int,AbstractVector{Int},Tuple};
155155
kwargs...,
156-
) where {
157-
ObjType<:Union{KetQuantumObject,OperatorQuantumObject},
158-
N,
159-
AType<:Union{Int,AbstractVector{Int},Tuple},
160-
BType<:Union{Int,AbstractVector{Int},Tuple},
161-
}
156+
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject},N}
162157
# check if selA and selB matches the dimensions of ρAB
163158
sel_A_B = (selA..., selB...)
164159
(length(sel_A_B) != N) && throw(
@@ -188,22 +183,29 @@ Here, ``S`` is the [Von Neumann entropy](https://en.wikipedia.org/wiki/Von_Neuma
188183
"""
189184
entropy_conditional(
190185
ρAB::QuantumObject{ObjType,<:AbstractDimensions{N}},
191-
selB::BType;
186+
selB::Union{Int,AbstractVector{Int},Tuple};
192187
kwargs...,
193-
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject},N,BType<:Union{Int,AbstractVector{Int},Tuple}} =
188+
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject},N} =
194189
entropy_vn(ρAB; kwargs...) - entropy_vn(ptrace(ρAB, selB); kwargs...)
195190

196-
"""
197-
entanglement(QO::QuantumObject, sel::Union{Int,AbstractVector{Int},Tuple})
191+
@doc raw"""
192+
entanglement(ρ::QuantumObject, sel; kwargs...)
193+
194+
Calculates the [entanglement entropy](https://en.wikipedia.org/wiki/Entropy_of_entanglement) by doing the partial trace of `ρ`, selecting only the dimensions with the indices contained in the `sel` vector, and then use the Von Neumann entropy [`entropy_vn`](@ref).
198195
199-
Calculates the entanglement by doing the partial trace of `QO`, selecting only the dimensions with the indices contained in the `sel` vector, and then using the Von Neumann entropy [`entropy_vn`](@ref).
196+
# Notes
197+
198+
- `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref).
199+
- `sel` specifies the indices of the remaining sub-system. See also [`ptrace`](@ref).
200+
- `kwargs` are the keyword arguments for calculating Von Neumann entropy. See also [`entropy_vn`](@ref).
200201
"""
201202
function entanglement(
202-
QO::QuantumObject{OpType},
203+
ρ::QuantumObject{OpType},
203204
sel::Union{Int,AbstractVector{Int},Tuple},
204-
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
205-
ψ = normalize(QO)
206-
ρ_tr = ptrace(ψ, sel)
207-
entropy = entropy_vn(ρ_tr)
208-
return (entropy > 0) * entropy
205+
kwargs...,
206+
) where {OpType<:Union{KetQuantumObject,OperatorQuantumObject}}
207+
= normalize(ρ)
208+
ρ_tr = ptrace(_ρ, sel)
209+
val = entropy_vn(ρ_tr; kwargs...)
210+
return (val > 0) * val
209211
end

0 commit comments

Comments
 (0)