|
1 | | -export SpectrumSolver, FFTCorrelation, ExponentialSeries |
2 | | -export correlation_3op_2t, correlation_2op_2t, correlation_2op_1t, spectrum |
3 | | - |
4 | | -abstract type SpectrumSolver end |
5 | | - |
6 | | -struct FFTCorrelation <: SpectrumSolver end |
7 | | - |
8 | | -struct ExponentialSeries{T<:Real,CALC_SS} <: SpectrumSolver |
9 | | - tol::T |
10 | | - ExponentialSeries(tol::T, calc_steadystate::Bool = false) where {T} = new{T,calc_steadystate}(tol) |
11 | | -end |
12 | | - |
13 | | -ExponentialSeries(; tol = 1e-14, calc_steadystate = false) = ExponentialSeries(tol, calc_steadystate) |
| 1 | +export correlation_3op_2t, correlation_2op_2t, correlation_2op_1t |
14 | 2 |
|
15 | 3 | @doc raw""" |
16 | | - correlation_3op_2t(H::QuantumObject, |
17 | | - ψ0::QuantumObject, |
18 | | - t_l::AbstractVector, |
19 | | - τ_l::AbstractVector, |
| 4 | + correlation_3op_2t(H::AbstractQuantumObject, |
| 5 | + ψ0::Union{Nothing,QuantumObject}, |
| 6 | + tlist::AbstractVector, |
| 7 | + τlist::AbstractVector, |
| 8 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
20 | 9 | A::QuantumObject, |
21 | 10 | B::QuantumObject, |
22 | | - C::QuantumObject, |
23 | | - c_ops::Union{Nothing,AbstractVector,Tuple}=nothing; |
| 11 | + C::QuantumObject; |
24 | 12 | kwargs...) |
25 | 13 |
|
26 | | -Returns the two-times correlation function of three operators ``\hat{A}``, ``\hat{B}`` and ``\hat{C}``: ``\left\langle \hat{A}(t) \hat{B}(t + \tau) \hat{C}(t) \right\rangle`` |
| 14 | +Returns the two-times correlation function of three operators ``\hat{A}``, ``\hat{B}`` and ``\hat{C}``: ``\left\langle \hat{A}(t) \hat{B}(t + \tau) \hat{C}(t) \right\rangle`` for a given initial state ``|\psi_0\rangle``. |
27 | 15 |
|
28 | | -for a given initial state ``\ket{\psi_0}``. |
| 16 | +If the initial state `ψ0` is given as `nothing`, then the [`steadystate`] will be used as the initial state. Note that this is only implemented if `H` is constant ([`QuantumObject`](@ref)). |
29 | 17 | """ |
30 | 18 | function correlation_3op_2t( |
31 | | - H::QuantumObject{<:AbstractArray{T1},HOpType}, |
32 | | - ψ0::QuantumObject{<:AbstractArray{T2},StateOpType}, |
33 | | - t_l::AbstractVector, |
34 | | - τ_l::AbstractVector, |
35 | | - A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
36 | | - B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject}, |
37 | | - C::QuantumObject{<:AbstractArray{T5},OperatorQuantumObject}, |
38 | | - c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; |
| 19 | + H::AbstractQuantumObject{DataType,HOpType}, |
| 20 | + ψ0::Union{Nothing,QuantumObject{<:AbstractArray{T1},StateOpType}}, |
| 21 | + tlist::AbstractVector, |
| 22 | + τlist::AbstractVector, |
| 23 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
| 24 | + A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
| 25 | + B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
| 26 | + C::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject}; |
39 | 27 | kwargs..., |
40 | 28 | ) where { |
| 29 | + DataType, |
41 | 30 | T1, |
42 | 31 | T2, |
43 | 32 | T3, |
44 | 33 | T4, |
45 | | - T5, |
46 | 34 | HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, |
47 | 35 | StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}, |
48 | 36 | } |
49 | | - allequal((H.dims, ψ0.dims, A.dims, B.dims, C.dims)) || throw(DimensionMismatch("The quantum objects are not of the same Hilbert dimension.")) |
| 37 | + L = liouvillian(H, c_ops) |
| 38 | + if ψ0 isa Nothing |
| 39 | + ψ0 = steadystate(L) |
| 40 | + end |
| 41 | + |
| 42 | + allequal((L.dims, ψ0.dims, A.dims, B.dims, C.dims)) || throw(DimensionMismatch("The quantum objects are not of the same Hilbert dimension.")) |
50 | 43 |
|
51 | | - kwargs2 = merge((saveat = collect(t_l),), (; kwargs...)) |
52 | | - ρt = mesolve(H, ψ0, t_l, c_ops; kwargs2...).states |
| 44 | + kwargs2 = merge((saveat = collect(tlist),), (; kwargs...)) |
| 45 | + ρt = mesolve(L, ψ0, tlist; kwargs2...).states |
53 | 46 |
|
54 | | - corr = map((t, ρ) -> mesolve(H, C * ρ * A, τ_l .+ t, c_ops, e_ops = [B]; kwargs...).expect[1, :], t_l, ρt) |
| 47 | + corr = map((t, ρ) -> mesolve(L, C * ρ * A, τlist .+ t, e_ops = [B]; kwargs...).expect[1, :], tlist, ρt) |
55 | 48 |
|
56 | 49 | return corr |
57 | 50 | end |
58 | 51 |
|
59 | 52 | @doc raw""" |
60 | | - correlation_2op_2t(H::QuantumObject, |
61 | | - ψ0::QuantumObject, |
62 | | - t_l::AbstractVector, |
63 | | - τ_l::AbstractVector, |
| 53 | + correlation_2op_2t(H::AbstractQuantumObject, |
| 54 | + ψ0::Union{Nothing,QuantumObject}, |
| 55 | + tlist::AbstractVector, |
| 56 | + τlist::AbstractVector, |
| 57 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
64 | 58 | A::QuantumObject, |
65 | | - B::QuantumObject, |
66 | | - c_ops::Union{Nothing,AbstractVector,Tuple}=nothing; |
| 59 | + B::QuantumObject; |
67 | 60 | reverse::Bool=false, |
68 | 61 | kwargs...) |
69 | 62 |
|
70 | | -Returns the two-times correlation function of two operators ``\hat{A}`` and ``\hat{B}`` |
71 | | -at different times: ``\left\langle \hat{A}(t + \tau) \hat{B}(t) \right\rangle``. |
| 63 | +Returns the two-times correlation function of two operators ``\hat{A}`` and ``\hat{B}`` : ``\left\langle \hat{A}(t + \tau) \hat{B}(t) \right\rangle`` for a given initial state ``|\psi_0\rangle``. |
| 64 | +
|
| 65 | +If the initial state `ψ0` is given as `nothing`, then the [`steadystate`] will be used as the initial state. Note that this is only implemented if `H` is constant ([`QuantumObject`](@ref)). |
72 | 66 |
|
73 | 67 | When `reverse=true`, the correlation function is calculated as ``\left\langle \hat{A}(t) \hat{B}(t + \tau) \right\rangle``. |
74 | 68 | """ |
75 | 69 | function correlation_2op_2t( |
76 | | - H::QuantumObject{<:AbstractArray{T1},HOpType}, |
77 | | - ψ0::QuantumObject{<:AbstractArray{T2},StateOpType}, |
78 | | - t_l::AbstractVector, |
79 | | - τ_l::AbstractVector, |
80 | | - A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
81 | | - B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject}, |
82 | | - c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; |
| 70 | + H::AbstractQuantumObject{DataType,HOpType}, |
| 71 | + ψ0::Union{Nothing,QuantumObject{<:AbstractArray{T1},StateOpType}}, |
| 72 | + tlist::AbstractVector, |
| 73 | + τlist::AbstractVector, |
| 74 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
| 75 | + A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
| 76 | + B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}; |
83 | 77 | reverse::Bool = false, |
84 | 78 | kwargs..., |
85 | 79 | ) where { |
| 80 | + DataType, |
86 | 81 | T1, |
87 | 82 | T2, |
88 | 83 | T3, |
89 | | - T4, |
90 | 84 | HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, |
91 | 85 | StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}, |
92 | 86 | } |
93 | 87 | C = eye(prod(H.dims), dims = H.dims) |
94 | 88 | if reverse |
95 | | - corr = correlation_3op_2t(H, ψ0, t_l, τ_l, A, B, C, c_ops; kwargs...) |
| 89 | + corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, A, B, C; kwargs...) |
96 | 90 | else |
97 | | - corr = correlation_3op_2t(H, ψ0, t_l, τ_l, C, A, B, c_ops; kwargs...) |
| 91 | + corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, C, A, B; kwargs...) |
98 | 92 | end |
99 | 93 |
|
100 | 94 | return reduce(hcat, corr) |
101 | 95 | end |
102 | 96 |
|
103 | 97 | @doc raw""" |
104 | | - correlation_2op_1t(H::QuantumObject, |
105 | | - ψ0::QuantumObject, |
106 | | - τ_l::AbstractVector, |
| 98 | + correlation_2op_1t(H::AbstractQuantumObject, |
| 99 | + ψ0::Union{Nothing,QuantumObject}, |
| 100 | + τlist::AbstractVector, |
| 101 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
107 | 102 | A::QuantumObject, |
108 | | - B::QuantumObject, |
109 | | - c_ops::Union{Nothing,AbstractVector,Tuple}=nothing; |
| 103 | + B::QuantumObject; |
110 | 104 | reverse::Bool=false, |
111 | 105 | kwargs...) |
112 | 106 |
|
113 | | -Returns the one-time correlation function of two operators ``\hat{A}`` and ``\hat{B}`` at different times ``\left\langle \hat{A}(\tau) \hat{B}(0) \right\rangle``. |
| 107 | +Returns the one-time correlation function of two operators ``\hat{A}`` and ``\hat{B}`` : ``\left\langle \hat{A}(\tau) \hat{B}(0) \right\rangle`` for a given initial state ``|\psi_0\rangle``. |
| 108 | +
|
| 109 | +If the initial state `ψ0` is given as `nothing`, then the [`steadystate`] will be used as the initial state. Note that this is only implemented if `H` is constant ([`QuantumObject`](@ref)). |
114 | 110 |
|
115 | 111 | When `reverse=true`, the correlation function is calculated as ``\left\langle \hat{A}(0) \hat{B}(\tau) \right\rangle``. |
116 | 112 | """ |
117 | 113 | function correlation_2op_1t( |
118 | | - H::QuantumObject{<:AbstractArray{T1},HOpType}, |
119 | | - ψ0::QuantumObject{<:AbstractArray{T2},StateOpType}, |
120 | | - τ_l::AbstractVector, |
121 | | - A::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
122 | | - B::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject}, |
123 | | - c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; |
| 114 | + H::AbstractQuantumObject{DataType,HOpType}, |
| 115 | + ψ0::Union{Nothing,QuantumObject{<:AbstractArray{T1},StateOpType}}, |
| 116 | + τlist::AbstractVector, |
| 117 | + c_ops::Union{Nothing,AbstractVector,Tuple}, |
| 118 | + A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
| 119 | + B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}; |
124 | 120 | reverse::Bool = false, |
125 | 121 | kwargs..., |
126 | 122 | ) where { |
| 123 | + DataType, |
127 | 124 | T1, |
128 | 125 | T2, |
129 | 126 | T3, |
130 | | - T4, |
131 | 127 | HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, |
132 | 128 | StateOpType<:Union{KetQuantumObject,OperatorQuantumObject}, |
133 | 129 | } |
134 | | - corr = correlation_2op_2t(H, ψ0, [0], τ_l, A, B, c_ops; reverse = reverse, kwargs...) |
| 130 | + corr = correlation_2op_2t(H, ψ0, [0], τlist, c_ops, A, B; reverse = reverse, kwargs...) |
135 | 131 |
|
136 | 132 | return corr[:, 1] |
137 | 133 | end |
138 | | - |
139 | | -@doc raw""" |
140 | | - spectrum(H::QuantumObject, |
141 | | - ω_list::AbstractVector, |
142 | | - A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
143 | | - B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
144 | | - c_ops::Union{Nothing,AbstractVector,Tuple}=nothing; |
145 | | - solver::SpectrumSolver=ExponentialSeries(), |
146 | | - kwargs...) |
147 | | -
|
148 | | -Returns the emission spectrum |
149 | | -
|
150 | | -```math |
151 | | -S(\omega) = \int_{-\infty}^\infty \left\langle \hat{A}(\tau) \hat{B}(0) \right\rangle e^{-i \omega \tau} d \tau |
152 | | -``` |
153 | | -""" |
154 | | -function spectrum( |
155 | | - H::QuantumObject{MT1,HOpType}, |
156 | | - ω_list::AbstractVector, |
157 | | - A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
158 | | - B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
159 | | - c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; |
160 | | - solver::SpectrumSolver = ExponentialSeries(), |
161 | | - kwargs..., |
162 | | -) where { |
163 | | - MT1<:AbstractMatrix, |
164 | | - T2, |
165 | | - T3, |
166 | | - HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, |
167 | | -} |
168 | | - return _spectrum(H, ω_list, A, B, c_ops, solver; kwargs...) |
169 | | -end |
170 | | - |
171 | | -function _spectrum( |
172 | | - H::QuantumObject{<:AbstractArray{T1},HOpType}, |
173 | | - ω_list::AbstractVector, |
174 | | - A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
175 | | - B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
176 | | - c_ops, |
177 | | - solver::FFTCorrelation; |
178 | | - kwargs..., |
179 | | -) where {T1,T2,T3,HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} |
180 | | - Nsamples = length(ω_list) |
181 | | - ω_max = abs(maximum(ω_list)) |
182 | | - dω = 2 * ω_max / (Nsamples - 1) |
183 | | - ω_l = -ω_max:dω:ω_max |
184 | | - |
185 | | - T = 2π / (ω_l[2] - ω_l[1]) |
186 | | - τ_l = range(0, T, length = length(ω_l)) |
187 | | - |
188 | | - ρss = steadystate(H, c_ops) |
189 | | - corr = correlation_2op_1t(H, ρss, τ_l, A, B, c_ops; kwargs...) |
190 | | - |
191 | | - S = fftshift(fft(corr)) / length(τ_l) |
192 | | - |
193 | | - return ω_l, 2 .* real.(S) |
194 | | -end |
195 | | - |
196 | | -function _spectrum_get_rates_vecs_ss(L, solver::ExponentialSeries{T,true}) where {T} |
197 | | - result = eigen(L) |
198 | | - rates, vecs = result.values, result.vectors |
199 | | - |
200 | | - return rates, vecs, steadystate(L).data |
201 | | -end |
202 | | - |
203 | | -function _spectrum_get_rates_vecs_ss(L, solver::ExponentialSeries{T,false}) where {T} |
204 | | - result = eigen(L) |
205 | | - rates, vecs = result.values, result.vectors |
206 | | - |
207 | | - ss_idx = findmin(abs2, rates)[2] |
208 | | - ρss = vec2mat(@view(vecs[:, ss_idx])) |
209 | | - ρss = (ρss + ρss') / 2 |
210 | | - ρss ./= tr(ρss) |
211 | | - |
212 | | - return rates, vecs, ρss |
213 | | -end |
214 | | - |
215 | | -function _spectrum( |
216 | | - H::QuantumObject{<:AbstractArray{T1},HOpType}, |
217 | | - ω_list::AbstractVector, |
218 | | - A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject}, |
219 | | - B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject}, |
220 | | - c_ops, |
221 | | - solver::ExponentialSeries; |
222 | | - kwargs..., |
223 | | -) where {T1,T2,T3,HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} |
224 | | - allequal((H.dims, A.dims, B.dims)) || throw(DimensionMismatch("The dimensions of H, A and B must be the same")) |
225 | | - |
226 | | - L = liouvillian(H, c_ops) |
227 | | - |
228 | | - rates, vecs, ρss = _spectrum_get_rates_vecs_ss(L, solver) |
229 | | - |
230 | | - ρ0 = B.data * ρss |
231 | | - v = vecs \ mat2vec(ρ0) |
232 | | - |
233 | | - amps = map(i -> v[i] * tr(A.data * vec2mat(@view(vecs[:, i]))), eachindex(rates)) |
234 | | - idxs = findall(x -> abs(x) > solver.tol, amps) |
235 | | - amps, rates = amps[idxs], rates[idxs] |
236 | | - |
237 | | - # spec = map(ω -> 2 * real(sum(@. amps * (1 / (1im * ω - rates)))), ω_list) |
238 | | - amps_rates = zip(amps, rates) |
239 | | - spec = map(ω -> 2 * real(sum(x -> x[1] / (1im * ω - x[2]), amps_rates)), ω_list) |
240 | | - |
241 | | - return spec |
242 | | -end |
0 commit comments