From 7d80921e502968fe090319e852bd22b9ff96b80d Mon Sep 17 00:00:00 2001 From: Zejian Li Date: Fri, 21 Jan 2022 16:02:03 +0100 Subject: [PATCH 1/5] Add function correlation_dynamic Add function for computing two-time correlations for time-dependent master equation. --- src/timecorrelations.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/timecorrelations.jl b/src/timecorrelations.jl index 80567240..2062d3e8 100644 --- a/src/timecorrelations.jl +++ b/src/timecorrelations.jl @@ -62,6 +62,39 @@ function correlation(rho0::Operator, H::AbstractOperator, J, end +""" + correlation_dynamic(tspan, rho0, f, op1, op2; ) + + +Calculate two time correlation values ``⟨A(t)B(0)⟩`` for time-dependent Liouvillian + +The calculation is done by multiplying the initial density operator +with ``B`` performing a time evolution according to a master equation +and then calculating the expectation value ``\\mathrm{Tr} \\{A ρ\\}`` + + +# Arguments +* `tspan`: Points of time at which the correlation should be calculated. +* `rho0`: Initial density operator. +* `f`: Function `f(t, rho) -> (H, J, Jdagger)` or `f(t, rho) -> (H, J, Jdagger, rates)` +* `op1`: Operator at time `t`. +* `op2`: Operator at time `t=0`. +* `rates=ones(N)`: Vector or matrix specifying the coefficients (decay rates) + for the jump operators. +* `kwargs...`: Further arguments are passed on to the ode solver. +""" +function correlation_dynamic(tspan, rho0::Operator, f, op1, op2; + rates=nothing, kwargs...) + + function fout(t, rho) + expect(op1, rho) + end + + t,u = timeevolution.master_dynamic(tspan, op2*rho0, f, rates=rates,fout=fout, kwargs...) + u +end + + """ timecorrelations.spectrum([omega_samplepoints,] H, J, op; ) From 05fd65fcef62074204db45fda553ecc06d85c570 Mon Sep 17 00:00:00 2001 From: Zejian Li Date: Wed, 26 Jan 2022 17:19:03 +0100 Subject: [PATCH 2/5] Add test for timecorrelations.correlation_dynamic Same test as for timecorrelations.correlation but in a rotating frame for the cavity mode, which does not affect the correlation for spin operators. --- test/test_timecorrelations.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test_timecorrelations.jl b/test/test_timecorrelations.jl index 0075d971..a421a911 100644 --- a/test/test_timecorrelations.jl +++ b/test/test_timecorrelations.jl @@ -30,6 +30,10 @@ Ja2 = embed(basis, 1, sqrt(0.5*γ)*sp) Jc = embed(basis, 2, sqrt(κ)*destroy(fockbasis)) J = [Ja, Ja2, Jc] +# time-dependent Hamiltonian in rotating frame of cavity mode, +# which should not change the time correlation for spin operators. +f_HJ(t,rho) = [ Ha + exp(im*ωc*t) * sm ⊗ create(fockbasis) + exp(-im*ωc*t) * sp ⊗ destroy(fockbasis), J, dagger.(J) ] + Ψ₀ = basisstate(spinbasis, 2) ⊗ fockstate(fockbasis, 5) ρ₀ = dm(Ψ₀) @@ -41,12 +45,16 @@ exp_values = timecorrelations.correlation(tspan, ρ₀, H, J, dagger(op), op) ρ₀ = dm(Ψ₀) tout, exp_values2 = timecorrelations.correlation(ρ₀, H, J, dagger(op), op; tol=1e-5) + +exp_values3 = timecorrelations.correlation_dynamic(tspan, ρ₀, f_HJ, dagger(op), op) @test length(exp_values) == length(tspan) @test length(exp_values2) == length(tout) +@test length(exp_values3) == length(tspan) @test norm(exp_values[1]-exp_values2[1]) < 1e-15 @test norm(exp_values[end]-exp_values2[end]) < 1e-4 - +@test all(norm.(exp_values .- exp_values3) .< 1e-4) + n = length(tspan) omega_sample = mod(n, 2) == 0 ? [-n/2:n/2-1;] : [-(n-1)/2:(n-1)/2;] omega_sample .*= 2pi/tspan[end] From 48d1ef583f2ea54f27cbc6b853ebfad43b1e560f Mon Sep 17 00:00:00 2001 From: Zejian Li Date: Wed, 26 Jan 2022 17:42:52 +0100 Subject: [PATCH 3/5] export correlation_dynamic in order for test_timecorrelations to call timecorrelations.correlation_dynamic --- src/timecorrelations.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/timecorrelations.jl b/src/timecorrelations.jl index 2062d3e8..a155eb22 100644 --- a/src/timecorrelations.jl +++ b/src/timecorrelations.jl @@ -1,6 +1,6 @@ module timecorrelations -export correlation, spectrum, correlation2spectrum +export correlation, spectrum, correlation2spectrum, correlation_dynamic using QuantumOpticsBase using ..timeevolution, ..steadystate @@ -63,7 +63,7 @@ end """ - correlation_dynamic(tspan, rho0, f, op1, op2; ) + timecorrelations.correlation_dynamic(tspan, rho0, f, op1, op2; ) Calculate two time correlation values ``⟨A(t)B(0)⟩`` for time-dependent Liouvillian From 045b759b8e21ffab849950cc2b6b11e24293978a Mon Sep 17 00:00:00 2001 From: Zejian Li Date: Wed, 26 Jan 2022 18:41:30 +0100 Subject: [PATCH 4/5] Update signature for timecorrelations.correlation_dynamic to match docstring Co-authored-by: Filippo Vicentini --- src/timecorrelations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timecorrelations.jl b/src/timecorrelations.jl index a155eb22..3dd8db8d 100644 --- a/src/timecorrelations.jl +++ b/src/timecorrelations.jl @@ -63,7 +63,7 @@ end """ - timecorrelations.correlation_dynamic(tspan, rho0, f, op1, op2; ) + timecorrelations.correlation_dynamic(tspan, rho0, f, A, B; ) Calculate two time correlation values ``⟨A(t)B(0)⟩`` for time-dependent Liouvillian From 0993ebbead623283ac66b70ac941f2c0697286d6 Mon Sep 17 00:00:00 2001 From: Christoph Hotter Date: Fri, 11 Feb 2022 09:51:25 +0100 Subject: [PATCH 5/5] op1 and op2 -> A and B (consistent with docstring) --- src/timecorrelations.jl | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/timecorrelations.jl b/src/timecorrelations.jl index 3dd8db8d..d156275d 100644 --- a/src/timecorrelations.jl +++ b/src/timecorrelations.jl @@ -9,7 +9,7 @@ using FFTW """ - timecorrelations.correlation([tspan, ]rho0, H, J, op1, op2; ) + timecorrelations.correlation([tspan, ]rho0, H, J, A, B; ) Calculate two time correlation values ``⟨A(t)B(0)⟩``. @@ -26,38 +26,38 @@ criterion specified in [`steadystate.master`](@ref). * `rho0`: Initial density operator. * `H`: Operator specifying the Hamiltonian. * `J`: Vector of jump operators. -* `op1`: Operator at time `t`. -* `op2`: Operator at time `t=0`. +* `A`: Operator at time `t`. +* `B`: Operator at time `t=0`. * `rates=ones(N)`: Vector or matrix specifying the coefficients (decay rates) for the jump operators. * `Jdagger=dagger.(J)`: Vector containing the hermitian conjugates of the jump * `kwargs...`: Further arguments are passed on to the ode solver. """ function correlation(tspan, rho0::Operator, H::AbstractOperator, J, - op1, op2; + A, B; rates=nothing, Jdagger=dagger.(J), kwargs...) function fout(t, rho) - expect(op1, rho) + expect(A, rho) end - t,u = timeevolution.master(tspan, op2*rho0, H, J; rates=rates, Jdagger=Jdagger, + t,u = timeevolution.master(tspan, B*rho0, H, J; rates=rates, Jdagger=Jdagger, fout=fout, kwargs...) u end function correlation(rho0::Operator, H::AbstractOperator, J, - op1, op2; + A, B; tol=1e-4, rates=nothing, Jdagger=dagger.(J), kwargs...) - op2rho0 = op2*rho0 - exp1 = expect(op1, op2rho0) + Brho0 = B*rho0 + exp1 = expect(A, Brho0) function fout(t, rho) - expect(op1, rho) + expect(A, rho) end - t,u = steadystate.master(H, J; rho0=op2rho0, tol=tol, fout=fout, + t,u = steadystate.master(H, J; rho0=Brho0, tol=tol, fout=fout, rates=rates, Jdagger=Jdagger, save_everystep=true,kwargs...) end @@ -77,20 +77,20 @@ and then calculating the expectation value ``\\mathrm{Tr} \\{A ρ\\}`` * `tspan`: Points of time at which the correlation should be calculated. * `rho0`: Initial density operator. * `f`: Function `f(t, rho) -> (H, J, Jdagger)` or `f(t, rho) -> (H, J, Jdagger, rates)` -* `op1`: Operator at time `t`. -* `op2`: Operator at time `t=0`. +* `A`: Operator at time `t`. +* `B`: Operator at time `t=0`. * `rates=ones(N)`: Vector or matrix specifying the coefficients (decay rates) for the jump operators. * `kwargs...`: Further arguments are passed on to the ode solver. """ -function correlation_dynamic(tspan, rho0::Operator, f, op1, op2; +function correlation_dynamic(tspan, rho0::Operator, f, A, B; rates=nothing, kwargs...) function fout(t, rho) - expect(op1, rho) + expect(A, rho) end - t,u = timeevolution.master_dynamic(tspan, op2*rho0, f, rates=rates,fout=fout, kwargs...) + t,u = timeevolution.master_dynamic(tspan, B*rho0, f, rates=rates,fout=fout, kwargs...) u end