Skip to content

Commit c417f12

Browse files
authored
Merge pull request #22 from numericalEFT/dev
Dev
2 parents 77270e9 + a5138f4 commit c417f12

File tree

9 files changed

+409
-173
lines changed

9 files changed

+409
-173
lines changed
File renamed without changes.

example/SYK.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ diff(a, b) = maximum(abs.(a - b)) # return the maximum deviation between a and b
2727

2828
conformal_tau(τ, β) = π^(1 / 4) / sqrt(2β) * 1 / sqrt(sin* τ / β))
2929

30-
function syk_sigma_dlr(d, G_x, J = 1.0)
30+
function syk_sigma_dlr(d, G_x, J = 1.0; sumrule = nothing, verbose = false)
3131

3232
tau_k = d.τ # DLR imaginary time nodes
3333
tau_k_rev = d.β .- tau_k # Reversed imaginary time nodes
3434

35-
G_x_rev = tau2tau(d, G_x, tau_k_rev) # G at beta - tau_k
35+
G_x_rev = tau2tau(d, G_x, tau_k_rev, sumrule = sumrule, verbose = verbose) # G at beta - tau_k
3636

3737
Sigma_x = J .^ 2 .* G_x .^ 2 .* G_x_rev # SYK self-energy in imaginary time
3838

@@ -50,15 +50,15 @@ function dyson(d, sigma_q, mu)
5050
end
5151
end
5252

53-
function solve_syk_with_fixpoint_iter(d, mu, tol = d.rtol * 10; mix = 0.1, maxiter = 5000, G_x = zeros(ComplexF64, length(d)), verbose = true)
53+
function solve_syk_with_fixpoint_iter(d, mu, tol = d.rtol * 10; mix = 0.1, maxiter = 5000, G_x = zeros(ComplexF64, length(d)), sumrule = nothing, verbose = true)
5454

5555
for iter in 1:maxiter
5656

57-
Sigma_x = syk_sigma_dlr(d, G_x)
57+
Sigma_x = syk_sigma_dlr(d, G_x, sumrule = sumrule, verbose = verbose)
5858

5959
G_q_new = dyson(d, tau2matfreq(d, Sigma_x), mu)
6060

61-
G_x_new = matfreq2tau(d, G_q_new)
61+
G_x_new = matfreq2tau(d, G_q_new, sumrule = sumrule, verbose = verbose)
6262

6363

6464
if verbose
@@ -94,21 +94,24 @@ printG(dsym_correct, G_x_correct)
9494

9595
printstyled("===== Test Symmetrized and Unsymmetrized DLR solver for SYK model =======\n", color = :yellow)
9696

97-
@printf("%30s%30s%30s%15s\n", "Euv", "symmetrized solver error", "unsymmetrized solver error", "good or bad")
97+
@printf("%30s%30s%30s%30s%20s\n", "Euv", "sym_solver", "unsym_solver", "unsym_solver+sum_rule", "good or bad")
9898
for Euv in LinRange(5.0, 10.0, 50)
9999

100100
rtol = 1e-10
101101
β = 10000.0
102102
# printstyled("===== Symmetrized DLR solver for SYK model =======\n", color = :yellow)
103103
mix = 0.01
104104
dsym = DLRGrid(Euv = Euv, β = β, isFermi = true, rtol = rtol, symmetry = :ph, rebuild = true, verbose = false) # Initialize DLR object
105-
@time G_x_ph = solve_syk_with_fixpoint_iter(dsym, 0.00, mix = mix, verbose = verbose)
106-
# printG(dsym, G_x_ph)
105+
G_x_ph = solve_syk_with_fixpoint_iter(dsym, 0.00, mix = mix, sumrule = nothing, verbose = verbose)
107106

108107
# printstyled("===== Unsymmetrized DLR solver for SYK model =======\n", color = :yellow)
109108
mix = 0.01
110109
dnone = DLRGrid(Euv = Euv, β = β, isFermi = true, rtol = rtol, symmetry = :none, rebuild = true, verbose = false) # Initialize DLR object
111-
@time G_x_none = solve_syk_with_fixpoint_iter(dnone, 0.00, mix = mix, verbose = verbose)
110+
G_x_none = solve_syk_with_fixpoint_iter(dnone, 0.00, mix = mix, sumrule = nothing, verbose = verbose)
111+
112+
# printstyled("===== Unsymmetrized DLR solver for SYK model =======\n", color = :yellow)
113+
mix = 0.01
114+
G_x_none_sumrule = solve_syk_with_fixpoint_iter(dnone, 0.00, mix = mix, sumrule = 1.0, verbose = verbose)
112115
# printG(dnone, G_x_none)
113116

