Skip to content

Commit

Permalink
All integration tests running now
Browse files Browse the repository at this point in the history
  • Loading branch information
merkelm committed Feb 23, 2024
1 parent d78e8a6 commit d43505d
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 99 deletions.
13 changes: 7 additions & 6 deletions python/solid_dmft/dmft_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from solid_dmft.dmft_tools import manipulate_chemical_potential as manipulate_mu
from solid_dmft.dmft_tools import initial_self_energies as initial_sigma
from solid_dmft.dmft_tools import greens_functions_mixer as gf_mixer
from solid_dmft.io_tools.dict_to_h5 import prep_params_for_h5

def _extract_quantity_per_inequiv(param_name, n_inequiv_shells, general_params):
"""
Expand Down Expand Up @@ -370,7 +371,7 @@ def dmft_cycle(general_params, solver_params, advanced_params, dft_params,
map_imp_solver.append(isolver)
break
solver_type_per_imp = [solver_params[map_imp_solver[iineq]]['type'] for iineq in range(sum_k.n_inequiv_shells)]
mpi.report('DEBUG', solver_type_per_imp)
mpi.report(f'Solver type per impurity: {solver_type_per_imp}')

# Checks that enforce_off_diag true for ftps and hartree
if any(s in ['ftps', 'hartree'] and not e for s, e in zip(solver_type_per_imp, general_params['enforce_off_diag'])):
Expand Down Expand Up @@ -467,7 +468,7 @@ def dmft_cycle(general_params, solver_params, advanced_params, dft_params,
archive['DMFT_input']['rot_mat'] = sum_k.rot_mat
else:
previous_rot_mat = None
if deg_orbs_ftps is not None:
if 'solver_struct_ftps' in archive['DMFT_input']:
deg_orbs_ftps = archive['DMFT_input/solver_struct_ftps']

sum_k.block_structure = mpi.bcast(sum_k.block_structure)
Expand Down Expand Up @@ -507,10 +508,10 @@ def dmft_cycle(general_params, solver_params, advanced_params, dft_params,
# If new calculation, writes input parameters and sum_k <-> solver mapping to archive
if iteration_offset == 0:
if mpi.is_master_node():
# FIXME: writing to archive crashes because of parameters that are None
# archive['DMFT_input']['general_params'] = general_params
# archive['DMFT_input']['solver_params'] = solver_params
# archive['DMFT_input']['advanced_params'] = advanced_params
archive['DMFT_input']['general_params'] = prep_params_for_h5(general_params)
archive['DMFT_input']['solver_params'] = prep_params_for_h5(solver_params)
archive['DMFT_input']['dft_params'] = prep_params_for_h5(dft_params)
archive['DMFT_input']['advanced_params'] = prep_params_for_h5(advanced_params)

archive['DMFT_input']['block_structure'] = sum_k.block_structure
archive['DMFT_input']['deg_shells'] = sum_k.deg_shells
Expand Down
155 changes: 97 additions & 58 deletions python/solid_dmft/dmft_tools/solver.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions python/solid_dmft/io_tools/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ csc = false
dc = true
dc_dmft = "<none>"
dc_type = "<none>"
diag_delta = false
enforce_off_diag = true
eta = "<none>"
fixed_mu_value = "<none>"
Expand All @@ -28,8 +27,6 @@ J = "<no default>"
jobname = "dmft_dir"
load_sigma = false
load_sigma_iter = -1
loc_n_min = "<none>"
loc_n_max = "<none>"
magmom = "<none>"
magnetic = false
mu_gap_gb2_threshold = "<none>"
Expand Down Expand Up @@ -73,7 +70,9 @@ fit_min_w = "<none>"
imag_threshold = 1.0e-14
legendre_fit = false
length_cycle = "<no default>"
max_time = "<none>"
loc_n_min = "<none>"
loc_n_max = "<none>"
max_time = -1
measure_chi_insertions = 100
measure_chi = "<none>"
measure_density_matrix = false
Expand All @@ -92,7 +91,7 @@ random_seed = "<none>"
type = "ctint"
idx_impurities = "<none>"
length_cycle = "<no default>"
max_time = "<none>"
max_time = -1
measure_pert_order = false
move_double = true
n_cycles_tot = "<no default>"
Expand All @@ -105,7 +104,7 @@ idx_impurities = "<none>"
improved_estimator = false
legendre_fit = false
length_cycle = "<no default>"
max_time = "<none>"
max_time = -1
measure_G_iw = false
measure_G_l = false
measure_G_tau = true
Expand All @@ -129,6 +128,7 @@ type = "ftps"
idx_impurities = "<none>"
bath_fit = "<no default>"
calc_me = true
diag_delta = false
dmrg_maxm = 100
dmrg_maxmB = 100
dmrg_maxmI = 100
Expand Down
23 changes: 23 additions & 0 deletions python/solid_dmft/io_tools/dict_to_h5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from copy import deepcopy

def _iteratively_replace_none(to_write, replace_from, replace_with):
""" Limitation: can only replace None with a string, or a string with None. """
# First two checks needed because comparison to triqs many-body operator fails
if (isinstance(to_write, str) or to_write is None) and to_write == replace_from:
return replace_with

if isinstance(to_write, dict):
for key, value in to_write.items():
to_write[key] = _iteratively_replace_none(value, replace_from, replace_with)
elif isinstance(to_write, list):
for i, value in enumerate(to_write):
to_write[i] = _iteratively_replace_none(value, replace_from, replace_with)

return to_write

def prep_params_for_h5(dict_to_write):
return _iteratively_replace_none(deepcopy(dict_to_write), None, 'none')

# Not sure if the reverse route is actually needed
def prep_params_from_h5(dict_to_read):
return _iteratively_replace_none(deepcopy(dict_to_read), 'none', None)
28 changes: 0 additions & 28 deletions python/solid_dmft/io_tools/verify_input_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,4 @@ def verify_input_params(params: FullConfig) -> None:
def manual_changes_input_params(params: FullConfig) -> None:
""" Necessary workarounds for some of the parameters. """

for entry in params['solver']:
# Calculates the number of solver cycles per rank
# if entry['type'] in ('cthyb', 'ctint', 'ctseg'):
# entry['n_cycles'] = entry['n_cycles_tot'] // mpi.size
# del entry['n_cycles_tot']

# Some parameters have different names for ctseg
if entry['type'] == 'ctseg':
entry['measure_gt'] = entry['measure_G_tau']
del entry['measure_G_tau']

entry['measure_gw'] = entry['measure_G_iw']
del entry['measure_G_iw']

# Makes sure measure_gw is true if improved estimators are used
if entry['improved_estimator']:
entry['measure_gt'] = True
entry['measure_ft'] = True
else:
entry['measure_ft'] = False
del entry['improved_estimator']

entry['measure_gl'] = entry['measure_G_l']
del entry['measure_G_l']

entry['measure_hist'] = entry['measure_pert_order']
del entry['measure_pert_order']

return
1 change: 1 addition & 0 deletions test/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# all pytest unittests
set (all_pytests
test_afm_mapping
test_dict_to_h5
test_interaction_hamiltonian
test_manipulate_chemical_potential.py
test_observables.py
Expand Down
2 changes: 1 addition & 1 deletion test/python/svo_cthyb_basic_tf/dmft_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
seedname = "inp"
jobname = "out"
enforce_off_diag = false
block_threshold= 0.001
block_threshold = 0.001
mu_initial_guess = -0.027041

prec_mu = 0.001
Expand Down
13 changes: 13 additions & 0 deletions test/python/test_dict_to_h5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from solid_dmft.io_tools import dict_to_h5

def test_prep_params_for_h5():
inp = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}
expected = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}

assert dict_to_h5.prep_params_for_h5(inp) == expected

def test_prep_params_from_h5():
inp = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}
expected = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}

assert dict_to_h5.prep_params_from_h5(inp) == expected

0 comments on commit d43505d

Please sign in to comment.