Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rates spectrum #402

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was removing the @testset on purpose? That can mess up a bit how tests get reported in the log.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry. I forgot to uncomment. Thanks for pointing this out, I will fix it!

# @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
Loading