Skip to content

Commit fd4f5c4

Browse files
committed
adaptive kink rho propagation
1 parent 06cc364 commit fd4f5c4

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumDynamics"
22
uuid = "5a40c529-53c2-4483-a223-e00c1cee8134"
33
authors = ["Amartya Bose <[email protected]> and contributors"]
4-
version = "0.2.22"
4+
version = "0.2.23"
55

66
[deps]
77
AtomsIO = "1692102d-eeb4-4df9-807b-c9517f998d44"

src/DynamicMap_MasterEquation/TTM.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function get_propagators(; fbU::Array{<:Complex,3}, Jw::Vector{T}, β, dt, ntime
172172
end
173173
T0e = get_Ts(U0e_within_r)
174174
if !isnothing(output)
175-
Utilities.check_or_insert_value(output, "Tmat", T0e)
175+
Utilities.check_or_insert_value(output, "T0e", T0e)
176176
flush(output)
177177
end
178178

src/PathIntegral/QuAPI.jl

+73
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,77 @@ function build_augmented_propagator_kink(; fbU::AbstractArray{ComplexF64,3}, Jw:
570570
end
571571
U0e
572572
end
573+
574+
function propagate_kink(; fbU::AbstractArray{ComplexF64,3}, Jw::Vector{T}, ρ0::AbstractMatrix{ComplexF64}, β::Real, dt::Real, ntimes::Int, extraargs::QuAPIArgs=QuAPIArgs(), svec=[1.0 -1.0], reference_prop=false, verbose::Bool=false, output::Union{Nothing,HDF5.Group}=nothing, from_TTM::Bool=false, exec=ThreadedEx()) where {T<:SpectralDensities.SpectralDensity}
575+
@assert length(Jw) == size(svec, 1)
576+
η = [EtaCoefficients.calculate_η(jw; β, dt, kmax=ntimes, imaginary_only=reference_prop) for jw in Jw]
577+
sdim = size(fbU, 2)
578+
sdim2 = sdim^2
579+
state_values, _ = setup_simulation(ones(sdim, sdim), η, svec, extraargs)
580+
581+
if verbose
582+
@info "Starting propagation within memory"
583+
end
584+
ρs = Array{ComplexF64}(undef, ntimes+1, sdim, sdim)
585+
ρs[1, :, :] = ρ0
586+
if !isnothing(output)
587+
Utilities.check_or_insert_value(output, "rho", ρs)
588+
Utilities.check_or_insert_value(output, "time_taken", zeros(Float64, ntimes))
589+
Utilities.check_or_insert_value(output, "num_paths", zeros(Int64, ntimes))
590+
end
591+
nkinks = extraargs.num_kinks==-1 ? ntimes : extraargs.num_kinks
592+
nblips = extraargs.num_blips==-1 ? ntimes+1 : extraargs.num_blips
593+
numpaths = zeros(Int64, ntimes)
594+
timetaken = zeros(Float64, ntimes)
595+
for ind in findall(!iszero, ρ0)
596+
forward_paths = [[UInt8(ind[1])]]
597+
forward_amplitudes = [1.0+0.0im]
598+
backward_paths = [[UInt8(ind[2])]]
599+
backward_amplitudes = [1.0+0.0im]
600+
for i = 1:ntimes
601+
if verbose
602+
@info "Starting time step $(i)"
603+
end
604+
_, time_taken, memory_allocated, gc_time, _ = @timed begin
605+
forward_paths, forward_amplitudes = Utilities.generate_paths_kink_limit(forward_paths, forward_amplitudes, nkinks, sdim, fbU, extraargs.prop_cutoff, sqrt(extraargs.cutoff))
606+
backward_paths, backward_amplitudes = Utilities.generate_paths_kink_limit(backward_paths, backward_amplitudes, nkinks, sdim, fbU, extraargs.prop_cutoff, sqrt(extraargs.cutoff))
607+
if verbose
608+
@info "Path generation done. $(length(forward_paths)) forward paths generated. Expect up to $(length(forward_paths)^2) forward-backward paths based on filtration."
609+
end
610+
@floop exec for ((fp, fa), (bp, ba)) in Iterators.product(zip(forward_paths, forward_amplitudes), zip(backward_paths, backward_amplitudes))
611+
num_blips = count(fp .!= bp)
612+
if num_blips > nblips
613+
continue
614+
end
615+
bare_amplitude = fa * conj(ba)
616+
if abs(bare_amplitude) < extraargs.cutoff
617+
continue
618+
end
619+
@init states = zeros(UInt16, i+1)
620+
states .= (fp.-1) .* sdim .+ bp
621+
@reduce num_paths = 0 + 1
622+
for (bn, bη) in enumerate(η)
623+
@inbounds bare_amplitude *= get_path_influence(bη, bn, state_values, states, false)
624+
end
625+
@init tmprho = zeros(ComplexF64, sdim2)
626+
tmprho .= 0.0
627+
@inbounds tmprho[states[end]] = bare_amplitude * ρ0[ind]
628+
@reduce tmprhot = zeros(ComplexF64, sdim2) .+ tmprho
629+
end
630+
numpaths[i] += num_paths
631+
@inbounds ρs[i+1, :, :] .+= Utilities.density_matrix_vector_to_matrix(tmprhot)
632+
end
633+
timetaken[i] += time_taken
634+
if verbose
635+
@info "Done time step $(i); # paths = $(sum(num_paths)); time = $(round(time_taken; digits=3)) sec; memory allocated = $(round(memory_allocated / 1e6; digits=3)) GB; gc time = $(round(gc_time; digits=3)) sec"
636+
end
637+
if !isnothing(output)
638+
output["rho"][i+1, :, :] = ρs
639+
output["time_taken"][i] = timetaken[i]
640+
output["num_paths"] = numpaths
641+
end
642+
end
643+
end
644+
0:dt:ntimes*dt, ρs
645+
end
573646
end

test/runtests.jl

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ end
7272
@test all(norm.(ρs[:, 1, 2] .- complex_dat[1:ntimes+1, 2, 1]) .< 1e-2)
7373
end
7474

75+
@testset "adaptive-kink-QuAPI" begin
76+
fU = Propagators.calculate_bare_propagators(; Hamiltonian, dt, ntimes, forward_backward=false)
77+
t, ρs = QuAPI.propagate_kink(; fbU=fU, Jw=[Jw], β, ρ0, dt, ntimes, svec)
78+
79+
@test all(ρs[:, 1, 2] .≈ conj(ρs[:, 2, 1]))
80+
@test all(ρs[:, 1, 1] .+ ρs[:, 2, 2] .≈ 1.0 + 0.0im)
81+
@test all(norm.(ρs[:, 1, 1] .- complex_dat[1:ntimes+1, 1, 1]) .< 1e-2)
82+
@test all(norm.(ρs[:, 1, 2] .- complex_dat[1:ntimes+1, 2, 1]) .< 1e-2)
83+
end
84+
7585
@testset "TEMPO" begin
7686
t, ρs = TEMPO.propagate(; fbU, Jw=[Jw], β, ρ0, dt, ntimes, kmax, svec, extraargs=TEMPO.TEMPOArgs(; cutoff=1e-15, maxdim=1000))
7787

0 commit comments

Comments
 (0)