114117
# printstyled("===== Unsymmetrized versus Symmetrized DLR solver =======\n", color = :yellow)
@@ -122,11 +125,13 @@ for Euv in LinRange(5.0, 10.0, 50)
122125

123126
G_x_interp_ph = tau2tau(dsym_correct, G_x_correct, dsym.τ)
124127
G_x_interp_none = tau2tau(dsym_correct, G_x_correct, dnone.τ)
128+
G_x_interp_none_sumrule = tau2tau(dsym_correct, G_x_correct, dnone.τ)
125129
d_ph = diff(G_x_interp_ph, G_x_ph)
126130
d_none = diff(G_x_interp_none, G_x_none)
127-
flag = (d_ph < 100rtol) && (d_none < 100rtol) ? "good" : "bad"
131+
d_none_sumrule = diff(G_x_interp_none_sumrule, G_x_none_sumrule)
132+
flag = (d_ph < 100rtol) && (d_none < 100rtol) && (d_none_sumrule < 100rtol) ? "good" : "bad"
128133

129-
@printf("%30.15f%30.15e%30.15e%20s\n", Euv, d_ph, d_none, flag)
134+
@printf("%30.15f%30.15e%30.15e%30.15e%20s\n", Euv, d_ph, d_none, d_none_sumrule, flag)
130135
# println("symmetric Euv = $Euv maximumal difference: ", diff(G_x_interp, G_x_ph))
131136
# println("non symmetric Euv = $Euv maximumal difference: ", diff(G_x_interp, G_x_none))
132137

example/demoMC.jl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Lehmann
2+
using DelimitedFiles
3+
using Printf
4+
using Gaston # for ploting
5+
6+
β = 10.0 # inverse temperature
7+
Euv = 4.0 # UV energy cutoff for the spectral density
8+
eps = 1.0e-8 # accuracy for DLR basis
9+
10+
# load Auxiliary field quantum Monte Carlo data for a fermionic Green's function from Yuanyao He
11+
data = DelimitedFiles.readdlm("QMC.txt")
12+
τ = data[:, 1] * β
13+
y = data[:, 2]
14+
err = data[:, 3]
15+
16+
# construct DLR basis
17+
dlr = DLRGrid(Euv, β, eps, true)
18+
19+
######################### G_dlr(τ) ################################
20+
printstyled("Fit without Sum Rule\n", color = :green)
21+
coeff = tau2dlr(dlr, y, τ; error = err)
22+
yp = dlr2tau(dlr, coeff, τ)
23+
# print comparsion for selected τ point
24+
printstyled("Compare G(τ) <--> G_dlr(τ)\n", color = :green)
25+
printstyled("G(0⁺)+G(β⁻)-1: ", y[1] + y[end] - 1, " vs ", yp[1] + yp[end] - 1, "\n", color = :red) #check sum rule
26+
printstyled("maximum dlr fitting error: ", maximum(abs.(y - yp)), "\n", color = :red)
27+
printstyled(" τi G(τ) G_dlr(τ) δG\n", color = :yellow)
28+
29+
printstyled("Fit with Sum Rule\n", color = :green)
30+
coeff_sumrule = tau2dlr(dlr, y, τ; error = err, sumrule = 1.0)
31+
yp = dlr2tau(dlr, coeff_sumrule, τ)
32+
# print comparsion for selected τ point
33+
printstyled("Compare G(τ) <--> G_dlr(τ)\n", color = :green)
34+
printstyled("G(0⁺)+G(β⁻)-1: ", y[1] + y[end] - 1, " vs ", yp[1] + yp[end] - 1, "\n", color = :red) #check sum rule
35+
printstyled("maximum dlr fitting error: ", maximum(abs.(y - yp)), "\n", color = :red)
36+
printstyled(" τi G(τ) G_dlr(τ) δG\n", color = :yellow)
37+
38+
for i in 1:25:length(y)
39+
@printf("%3i %10.8f %10.8f %10.8f\n", i, y[i], yp[i], abs(y[i] - yp[i]))
40+
end
41+
42+
######################### G_dlr(iωn) ################################
43+
n = collect(0:50)
44+
Gn = dlr2matfreq(dlr, coeff, n)
45+
46+
printstyled("Matsubara frequency G_dlr(ωn)\n", color = :green)
47+
printstyled(" n Re Im\n", color = :yellow)
48+
for i in 1:length(n)
49+
@printf("%3i %10.8f %10.8f\n", n[i], real(Gn[i]), -imag(Gn[i]))
50+
end
51+
52+
######################### Σ_dlr(iωn) ################################
53+
g0inv = @. -1im * (2 * n + 1) * π / β + 0.4
54+
Ginv = 1.0 ./ Gn
55+
Σ = g0inv - Ginv
56+
57+
printstyled("Matsubara frequency Σ_dlr(ωn)\n", color = :green)
58+
printstyled(" n Re Im\n", color = :yellow)
59+
for i in 1:length(n)
60+
@printf("%3i %10.8f %10.8f\n", n[i], real(Σ[i]), -imag(Σ[i]))
61+
end
62+
63+
# set(term = "qt")
64+
# p = plot(n, -imag.(Σ))
65+
# display(p)
66+
# readline()

