Skip to content

Commit

Permalink
Rates spectrum (#402)
Browse files Browse the repository at this point in the history
* properly pass the kwarg rates to the function spectrum

* typo rates test
  • Loading branch information
ChristophHotter authored Jul 25, 2024
1 parent 7e72226 commit 13ef433
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/timecorrelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,32 @@ function spectrum(omega_samplepoints,
H::AbstractOperator, J, op;
rho0=tensor(basisstate(H.basis_l, 1), dagger(basisstate(H.basis_r, 1))),
tol=1e-4,
rho_ss=steadystate.master(H, J; tol=tol, rho0=rho0)[end][end],
rates=nothing,
rho_ss=steadystate.master(H, J; rates=rates, tol=tol, rho0=rho0)[end][end],
kwargs...)
domega = minimum(diff(omega_samplepoints))
dt = 2*pi/abs(omega_samplepoints[end] - omega_samplepoints[1])
T = 2*pi/domega
tspan = [0.:dt:T;]
exp_values = correlation(tspan, rho_ss, H, J, dagger(op), op, kwargs...)
exp_values = correlation(tspan, rho_ss, H, J, dagger(op), op; rates=rates, kwargs...)
S = 2dt.*fftshift(real(fft(exp_values)))
return omega_samplepoints, S
end

function spectrum(H::AbstractOperator, J, op;
rho0=tensor(basisstate(H.basis_l, 1), dagger(basisstate(H.basis_r, 1))),
tol=1e-4,
rho_ss=steadystate.master(H, J; tol=tol)[end][end],
rates=nothing,
rho_ss=steadystate.master(H, J; rates=rates, tol=tol)[end][end],
kwargs...)
tspan, exp_values = correlation(rho_ss, H, J, dagger(op), op, tol=tol, kwargs...)
tspan, exp_values = correlation(rho_ss, H, J, dagger(op), op; rates=rates, tol=tol, kwargs...)
dtmin = minimum(diff(tspan))
T = tspan[end] - tspan[1]
tspan = Float64[0.:dtmin:T;]
n = length(tspan)
omega = mod(n, 2) == 0 ? [-n/2:n/2-1;] : [-(n-1)/2:(n-1)/2;]
omega .*= 2pi/T
return spectrum(omega, H, J, op; tol=tol, rho_ss=rho_ss, kwargs...)
return spectrum(omega, H, J, op; tol=tol, rates=rates, rho_ss=rho_ss, kwargs...)
end


Expand Down
16 changes: 14 additions & 2 deletions test/test_timecorrelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Test
using QuantumOptics
using LinearAlgebra

@testset "timecorrelations" begin
# @testset "timecorrelations" begin

ωc = 1.2
ωa = 0.9
Expand Down Expand Up @@ -72,4 +72,16 @@ omegaFFT, SFFT = timecorrelations.correlation2spectrum(tspan, exp_values)
tspan[5] = tspan[4]
@test_throws ArgumentError timecorrelations.correlation2spectrum(tspan, exp_values)

end # testset
# tests kwarg rates
J5 = [embed(basis, 1, sm), embed(basis, 1, sp), embed(basis, 2, destroy(fockbasis))]
rates5 = [γ, 0.5γ, κ]
exp_values5 = timecorrelations.correlation(tspan, ρ₀, H, J5, dagger(op), op; rates=rates5)
@test abs(exp_values[end] - exp_values5[end] ) < 1e-8

omega5, S5 = timecorrelations.spectrum(omega_sample, H, J5, op; rho_ss=ρ₀, rates=rates5)
@test abs(sum(S .- S5)) < 1e-8

omega5_2, S5_2 = timecorrelations.spectrum(H, J5, op; rates=rates5, tol=1e-3)
@test abs(sum(S2 .- S5_2)) < 1e-8

# end # testset

0 comments on commit 13ef433

Please sign in to comment.