Skip to content

Commit

Permalink
introduce proj
Browse files Browse the repository at this point in the history
  • Loading branch information
ytdHuang committed Jun 3, 2024
1 parent daac4be commit a763c0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ LinearAlgebra.normalize!
unit
LinearAlgebra.inv
LinearAlgebra.diag
proj
ptrace
purity
tidyup
Expand Down
10 changes: 9 additions & 1 deletion src/qobj/arithmetic_and_attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Arithmetic and Attributes for QuantumObject

export trans, dag, dagger, matrix_element, unit
export sqrtm, logm, expm, sinm, cosm
export ptrace, purity
export proj, ptrace, purity
export tidyup, tidyup!
export get_data, get_coherence

Expand Down Expand Up @@ -558,6 +558,14 @@ LinearAlgebra.diag(
k::Int = 0,
) where {T,ObjType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} = diag(A.data, k)

@doc raw"""
proj(ψ::QuantumObject)
Return the projector for a [`Ket`](@ref) or [`Bra`](@Ref) type of [`QuantumObject`](@ref)
"""
proj::QuantumObject{<:AbstractArray{T},KetQuantumObject}) where {T} = ψ * ψ'
proj::QuantumObject{<:AbstractArray{T},BraQuantumObject}) where {T} = ψ' * ψ

@doc raw"""
ptrace(QO::QuantumObject, sel::Vector{Int})
Expand Down
2 changes: 1 addition & 1 deletion test/quantum_objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

N = 10
a = fock(N, 3)
@test sparse(ket2dm(a)) projection(N, 3, 3)
@test proj(a) proj(a') sparse(ket2dm(a)) projection(N, 3, 3)
@test isket(a') == false
@test isbra(a') == true
@test size(a) == (N,)
Expand Down

0 comments on commit a763c0b

Please sign in to comment.