example/demoSumRule.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Lehmann
2+
using Printf
3+
using Gaston
4+
β = 40.0
5+
rtol = 1e-8
6+
eta = 1e-2
7+
N = 128
8+
9+
dlr = DLRGrid= β, Euv = 1.0, isFermi = true, rtol = rtol, symmetry = :none)
10+
τgrid = collect(LinRange(0.0, β, N))
11+
println(τgrid)
12+
G = Sample.SemiCircle(dlr, , τgrid)
13+
G += rand(length(G)) / 2.0 * eta
14+
coeff = tau2dlr(dlr, G, τgrid)
15+
coeff_sumrule = tau2dlr(dlr, G, τgrid, sumrule = π / 2)
16+
println("sum rule: ", abs(sum(coeff) - π / 2), " versus ", abs(sum(coeff_sumrule) - π / 2))
17+
18+
19+
dlr10 = DLRGrid= β, Euv = 100.0, isFermi = true, rtol = rtol, symmetry = :none)
20+
21+
Gtrue = Sample.SemiCircle(dlr, , dlr10.τ)
22+
Gfit = real.(dlr2tau(dlr, coeff, dlr10.τ))
23+
Gfit_sumrule = real.(dlr2tau(dlr, coeff_sumrule, dlr10.τ))
24+
25+
@printf("%15s%30s%30s%30s\n", "tau", "true", "no sumrule", "with sumrule")
26+
for i in 1:dlr10.size
27+
@printf("%15.6f%30.15f%30.15e%30.15e\n", dlr10.τ[i], Gtrue[i], abs(Gfit[i] - Gtrue[i]), abs(Gfit_sumrule[i] - Gtrue[i]))
28+
end
29+
30+
set(term = "qt")
31+
# p = plot(dlr10.τ, Gtrue, label = "original", axis = "semilogy")
32+
xrange = (0.0, 40)
33+
p = plot(dlr10.τ, Gfit - Gtrue, plotstyle = :linespoints, leg = Symbol("DLR no sum rule"), Axes(xrange = xrange))
34+
plot!(dlr10.τ, Gfit_sumrule - Gtrue, plotstyle = :linespoints, leg = Symbol("DLR with sum rule"))
35+
display(p)
36+
readline()
Loading

experiment/fit_yuanyao.jl

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/dlr.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,38 @@ mutable struct DLRGrid
4646

