Skip to content

Commit

Permalink
add a sugar for density matrix, cheers
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Jul 4, 2018
1 parent d14d244 commit ce2b421
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Registers/DensityMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ end
DensityMatrix(state::MT) where {T, MT<:AbstractArray{T, 3}} = DensityMatrix{size(state, 3), T, MT}(state)
DensityMatrix(state::MT) where {T, MT<:AbstractArray{T, 2}} = (state=state[:,:,1:1]; DensityMatrix{1, T, typeof(state)}(state))

"""
density_matrix(register)
Returns the density matrix of this register.
"""
function density_matrix end

"""
ρ(register)
Returns the density matrix of this register.
"""
const ρ = density_matrix

density_matrix(reg::DefaultRegister{1}) = DensityMatrix(reg.state*reg.state')

function density_matrix(reg::DefaultRegister{B}) where B
Expand Down
2 changes: 1 addition & 1 deletion src/Registers/Registers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export register, zero_state, rand_state, randn_state, stack, uniform_state

# bit_str
export @bit_str, asindex
export DensityMatrix, density_matrix
export DensityMatrix, density_matrix, ρ
export fidelity, tracedist


Expand Down

0 comments on commit ce2b421

Please sign in to comment.