Skip to content

Commit 1f29fa8

Browse files
committed
introduce correlation_3op_1t
1 parent 34e6c49 commit 1f29fa8

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

docs/src/resources/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ lr_mesolve
230230

231231
```@docs
232232
correlation_3op_2t
233+
correlation_3op_1t
233234
correlation_2op_2t
234235
correlation_2op_1t
235236
spectrum_correlation_fft

src/correlations.jl

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
export correlation_3op_2t, correlation_2op_2t, correlation_2op_1t
1+
export correlation_3op_2t, correlation_3op_1t, correlation_2op_2t, correlation_2op_1t
2+
3+
function _check_correlation_time_list(tlist::AbstractVector)
4+
any(t -> t == 0, tlist) || throw(ArgumentError("The time list for calculating correlation function must contain the element `0`"))
5+
all(>=(0), tlist) || throw(ArgumentError("All the elements in the time list for calculating correlation function must be positive."))
6+
return nothing
7+
end
28

39
@doc raw"""
410
correlation_3op_2t(H::AbstractQuantumObject,
@@ -34,6 +40,10 @@ function correlation_3op_2t(
3440
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
3541
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
3642
}
43+
# check tlist and τlist
44+
_check_correlation_time_list(tlist)
45+
_check_correlation_time_list(τlist)
46+
3747
L = liouvillian(H, c_ops)
3848
if ψ0 isa Nothing
3949
ψ0 = steadystate(L)
@@ -47,7 +57,44 @@ function correlation_3op_2t(
4757

4858
corr = map((t, ρ) -> mesolve(L, C * ρ * A, τlist .+ t, e_ops = [B]; kwargs...).expect[1, :], tlist, ρt)
4959

50-
return corr
60+
return reduce(hcat, corr)
61+
end
62+
63+
@doc raw"""
64+
correlation_3op_1t(H::AbstractQuantumObject,
65+
ψ0::Union{Nothing,QuantumObject},
66+
τlist::AbstractVector,
67+
c_ops::Union{Nothing,AbstractVector,Tuple},
68+
A::QuantumObject,
69+
B::QuantumObject,
70+
C::QuantumObject;
71+
kwargs...)
72+
73+
Returns the one-time correlation function of three operators ``\hat{A}``, ``\hat{B}`` and ``\hat{C}``: ``\left\langle \hat{A}(0) \hat{B}(\tau) \hat{C}(0) \right\rangle`` for a given initial state ``|\psi_0\rangle``.
74+
75+
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)).
76+
"""
77+
function correlation_3op_1t(
78+
H::AbstractQuantumObject{DataType,HOpType},
79+
ψ0::Union{Nothing,QuantumObject{<:AbstractArray{T1},StateOpType}},
80+
τlist::AbstractVector,
81+
c_ops::Union{Nothing,AbstractVector,Tuple},
82+
A::QuantumObject{<:AbstractArray{T2},OperatorQuantumObject},
83+
B::QuantumObject{<:AbstractArray{T3},OperatorQuantumObject},
84+
C::QuantumObject{<:AbstractArray{T4},OperatorQuantumObject};
85+
kwargs...,
86+
) where {
87+
DataType,
88+
T1,
89+
T2,
90+
T3,
91+
T4,
92+
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
93+
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
94+
}
95+
corr = correlation_3op_2t(H, ψ0, [0], τlist, c_ops, A, B, C; kwargs...)
96+
97+
return corr[:, 1]
5198
end
5299

53100
@doc raw"""
@@ -92,7 +139,7 @@ function correlation_2op_2t(
92139
corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, C, A, B; kwargs...)
93140
end
94141

95-
return reduce(hcat, corr)
142+
return corr
96143
end
97144

98145
@doc raw"""

test/core-test/correlations_and_spectrum.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
@testset "Correlations and Spectrum" begin
2+
Id = qeye(10)
23
a = destroy(10)
34
H = a' * a
45
c_ops = [sqrt(0.1 * (0.01 + 1)) * a, sqrt(0.1 * (0.01)) * a']
56

67
t_l = range(0, 333 * π, length = 1000)
7-
corr = correlation_2op_1t(H, nothing, t_l, c_ops, a', a; progress_bar = Val(false))
8-
ω_l1, spec1 = spectrum_correlation_fft(t_l, corr)
8+
corr1 = correlation_2op_1t(H, nothing, t_l, c_ops, a', a; progress_bar = Val(false))
9+
corr2 = correlation_3op_1t(H, nothing, t_l, c_ops, Id, a', a; progress_bar = Val(false))
10+
ω_l1, spec1 = spectrum_correlation_fft(t_l, corr1)
911

1012
ω_l2 = range(0, 3, length = 1000)
1113
spec2 = spectrum(H, ω_l2, c_ops, a', a)
@@ -21,14 +23,25 @@
2123
idxs2 = test_func2 .> 0.05
2224
@test sum(abs2.(spec1[idxs1] .- test_func1[idxs1])) / sum(abs2.(test_func1[idxs1])) < 0.01
2325
@test sum(abs2.(spec2[idxs2] .- test_func2[idxs2])) / sum(abs2.(test_func2[idxs2])) < 0.01
26+
@test all(corr1 .≈ corr2)
2427
@test all(spec2 .≈ spec3)
2528

2629
@testset "Type Inference spectrum" begin
2730
@inferred correlation_2op_1t(H, nothing, t_l, c_ops, a', a; progress_bar = Val(false))
28-
@inferred spectrum_correlation_fft(t_l, corr)
31+
@inferred spectrum_correlation_fft(t_l, corr1)
2932
@inferred spectrum(H, ω_l2, c_ops, a', a)
3033
@inferred spectrum(H, ω_l2, c_ops, a', a; solver = PseudoInverse())
3134
end
3235

36+
t_wrong1 = [1, 2, 3]
37+
t_wrong2 = [-1, 0, 1]
38+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_l, t_wrong1, c_ops, Id, a', a)
39+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_l, t_wrong2, c_ops, Id, a', a)
40+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong1, t_l, c_ops, Id, a', a)
41+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong2, t_l, c_ops, Id, a', a)
42+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong1, t_wrong1, c_ops, Id, a', a)
43+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong1, t_wrong2, c_ops, Id, a', a)
44+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong2, t_wrong1, c_ops, Id, a', a)
45+
@test_throws ArgumentError correlation_3op_2t(H, nothing, t_wrong2, t_wrong2, c_ops, Id, a', a)
3346
@test_throws ErrorException FFTCorrelation()
3447
end

0 commit comments

Comments
 (0)