|
56 | 56 | using QuantumOpticsBase |
57 | 57 | import QuantumOpticsBase: entanglement_entropy |
58 | 58 |
|
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 |
60 | 60 | 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 |
66 | 67 |
|
67 | 68 | if !isempty(intersect(subsystem_rangeA, subsystem_rangeB)) |
68 | 69 | @test_throws ArgumentError mutual_information(copy(s), subsystem_rangeA, subsystem_rangeB, Val(:clip)) |
|
82 | 83 | @test mi_clip ≥ 0 |
83 | 84 | ψ = Ket(s) |
84 | 85 | ρ = 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). |
89 | 91 | mi_indep = (S_A + S_B - S_AB) / (2 * log(2)) |
90 | 92 | @test isapprox(mi_clip, mi_indep; atol=1e-6) |
91 | 93 | else |
|
0 commit comments