Skip to content

Commit

Permalink
Fix tracedist (#495)
Browse files Browse the repository at this point in the history
* fix tracedist 1/2 factor

* add make file for testing and doc

* rm makefile to avoid redun

---------

Co-authored-by: Xiu-zhe (Roger) Luo <rogerluo.rl18@gmail.com>
  • Loading branch information
exAClior and Roger-luo authored Mar 12, 2024
1 parent 888280c commit f44487b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/YaoAPI/src/registers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ Trace distance is defined as following:
\\frac{1}{2} || A - B ||_{\\rm tr}
```
It takes values between 0 and 1.
### Examples
```jldoctest; setup=:(using Yao)
Expand All @@ -672,7 +674,7 @@ julia> reg1 = uniform_state(3);
julia> reg2 = zero_state(3);
julia> tracedist(reg1, reg2)
1.8708286933869704
0.9354143466934852
```
### References
Expand Down
2 changes: 1 addition & 1 deletion lib/YaoArrayRegister/src/density_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end
YaoAPI.density_matrix(reg::ArrayReg{D}) where D = DensityMatrix{D}(reg.state * reg.state')
YaoAPI.density_matrix(rho::DensityMatrix) = copy(rho)

YaoAPI.tracedist(dm1::DensityMatrix{D}, dm2::DensityMatrix{D}) where {D} = trace_norm(dm1.state .- dm2.state)
YaoAPI.tracedist(dm1::DensityMatrix{D}, dm2::DensityMatrix{D}) where {D} = trace_norm(dm1.state .- dm2.state) / 2.0

"""
is_density_matrix(dm::AbstractMatrix; kw...)
Expand Down

0 comments on commit f44487b

Please sign in to comment.