@@ -3,7 +3,7 @@ Functions for calculating metrics (distance measures) between states and operato
33=#
44
55export fidelity
6- export tracedist, hilbert_dist
6+ export tracedist, hilbert_dist, hellinger_dist
77export bures_dist, bures_angle
88
99@doc raw """
@@ -65,6 +65,33 @@ function hilbert_dist(
6565 return tr (A' * A)
6666end
6767
68+ @doc raw """
69+ hellinger_dist(ρ::QuantumObject, σ::QuantumObject)
70+
71+ Calculates the [Hellinger distance](https://en.wikipedia.org/wiki/Hellinger_distance) between two [`QuantumObject`](@ref):
72+ ``D_H(\h at{\r ho}, \h at{\s igma}) = \s qrt{2 - 2 \t extrm{Tr}\l eft(\s qrt{\h at{\r ho}}\s qrt{\h at{\s igma}}\r ight)}``
73+
74+ Note that `ρ` and `σ` must be either [`Ket`](@ref) or [`Operator`](@ref).
75+
76+ # References
77+ - [Spehner2017](@citet)
78+ """
79+ function hellinger_dist (
80+ ρ:: QuantumObject{ObjType1} ,
81+ σ:: QuantumObject{ObjType2} ,
82+ ) where {
83+ ObjType1<: Union{KetQuantumObject,OperatorQuantumObject} ,
84+ ObjType2<: Union{KetQuantumObject,OperatorQuantumObject} ,
85+ }
86+ # Ket (pure state) doesn't need to do square root
87+ sqrt_ρ = (ρ isa KetQuantumObject) ? ket2dm (ρ) : sqrt (ρ)
88+ sqrt_σ = (σ isa KetQuantumObject) ? ket2dm (σ) : sqrt (σ)
89+
90+ # `max` is to avoid numerical instabilities
91+ # it happens when ρ = σ, sum(eigvals) might be slightly larger than 1
92+ return sqrt (2.0 * max (0.0 , 1.0 - sum (real, eigvals (sqrt_ρ * sqrt_σ))))
93+ end
94+
6895@doc raw """
6996 bures_dist(ρ::QuantumObject, σ::QuantumObject)
7097
0 commit comments