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
@@ -663,64 +663,96 @@ Returns the data of a [`AbstractQuantumObject`](@ref).
663
663
get_data(A::AbstractQuantumObject) = A.data
664
664
665
665
@docraw"""
666
-
get_coherence(ψ::QuantumObject)
666
+
get_coherence(ψ::QuantumObject; idx)
667
667
668
-
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``.
676
669
677
-
x =0.0im
678
-
for J in off+2:length(ψ.data)
679
-
x += ψ[J] *conj(ψ[J-off]) *prod(sqrt.(_ind2sub(t, J) .-1))
670
+
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`.
671
+
"""
672
+
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}
754
+
αs=get_coherence(ρ)
755
+
D =mapreduce(k ->displace(ρ.dims[k], αs[k]), ⊗, eachindex(ρ.dims))
724
756
725
757
return D'* ρ * D
726
758
end
@@ -730,7 +762,7 @@ end
730
762
731
763
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}}``.
732
764
733
-
It returns the expectation value of the number operator.
765
+
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`.
734
766
"""
735
767
functionmean_occupation(ψ::QuantumObject{T,KetQuantumObject}; idx::Union{Int,Nothing}=nothing) where {T}
736
768
t =Tuple(reverse(ψ.dims))
@@ -751,7 +783,6 @@ function mean_occupation(ρ::QuantumObject{T,OperatorQuantumObject}; idx::Union{
751
783
t =Tuple(reverse(ρ.dims))
752
784
mean_occ =zeros(eltype(ρ.data), length(ρ.dims))
753
785
754
-
x =0.0im
755
786
for J ineachindex(ρ.data[:, 1])
756
787
sub_indices =_ind2sub(t, J) .-1
757
788
mean_occ .+= ρ[J, J] .* sub_indices
@@ -764,15 +795,26 @@ end
764
795
mean_occupation(ρ::QuantumObject{T,OperatorQuantumObject,1}) where {T} =
765
796
mapreduce(k -> ρ[k, k] * (k -1), +, 1:ρ.dims[1])
766
797
767
-
functionmean_occupation(v::QuantumObject{T,OperatorKetQuantumObject}) where {T}
768
-
iflength(v.dims) >1
769
-
throw(ArgumentError("Mean photon number not implemented for composite OPeratorKetQuantumObject"))
770
-
end
771
-
798
+
functionmean_occupation(v::QuantumObject{T,OperatorKetQuantumObject,1}) where {T}
0 commit comments