Skip to content

Commit 122ce91

Browse files
authored
add entanglement entropy (#6)
* add entanglement entropy * tests for entanglement_entropy * Improve docstring, dispatch for entanglement_entropy * Bump version v0.1.1 -> v0.1.2
1 parent bed32d5 commit 122ce91

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "QuantumOpticsBase"
22
uuid = "4f57444f-1401-5e15-980d-4471b28d5678"
3-
version = "v0.1.1"
3+
version = "v0.1.2"
44

55
[deps]
66
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"

src/QuantumOpticsBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export bases, Basis, GenericBasis, CompositeBasis, basis,
2828
metrics, tracenorm, tracenorm_h, tracenorm_nh,
2929
tracedistance, tracedistance_h, tracedistance_nh,
3030
entropy_vn, fidelity, ptranspose, PPT,
31-
negativity, logarithmic_negativity,
31+
negativity, logarithmic_negativity, entanglement_entropy,
3232
PauliBasis, PauliTransferMatrix, DensePauliTransferMatrix,
3333
ChiMatrix, DenseChiMatrix, avg_gate_fidelity
3434

src/metrics.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,46 @@ function avg_gate_fidelity(x::T, y::T) where T <: Union{PauliTransferMatrix{B, B
236236
dim = 2 ^ length(x.basis_l)
237237
return (tr(transpose(x.data) * y.data) + dim) / (dim^2 + dim)
238238
end
239+
240+
"""
241+
entanglement_entropy(state, partition, [entropy_fun=entropy_vn])
242+
243+
Computes the entanglement entropy of `state` between the list of sites `partition`
244+
and the rest of the system. The state must be defined in a composite basis.
245+
246+
If `state isa AbstractOperator` the operator-space entanglement entropy is
247+
computed, which has the property
248+
```julia
249+
entanglement_entropy(dm(ket)) = 2 * entanglement_entropy(ket)
250+
```
251+
252+
By default the computed entropy is the Von-Neumann entropy, but a different
253+
function can be provided (for example to compute the entanglement-renyi entropy).
254+
"""
255+
function entanglement_entropy(psi::Ket{B}, partition::Vector{Int}, entropy_fun=entropy_vn) where B<:CompositeBasis
256+
# check that sites are within the range
257+
@assert all(partition .<= length(psi.basis.bases))
258+
259+
rho = ptrace(psi, partition)
260+
return entropy_fun(rho)
261+
end
262+
263+
function entanglement_entropy(rho::DenseOperator{B,B}, partition::Vector{Int}, args...) where {B<:CompositeBasis}
264+
# check that sites is within the range
265+
hilb = rho.basis_l
266+
all(partition .<= length(hilb.bases)) || throw(ArgumentError("Indices in partition must be within the bounds of the composite basis."))
267+
length(partition) <= length(hilb.bases) || throw(ArgumentError("Partition cannot include the whole system."))
268+
269+
# build the doubled hilbert space for the vectorised dm, normalized like a Ket.
270+
b_doubled = hilb^2
271+
rho_vec = normalize!(Ket(b_doubled, vec(rho.data)))
272+
273+
return entanglement_entropy(rho_vec,
274+
vcat(partition, partition.+length(hilb.bases)),
275+
args...)
276+
end
277+
278+
entanglement_entropy(state, partition::Number, args...) =
279+
entanglement_entropy(state, [partition], args...)
280+
entanglement_entropy(state, partition, args...) =
281+
entanglement_entropy(state, collect(partition), args...)

test/test_metrics.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ rho = rho ⊗ dm(g)
9090
@test logarithmic_negativity(rho, 1) == logarithmic_negativity(rho, 2) 1.0
9191
@test isapprox(logarithmic_negativity(rho, 3), 0.0, atol=1e-15)
9292

93+
# Entanglement Entropy
94+
b1 = SpinBasis(1//2)
95+
psi = 1/sqrt(2)*(spinup(b1)spindown(b1) + spindown(b1)spinup(b1))
96+
rho_ent = dm(psi)
97+
rho_mix = DenseOperator(rho_ent.basis_l, diagm(ComplexF64[1.0,1.0,1.0,1.0]))
98+
@test entanglement_entropy(rho_mix, 1) 0.0
99+
@test entanglement_entropy(rho_ent, 1, entropy_vn) 2 * log(2)
100+
@test entanglement_entropy(rho_ent, 1) 2 * entanglement_entropy(psi, 1)
101+
@test_throws ArgumentError entanglement_entropy(rho_mix, (1,2))
102+
@test_throws ArgumentError entanglement_entropy(rho_mix, 3)
103+
93104
q2 = PauliBasis(2)
94105
CNOT = DenseOperator(q2, q2, diagm(0 => [1,1,0,0], 1 => [0,0,1], -1 => [0,0,1]))
95106
CNOT_sop = SuperOperator(CNOT)

0 commit comments

Comments
 (0)