You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/entropy.jl
+16-6Lines changed: 16 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -195,7 +195,7 @@ Calculates the [entanglement entropy](https://en.wikipedia.org/wiki/Entropy_of_e
195
195
196
196
# Notes
197
197
198
-
- `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref).
198
+
- `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref). But should be a pure state.
199
199
- `sel` specifies the indices of the remaining sub-system. See also [`ptrace`](@ref).
200
200
- `kwargs` are the keyword arguments for calculating Von Neumann entropy. See also [`entropy_vn`](@ref).
201
201
"""
@@ -204,10 +204,16 @@ function entanglement(
204
204
sel::Union{Int,AbstractVector{Int},Tuple},
205
205
kwargs...,
206
206
) where {OpType<:Union{KetQuantumObject,OperatorQuantumObject}}
207
-
_ρ =normalize(ρ)
208
-
ρ_tr =ptrace(_ρ, sel)
207
+
p =purity(ρ)
208
+
isapprox(p, 1; atol =1e-2) ||throw(
209
+
ArgumentError(
210
+
"The entanglement entropy only works for normalized pure state, the purity of the given state: $(p) ≉ 1",
211
+
),
212
+
)
213
+
214
+
ρ_tr =ptrace(ρ, sel)
209
215
val =entropy_vn(ρ_tr; kwargs...)
210
-
return(val>0) * val
216
+
returnmax(0.0, val) # use 0.0 to make sure it always return value in Float-type
211
217
end
212
218
213
219
@docraw"""
@@ -220,7 +226,11 @@ Calculate the [concurrence](https://en.wikipedia.org/wiki/Concurrence_(quantum_c
220
226
- `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref).
221
227
"""
222
228
functionconcurrence(ρ::QuantumObject{OpType}) where {OpType<:Union{KetQuantumObject,OperatorQuantumObject}}
223
-
(ρ.dimensions ==Dimensions((Space(2), Space(2)))) ||throw(ArgumentError("The `concurrence` only support for a two-qubit state, invalid dims = $(_get_dims_string(ρ.dimensions))."))
0 commit comments