You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/qobj/arithmetic_and_attributes.jl
+83-41Lines changed: 83 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -697,64 +697,96 @@ Returns the data of a [`AbstractQuantumObject`](@ref).
697
697
get_data(A::AbstractQuantumObject) = A.data
698
698
699
699
@docraw"""
700
-
get_coherence(ψ::QuantumObject)
700
+
get_coherence(ψ::QuantumObject; idx)
701
701
702
-
Returns the coherence value ``\alpha`` by measuring the expectation value of the destruction operator ``\hat{a}`` on a state ``\ket{\psi}`` or a density matrix ``\hat{\rho}``.
Returns the coherence value ``\alpha`` by measuring the expectation value of the destruction operator ``\hat{a}`` on a state ``\ket{\psi}``, density matrix ``\hat{\rho}`` or vectorized state ``|\hat{\rho}\rangle\rangle``.
710
703
711
-
x =0.0im
712
-
for J in off+2:length(ψ.data)
713
-
x += ψ[J] *conj(ψ[J-off]) *prod(sqrt.(_ind2sub(t, J) .-1))
704
+
If the state is a composite state, the coherence values of each subsystems are returned as an array of complex numbers. It is possible to specify the index of the sybsystem to get the coherence value by fixing `idx`.
705
+
"""
706
+
functionget_coherence(ψ::QuantumObject{T,KetQuantumObject,N}; idx::Union{Nothing,Int}=nothing) where {T,N}
Returns the corresponding state with the coherence removed: ``\ket{\delta_\alpha} = \exp ( \alpha^* \hat{a} - \alpha \hat{a}^\dagger ) \ket{\psi}`` for a pure state, and ``\hat{\rho_\alpha} = \exp ( \alpha^* \hat{a} - \alpha \hat{a}^\dagger ) \hat{\rho} \exp ( -\bar{\alpha} \hat{a} + \alpha \hat{a}^\dagger )`` for a density matrix. These states correspond to the quantum fluctuations around the coherent state ``\ket{\alpha}`` or ``|\alpha\rangle\langle\alpha|``.
functionremove_coherence(ρ::QuantumObject{T,OperatorQuantumObject}) where {T}
788
+
αs=get_coherence(ρ)
789
+
D =mapreduce(k ->displace(ρ.dims[k], αs[k]), ⊗, eachindex(ρ.dims))
758
790
759
791
return D'* ρ * D
760
792
end
@@ -764,7 +796,7 @@ end
764
796
765
797
Get the mean occupation number ``n`` by measuring the expectation value of the number operator ``\hat{n}`` on a state ``\ket{\psi}``, a density matrix ``\hat{\rho}`` or a vectorized density matrix ``\ket{\hat{\rho}}``.
766
798
767
-
It returns the expectation value of the number operator.
799
+
If the state is a composite state, the mean occupation numbers of each subsystems are returned as an array of real numbers. It is possible to specify the index of the sybsystem to get the mean occupation number by fixing `idx`.
768
800
"""
769
801
functionmean_occupation(ψ::QuantumObject{T,KetQuantumObject}; idx::Union{Int,Nothing}=nothing) where {T}
770
802
t =Tuple(reverse(ψ.dims))
@@ -785,7 +817,6 @@ function mean_occupation(ρ::QuantumObject{T,OperatorQuantumObject}; idx::Union{
785
817
t =Tuple(reverse(ρ.dims))
786
818
mean_occ =zeros(eltype(ρ.data), length(ρ.dims))
787
819
788
-
x =0.0im
789
820
for J ineachindex(ρ.data[:, 1])
790
821
sub_indices =_ind2sub(t, J) .-1
791
822
mean_occ .+= ρ[J, J] .* sub_indices
@@ -798,15 +829,26 @@ end
798
829
mean_occupation(ρ::QuantumObject{T,OperatorQuantumObject,1}) where {T} =
799
830
mapreduce(k -> ρ[k, k] * (k -1), +, 1:ρ.dims[1])
800
831
801
-
functionmean_occupation(v::QuantumObject{T,OperatorKetQuantumObject}) where {T}
802
-
iflength(v.dims) >1
803
-
throw(ArgumentError("Mean photon number not implemented for composite OPeratorKetQuantumObject"))
804
-
end
805
-
832
+
functionmean_occupation(v::QuantumObject{T,OperatorKetQuantumObject,1}) where {T}
0 commit comments