Skip to content

Commit

Permalink
[feat] add std tail fitting in ctseg
Browse files Browse the repository at this point in the history
  • Loading branch information
the-hampel committed Jun 12, 2024
1 parent d488ebe commit 35c22cc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
23 changes: 19 additions & 4 deletions python/solid_dmft/dmft_tools/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _fit_tail_window(
tail_barr : dict of arr
fitted tail of Sigma_iw
"""
from triqs.gf import fit_hermitian_tail_on_window
from triqs.gf.gf_fnt import fit_hermitian_tail_on_window, replace_by_tail

# Define default tail quantities
if fit_min_w is not None:
Expand All @@ -162,7 +162,8 @@ def _fit_tail_window(

# Now fit the tails of Sigma_iw and replace the high frequency part with the tail expansion
tail_barr = {}
for name, sig in Sigma_iw:
Sigma_fit = Sigma_iw.copy()
for name, sig in Sigma_fit:

tail, err = fit_hermitian_tail_on_window(
sig,
Expand All @@ -174,8 +175,9 @@ def _fit_tail_window(
expansion_order = fit_max_moment
)
tail_barr[name] = tail
replace_by_tail(sig, tail, n_min=fit_min_n)

return tail_barr
return Sigma_fit, tail_barr

class SolverStructure:

Expand Down Expand Up @@ -1427,6 +1429,19 @@ def set_Gs_from_G_l():
self.G_l << legendre_filter.apply(self.G_time, self.solver_params['n_l'])
# get G_time, G_freq, Sigma_freq from G_l
set_Gs_from_G_l()
elif self.solver_params['perform_tail_fit']:
self.Sigma_freq = inverse(self.G0_freq) - inverse(self.G_freq)
# without any degenerate shells we run the minimization for all blocks
self.Sigma_freq, tail = _fit_tail_window(self.Sigma_freq,
fit_min_n=self.solver_params['fit_min_n'],
fit_max_n=self.solver_params['fit_max_n'],
fit_min_w=self.solver_params['fit_min_w'],
fit_max_w=self.solver_params['fit_max_w'],
fit_max_moment=self.solver_params['fit_max_moment'],)
self.Sigma_Hartree = {}
for block in tail.keys():
self.Sigma_Hartree[block] = tail[block][0]

# if improved estimators are turned on calc Sigma from F_tau, otherwise:
elif self.solver_params['improved_estimator']:
self.F_freq = self.G_freq.copy()
Expand Down Expand Up @@ -1484,7 +1499,7 @@ def set_Gs_from_G_l():
# minimize dyson for the first entry of each deg shell
self.Sigma_dlr = self.sum_k.block_structure.create_gf(ish=self.icrsh, gf_function=Gf, mesh=mesh_dlr_iw, space='solver')
# without any degenerate shells we run the minimization for all blocks
tail = _fit_tail_window(Sigma_iw,
_, tail = _fit_tail_window(Sigma_iw,
fit_min_n=self.solver_params['fit_min_n'],
fit_max_n=self.solver_params['fit_max_n'],
fit_min_w=self.solver_params['fit_min_w'],
Expand Down
2 changes: 1 addition & 1 deletion python/solid_dmft/gw_embedding/gw_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

from h5 import HDFArchive
from triqs.utility import mpi
from triqs.gf.tools import inverse
from triqs.gf import (
iOmega_n,
inverse,
fit_hermitian_tail,
Gf,
BlockGf,
Expand Down
1 change: 1 addition & 0 deletions python/solid_dmft/io_tools/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ n_l = "<none>"
n_tau_k = 10001
n_warmup_cycles = "<no default>"
off_diag_threshold = 0.0
perform_tail_fit = true
random_seed = "<none>"

[[solver]]
Expand Down
2 changes: 2 additions & 0 deletions python/solid_dmft/io_tools/documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ n_warmup_cycles : int, mandatory
number of warmup cycles before real measurement sets in
off_diag_threshold : float, default = 0.0
threshold for off-diag elements in Hloc0
perform_tail_fit : bool, default = False
tail fitting if legendre is off?
random_seed : str, default = None
if None, uses default seed by triqs.
If specified the int will be used for random seeds. Careful, this will give the same random
Expand Down
18 changes: 7 additions & 11 deletions test/python/svo_gw_emb_stat/dmft_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ enforce_off_diag = false

n_iw = 20000
n_tau = 200001
dlr_wmax = 0.5
dlr_eps = 1e-8
dlr_wmax = 20
dlr_eps = 1e-10

gw_embedding = true
h_int_type = "crpa_density_density"
Expand All @@ -20,17 +20,13 @@ it_1e = 1
it_2e = 1

[solver]
type = "cthyb"
type = "ctseg"
length_cycle = 120
n_warmup_cycles = 1e+3
n_cycles_tot = 5e+5
off_diag_threshold = 1e-5
imag_threshold = 1e-4
delta_interface = false
diag_delta = false
measure_density_matrix = true
crm_dyson_solver = true
# perform_tail_fit = true
# fit_max_moment = 4
# fit_min_w = 0.2
# fit_max_w = 0.8
perform_tail_fit = true
fit_max_moment = 4
fit_min_w = 0.2
fit_max_w = 0.8
12 changes: 5 additions & 7 deletions test/python/svo_gw_emb_stat/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import sys
import shutil
import importlib.util

from triqs.gf import *
from triqs.utility.comparison_tests import assert_block_gfs_are_close, assert_arrays_are_close
from h5 import HDFArchive
import triqs.utility.mpi as mpi

import solid_dmft.main as solid

try:
from triqs_cthyb import Solver
except ImportError:
print('ctseg solver not installed skipping')
# try triqs_ctseg import
ctseg = importlib.util.find_spec("triqs_ctseg") is not None
if not ctseg:
mpi.report('ImportWarning: ctseg needs to be installed to run this test')
sys.exit()

if mpi.is_master_node():
Expand Down

0 comments on commit 35c22cc

Please sign in to comment.