diff --git a/docs/src/api.md b/docs/src/api.md index 3113534a..a5eeee85 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -68,6 +68,7 @@ LinearAlgebra.normalize! unit LinearAlgebra.inv LinearAlgebra.diag +proj ptrace purity tidyup diff --git a/src/qobj/arithmetic_and_attributes.jl b/src/qobj/arithmetic_and_attributes.jl index 9c1271d1..18a37a68 100644 --- a/src/qobj/arithmetic_and_attributes.jl +++ b/src/qobj/arithmetic_and_attributes.jl @@ -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 @@ -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}) diff --git a/test/quantum_objects.jl b/test/quantum_objects.jl index f8e89aaa..19ebbc4b 100644 --- a/test/quantum_objects.jl +++ b/test/quantum_objects.jl @@ -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,)