Skip to content

Commit 92c96ec

Browse files
committed
fixup
1 parent 0a9c685 commit 92c96ec

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test/test_entanglement.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@
5656
using QuantumOpticsBase
5757
import QuantumOpticsBase: entanglement_entropy
5858

59-
for n in test_sizes[3:end]
59+
for n in [4, 5, 6, 7] # exclude larger test sizes to avoid out of memory error
6060
s = random_stabilizer(n)
61-
endpointsA = sort(rand(1:n÷2, 2))
62-
subsystem_rangeA = endpointsA[1]:endpointsA[2]
63-
startB = endpointsA[2]+rand(1:3)
64-
endB = rand(startB:n)
65-
subsystem_rangeB = startB:endB
61+
a_start = rand(1:max(1, n-2))
62+
a_end = rand(a_start:min(n-1, a_start+2))
63+
subsystem_rangeA = a_start:a_end
64+
b_start = min(n, a_end + rand(1:2))
65+
b_end = rand(b_start:n)
66+
subsystem_rangeB = b_start:b_end
6667

6768
if !isempty(intersect(subsystem_rangeA, subsystem_rangeB))
6869
@test_throws ArgumentError mutual_information(copy(s), subsystem_rangeA, subsystem_rangeB, Val(:clip))
@@ -82,10 +83,11 @@
8283
@test mi_clip 0
8384
ψ = Ket(s)
8485
ρ = dm(ψ)
85-
S_A = entanglement_entropy(ρ, subsystem_rangeA, entropy_vn)
86-
S_B = entanglement_entropy(ρ, subsystem_rangeB, entropy_vn)
87-
# If A ∪ B covers the full system (1:n), set S_AB = 0
88-
S_AB = union_AB == (1:n) ? 0.0 : entanglement_entropy(ρ, union_AB, entropy_vn)
86+
S_A = QuantumOpticsBase.entanglement_entropy(ρ, subsystem_rangeA, entropy_vn)
87+
S_B = QuantumOpticsBase.entanglement_entropy(ρ, subsystem_rangeB, entropy_vn)
88+
# If A ∪ B covers the full system (1:n), set S_AB = 0 to avoid an invalid full-system trace in entanglement_entropy
89+
S_AB = union_AB == (1:n) ? 0.0 : QuantumOpticsBase.entanglement_entropy(ρ, union_AB, entropy_vn)
90+
# For a pure state: I(A:B) = [S(A) + S(B) - S(A∪B)] / 2, and convert nats → bits by dividing by log(2).
8991
mi_indep = (S_A + S_B - S_AB) / (2 * log(2))
9092
@test isapprox(mi_clip, mi_indep; atol=1e-6)
9193
else

0 commit comments

Comments
 (0)