|
65 | 65 | end |
66 | 66 | end |
67 | 67 |
|
68 | | -@testset "trace distance" begin |
| 68 | +@testset "trace and Hilbert-Schmidt distance" begin |
69 | 69 | ψz0 = basis(2, 0) |
70 | 70 | ψz1 = basis(2, 1) |
71 | 71 | ρz0 = to_sparse(ket2dm(ψz0)) |
|
76 | 76 | @test tracedist(ψz1, ρz0) ≈ 1.0 |
77 | 77 | @test tracedist(ρz0, ρz1) ≈ 1.0 |
78 | 78 |
|
| 79 | + ψ = rand_ket(10) |
| 80 | + ϕ = rand_ket(10) |
| 81 | + @test isapprox(tracedist(ψ, ϕ)^2, hilbert_dist(ψ, ϕ) / 2; atol = 1e-6) |
| 82 | + |
79 | 83 | @testset "Type Inference (trace distance)" begin |
80 | 84 | @inferred tracedist(ψz0, ψx0) |
81 | 85 | @inferred tracedist(ρz0, ψz1) |
82 | 86 | @inferred tracedist(ψz1, ρz0) |
83 | 87 | @inferred tracedist(ρz0, ρz1) |
84 | 88 | end |
| 89 | + |
| 90 | + @testset "Type Inference (Hilbert-Schmidt distance)" begin |
| 91 | + @inferred hilbert_dist(ψz0, ψx0) |
| 92 | + @inferred hilbert_dist(ρz0, ψz1) |
| 93 | + @inferred hilbert_dist(ψz1, ρz0) |
| 94 | + @inferred hilbert_dist(ρz0, ρz1) |
| 95 | + end |
85 | 96 | end |
86 | 97 |
|
87 | | -@testset "fidelity" begin |
88 | | - M = sprand(ComplexF64, 5, 5, 0.5) |
89 | | - M0 = Qobj(M * M') |
90 | | - ψ1 = Qobj(rand(ComplexF64, 5)) |
91 | | - ψ2 = Qobj(rand(ComplexF64, 5)) |
92 | | - M1 = ψ1 * ψ1' |
| 98 | +@testset "fidelity, Bures metric, and Hellinger distance" begin |
| 99 | + M0 = rand_dm(5) |
| 100 | + ψ1 = rand_ket(5) |
| 101 | + ψ2 = rand_ket(5) |
| 102 | + M1 = ket2dm(ψ1) |
| 103 | + b00 = bell_state(Val(0), Val(0)) |
| 104 | + b01 = bell_state(Val(0), Val(1)) |
93 | 105 | @test isapprox(fidelity(M0, M1), fidelity(ψ1, M0); atol = 1e-6) |
94 | 106 | @test isapprox(fidelity(ψ1, ψ2), fidelity(ket2dm(ψ1), ket2dm(ψ2)); atol = 1e-6) |
| 107 | + @test isapprox(fidelity(b00, b00), 1; atol = 1e-6) |
| 108 | + @test isapprox(bures_dist(b00, b00) + 1, 1; atol = 1e-6) |
| 109 | + @test isapprox(bures_angle(b00, b00) + 1, 1; atol = 1e-6) |
| 110 | + @test isapprox(hellinger_dist(b00, b00) + 1, 1; atol = 1e-6) |
| 111 | + @test isapprox(fidelity(b00, b01) + 1, 1; atol = 1e-6) |
| 112 | + @test isapprox(bures_dist(b00, b01), √2; atol = 1e-6) |
| 113 | + @test isapprox(bures_angle(b00, b01), π / 2; atol = 1e-6) |
| 114 | + @test isapprox(hellinger_dist(b00, b01), √2; atol = 1e-6) |
| 115 | + |
| 116 | + # some relations between Bures and Hellinger dintances |
| 117 | + # together with some monotonicity under tensor products |
| 118 | + # [see arXiv:1611.03449 (2017); section 4.2] |
| 119 | + ρA = rand_dm(5) |
| 120 | + ρB = rand_dm(6) |
| 121 | + ρAB = tensor(ρA, ρB) |
| 122 | + σA = rand_dm(5) |
| 123 | + σB = rand_dm(6) |
| 124 | + σAB = tensor(σA, σB) |
| 125 | + d_Bu_A = bures_dist(ρA, σA) |
| 126 | + d_Bu_AB = bures_dist(ρAB, σAB) |
| 127 | + d_He_A = hellinger_dist(ρA, σA) |
| 128 | + d_He_AB = hellinger_dist(ρAB, σAB) |
| 129 | + @test isapprox(fidelity(ρAB, σAB), fidelity(ρA, σA) * fidelity(ρB, σB); atol = 1e-6) |
| 130 | + @test d_He_AB >= d_Bu_AB |
| 131 | + @test d_Bu_AB >= d_Bu_A |
| 132 | + @test isapprox(bures_dist(ρAB, tensor(σA, ρB)), d_Bu_A; atol = 1e-6) |
| 133 | + @test d_He_AB >= d_He_A |
| 134 | + @test isapprox(hellinger_dist(ρAB, tensor(σA, ρB)), d_He_A; atol = 1e-6) |
95 | 135 |
|
96 | 136 | @testset "Type Inference (fidelity)" begin |
97 | 137 | @inferred fidelity(M0, M1) |
98 | 138 | @inferred fidelity(ψ1, M0) |
99 | 139 | @inferred fidelity(ψ1, ψ2) |
100 | 140 | end |
| 141 | + |
| 142 | + @testset "Type Inference (Hellinger distance)" begin |
| 143 | + @inferred hellinger_dist(M0, M1) |
| 144 | + @inferred hellinger_dist(ψ1, M0) |
| 145 | + @inferred hellinger_dist(ψ1, ψ2) |
| 146 | + end |
| 147 | + |
| 148 | + @testset "Type Inference (Bures metric)" begin |
| 149 | + @inferred bures_dist(M0, M1) |
| 150 | + @inferred bures_dist(ψ1, M0) |
| 151 | + @inferred bures_dist(ψ1, ψ2) |
| 152 | + @inferred bures_angle(M0, M1) |
| 153 | + @inferred bures_angle(ψ1, M0) |
| 154 | + @inferred bures_angle(ψ1, ψ2) |
| 155 | + end |
101 | 156 | end |
0 commit comments