Skip to content

Commit

Permalink
add MatsubraGF
Browse files Browse the repository at this point in the history
  • Loading branch information
ZongYongyue committed Nov 29, 2024
1 parent 71e7e8f commit d3bc93f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
8 changes: 5 additions & 3 deletions src/DynamicalCorrelators.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module DynamicalCorrelators

using LinearAlgebra: norm
using QuantumLattices: Hilbert, Term, Lattice, Neighbors, bonds, OperatorGenerator, Operator, CompositeIndex #CoordinatedIndex, FockIndex, Index, OperatorSet
using TensorKit: FermionParity, U1Irrep, SU2Irrep, Vect, Sector, ProductSector, AbstractTensorMap, TensorMap
using TensorKit: truncdim, truncerr, truncspace, truncbelow, , space, numout, numin, dual, fuse
Expand All @@ -16,21 +17,22 @@ import MPSKit: propagator, dot

export hubbard

export fZ, e_plus, e_min, number, onsiteCoulomb, S_plus, S_min, S_z, S_square, b_plus, b_min
export fZ, e_plus, e_min, number, onsiteCoulomb, S_plus, S_min, S_z, S_square, b_plus, b_min, j_l
export chargedMPO, hamiltonian

export add_single_util_leg, setprocs
export add_single_util_leg

export chargedMPS, randFiniteMPS

export propagator, dcorrelator
export RetardedGF, GreaterLessGF
export RetardedGF, GreaterLessGF, MatsubaraGF

include("models/hamiltonians.jl")
include("models/lattices.jl")
include("operators/fermions.jl")
include("operators/chargedmpo.jl")
include("operators/operator2mpo.jl")
include("operators/currentoperator.jl")
include("tools.jl")
include("states/chargedmps.jl")
include("states/randmps.jl")
Expand Down
57 changes: 44 additions & 13 deletions src/observables/correlator.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
"""
propagator(H::MPOHamiltonian, bra::FiniteMPS, ket::FiniteMPS; rev::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
propagator(H::MPOHamiltonian, bra::FiniteMPS, ket::FiniteMPS; rev::Bool=false, imag::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
propagator(H::MPOHamiltonian, bras::Vector{<:FiniteMPS}, ket::FiniteMPS; rev::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
"""
function propagator(H::MPOHamiltonian, bra::FiniteMPS, ket::FiniteMPS; rev::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
function propagator(H::MPOHamiltonian, bra::FiniteMPS, ket::FiniteMPS; rev::Bool=false, imag::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
times = collect(0:dt:ft)
propagators = zeros(ComplexF64, length(times))
propagators[1] = dot(bra, ket)
envs = environments(ket, H)
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, dt, alg, envs)
propagators[i+1] = dot(bra, ket)
if imag
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, -1im*dt, alg, envs)
propagators[i+1] = dot(bra, ket)
end
else
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, dt, alg, envs)
propagators[i+1] = dot(bra, ket)
end
end
rev ? propagators = conj.(propagators) : propagators = propagators
return propagators
end

function propagator(H::MPOHamiltonian, bras::Vector{<:FiniteMPS}, ket::FiniteMPS; rev::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
function propagator(H::MPOHamiltonian, bras::Vector{<:FiniteMPS}, ket::FiniteMPS; rev::Bool=false, imag::Bool=false, dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
times = collect(0:dt:ft)
propagators = zeros(ComplexF64, length(bras), length(times))
propagators[:,1] = [dot(bras[i], ket) for i in 1:length(bras)]
envs = environments(ket, H)
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, dt, alg, envs)
for j in eachindex(bras)
propagators[j,i+1] = dot(bras[j], ket)
if imag
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, -1im*dt, alg, envs)
for j in eachindex(bras)
propagators[j,i+1] = dot(bras[j], ket)
end
end
else
for (i, t) in enumerate(times[2:end])
alg = t > n * dt ? TDVP() : TDVP2(; trscheme=trscheme)
ket, envs = timestep(ket, H, 0, dt, alg, envs)
for j in eachindex(bras)
propagators[j,i+1] = dot(bras[j], ket)
end
end
end
rev ? propagators = conj.(propagators) : propagators = propagators
Expand Down Expand Up @@ -98,4 +116,17 @@ end


struct GorkovGF end
struct MatsubaraGF end

struct MatsubaraGF end

function dcorrelator(::Type{MatsubaraGF}, H::MPOHamiltonian, gsenergy::Number, mps::Vector{<:FiniteMPS}; dt::Number=0.05, ft::Number=5.0, n::Integer=3, trscheme=truncerr(1e-3))
t = collect(0:dt:ft)
gf = SharedArray{ComplexF64, 3}(length(mps), length(mps), length(0:dt:ft))
@sync @distributed for i in 1:length(mps)
gf[i,:,:] = propagator(H, mps[1:end], mps[i]; rev=false, imag=true, dt=dt, ft=ft, n=n, trscheme=trscheme)
end
for i in eachindex(t)
gf[:,:,i] = exp(gsenergy*t[i])*gf[:,:,i]
end
return gf
end
6 changes: 0 additions & 6 deletions src/tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,4 @@ function add_single_util_leg(tensor::AbstractTensorMap{S,N1,N2}) where {S,N1,N2}
throw(ArgumentError("invalid operator, expected 3-leg tensor"))
end
return fourlegtensor
end

function setprocs(numworkers::Int)
np = length(workers())
np < numworkers ? addworkers=(numworkers - np) : addworkers = 0
addprocs(addworkers)
end

0 comments on commit d3bc93f

Please sign in to comment.