4747
"""
4848
function DLRGrid(Euv, β, rtol, isFermi::Bool; symmetry::Symbol = :none, rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
49-
function DLRGrid(; Euv, β, isFermi::Bool, symmetry::Symbol = :none, rtol = 1e-8, rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
49+
function DLRGrid(; isFermi::Bool, β = -1.0, beta = -1.0, Euv = 1.0, symmetry::Symbol = :none, rtol = 1e-14, rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
5050
5151
Create DLR grids
5252
5353
#Arguments:
54-
- `Euv` : the UV energy scale of the spectral density
55-
- `β` : inverse temeprature
56-
- `isFermi` : bool is fermionic or bosonic
57-
- `symmetry` : particle-hole symmetric :ph, or particle-hole asymmetric :pha, or :none
58-
- `rtol` : tolerance absolute error
59-
- `rebuild` : set false to load DLR basis from the file, set true to recalculate the DLR basis on the fly
60-
- `folder` : if rebuild is true and folder is set, then dlrGrid will be rebuilt and saved to the specified folder
61-
if rebuild is false and folder is set, then dlrGrid will be loaded from the specified folder
62-
- `algorithm` : if rebuild = true, then set :functional to use the functional algorithm to generate the DLR basis, or set :discrete to use the matrix algorithm.
63-
- `verbose` : false not to print DLRGrid to terminal, or true to print
54+
- `Euv` : the UV energy scale of the spectral density
55+
- `β` or `beta` : inverse temeprature
56+
- `isFermi` : bool is fermionic or bosonic
57+
- `symmetry` : particle-hole symmetric :ph, or particle-hole asymmetric :pha, or :none
58+
- `rtol` : tolerance absolute error
59+
- `rebuild` : set false to load DLR basis from the file, set true to recalculate the DLR basis on the fly
60+
- `folder` : if rebuild is true and folder is set, then dlrGrid will be rebuilt and saved to the specified folder
61+
if rebuild is false and folder is set, then dlrGrid will be loaded from the specified folder
62+
- `algorithm` : if rebuild = true, then set :functional to use the functional algorithm to generate the DLR basis, or set :discrete to use the matrix algorithm.
63+
- `verbose` : false not to print DLRGrid to terminal, or true to print
6464
"""
6565
function DLRGrid(Euv, β, rtol, isFermi::Bool, symmetry::Symbol = :none; rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
6666
Λ = Euv * β # dlr only depends on this dimensionless scale
6767
# println("Get $Λ")
6868
@assert rtol > 0.0 "rtol=$rtol is not positive and nonzero!"
6969
@assert Λ > 0 "Energy scale must be positive!"
7070
@assert symmetry == :ph || symmetry == :pha || symmetry == :none "symmetry must be :ph, :pha or nothing"
71+
@assert algorithm == :functional || algorithm == :discrete "Algorithm is either :functional or :discrete"
72+
@assert β > 0.0 "Inverse temperature must be temperature."
73+
@assert Euv > 0.0 "Energy cutoff must be positive."
7174

7275
if Λ > 1e8 && symmetry == :none
7376
@warn("Current DLR without symmetry may cause ~ 3-4 digits loss for Λ ≥ 1e8!")
7477
end
7578

76-
if rtol >= 1e-6
77-
@warn("Current implementation may cause ~ 3-4 digits loss for rtol 1e-6!")
79+
if rtol > 1e-6
80+
@warn("Current implementation may cause ~ 3-4 digits loss for rtol > 1e-6!")
7881
end
7982

8083
rtolpower = Int(floor(log10(rtol))) # get the biggest n so that rtol>1e-n
@@ -144,7 +147,15 @@ mutable struct DLRGrid
144147
return dlr
145148
end
146149

147-
function DLRGrid(; Euv, β, isFermi::Bool, symmetry::Symbol = :none, rtol = 1e-14, rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
150+
function DLRGrid(; isFermi::Bool, β = -1.0, beta = -1.0, Euv = 1.0, symmetry::Symbol = :none, rtol = 1e-14, rebuild = false, folder = nothing, algorithm = :functional, verbose = false)
151+
if β <= 0.0 && beta > 0.0
152+
β = beta
153+
elseif β > 0.0 && beta <= 0.0
154+
beta = β
155+
elseif β < 0.0 && beta < 0.0
156+
error("Either β or beta needs to be initialized with a positive value!")
157+
end
158+
@assert β beta
148159
return DLRGrid(Euv, β, rtol, isFermi, symmetry; rebuild = rebuild, folder = folder, algorithm = algorithm, verbose = verbose)
149160
end
150161
end

0 commit comments

Comments
 (0)