From 3c9a8c41fc8882d393e475de980faf6cb4252c6c Mon Sep 17 00:00:00 2001 From: mmerkel Date: Fri, 23 Feb 2024 15:55:19 -0500 Subject: [PATCH] Deleted outdated scripts to port config and h5 --- python/solid_dmft/util/update_dmft_config.py | 149 ------------------- python/solid_dmft/util/update_results_h5.py | 92 ------------ test/python/CMakeLists.txt | 2 - test/python/test_update_dmft_config.py | 74 --------- test/python/test_update_results_h5.py | 43 ------ 5 files changed, 360 deletions(-) delete mode 100644 python/solid_dmft/util/update_dmft_config.py delete mode 100644 python/solid_dmft/util/update_results_h5.py delete mode 100755 test/python/test_update_dmft_config.py delete mode 100644 test/python/test_update_results_h5.py diff --git a/python/solid_dmft/util/update_dmft_config.py b/python/solid_dmft/util/update_dmft_config.py deleted file mode 100644 index e661628b..00000000 --- a/python/solid_dmft/util/update_dmft_config.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2016-2018, N. Wentzell -# Copyright (C) 2018-2019, Simons Foundation -# author: N. Wentzell -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ -""" -Updates the config file (usually dmft_config.ini) for continuing old calculations. -""" - -import os.path -import shutil -import sys -from configparser import ConfigParser - -def _backup_old_file(path): - """ Copies file to same folder with the prefix "backup_". """ - directory, filename = os.path.split(path) - shutil.copy2(path, os.path.join(directory, 'backup_'+filename)) - -def _load_config_file(path): - """ Loads file with the configparser module. Returns ConfigParser object. """ - config = ConfigParser() - config.read(path) - return config - -def _update_section_names(config): - """ - Applies the mapping between legacy names of sections and new names. The - mapping is saved in LEGACY_SECTION_NAME_MAPPING. - - Parameters - ---------- - config : ConfigParser - A configparser instance that has read the config file already. - - Returns - ------- - config : ConfigParser - The configparser with correct section names. - """ - - LEGACY_SECTION_NAME_MAPPING = {'solver': 'solver_parameters', 'advanced': 'advanced_parameters'} - - for new_name, legacy_name in LEGACY_SECTION_NAME_MAPPING.items(): - # Only new name in there, everything is okay - if legacy_name not in config.keys(): - continue - - # Only legacy name exists, creates updated section - if new_name not in config.keys(): - config.add_section(new_name) - - # Transfers parameters in legacy section to updated section - for param_name, param_value in config[legacy_name].items(): - config.set(new_name, param_name, param_value) - config.remove_section(legacy_name) - - return config - -def _update_params(config): - """ - Updates parameter names/values and adds new required parameters. - - Parameters - ---------- - config : ConfigParser - The config parser with correct section names. - - Returns - ------- - config : ConfigParser - The completely updated config parser. - """ - - # Updates h_int_type - if config['general']['h_int_type'] in ('1', '2', '3'): - config['general']['h_int_type'] = {'1': 'density_density', - '2': 'kanamori', - '3': 'full_slater' - }[config['general']['h_int_type']] - - # ---new params - # Updates solver_type - if not existent, uses previous default cthyb - if 'solver_type' not in config['general']: - config['general']['solver_type'] = 'cthyb' - - if 'dft_code' not in config['dft']: - config['dft']['dft_code'] = 'vasp' - - # ---updated params - # Updates legendre coefficients - if 'n_LegCoeff' in config['solver']: - config['general']['n_l'] = config['solver']['n_LegCoeff'] - del config['solver']['n_LegCoeff'] - - # Updates dft_executable - if 'executable' in config['dft']: - config['dft']['dft_exec'] = config['dft']['executable'] - del config['dft']['executable'] - - # Updates dft_executable - if 'wannier90_exec' in config['dft']: - config['dft']['w90_exec'] = config['dft']['wannier90_exec'] - del config['dft']['wannier90_exec'] - - return config - -def _write_config_file(config, path): - """ Writes config parser content to a file. """ - with open(path, 'w') as file: - config.write(file) - -def main(path='dmft_config.ini'): - """ Combines methods in the full work flow for updating the config file. """ - if not os.path.isfile(path): - raise ValueError('File {} does not exist.'.format(path)) - - _backup_old_file(path) - - config = _load_config_file(path) - config = _update_section_names(config) - config = _update_params(config) - _write_config_file(config, path) - -if __name__ == '__main__': - if len(sys.argv) == 1: - main() - elif len(sys.argv) == 2: - main(sys.argv[1]) - else: - raise TypeError('Maximally one argument supported: the config file name') diff --git a/python/solid_dmft/util/update_results_h5.py b/python/solid_dmft/util/update_results_h5.py deleted file mode 100644 index 4d80138a..00000000 --- a/python/solid_dmft/util/update_results_h5.py +++ /dev/null @@ -1,92 +0,0 @@ -# -*- coding: utf-8 -*- -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2016-2018, N. Wentzell -# Copyright (C) 2018-2019, Simons Foundation -# author: N. Wentzell -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ -""" -Updates the h5 archives with soliDMFT results for continuing old calculations. -""" -import os.path -import shutil -import sys -import numpy as np -from h5 import HDFArchive -# Import needed for transfering Green's functions in _update_results_per_iteration -from triqs.gf import BlockGf - -def _backup_old_file(path): - """ Copies file to same folder with the prefix "backup_". """ - directory, filename = os.path.split(path) - shutil.copy2(path, os.path.join(directory, 'backup_'+filename)) - -def _update_results_per_iteration(archive): - iterations = [key for key in archive['DMFT_results'] if key.startswith('it_')] - iterations.append('last_iter') - - for it in iterations: - keys = list(archive['DMFT_results'][it].keys()) - for key in keys: - if '_iw' in key: - new_key = key.replace('_iw_', '_freq_').replace('_iw', '_freq_') - archive['DMFT_results'][it][new_key] = archive['DMFT_results'][it][key] - del archive['DMFT_results'][it][key] - elif '_tau' in key: - new_key = key.replace('_tau_', '_time_').replace('_tau', '_time_') - archive['DMFT_results'][it][new_key] = archive['DMFT_results'][it][key] - del archive['DMFT_results'][it][key] - # Updates chemical potential to _post - elif key == 'chemical_potential': - it_number = int(it[3:]) if it.startswith('it_') else -1 - archive['DMFT_results'][it]['chemical_potential_post'] = archive['DMFT_results'][it]['chemical_potential'] - archive['DMFT_results'][it]['chemical_potential_pre'] = archive['DMFT_results']['observables']['mu'][it_number] - del archive['DMFT_results'][it]['chemical_potential'] - -def _update_observables(archive): - if 'orb_Z' not in archive['DMFT_results']['observables']: - orb_gb2 = archive['DMFT_results']['observables']['orb_gb2'] - orb_Z = [] - - for i in range(len(orb_gb2)): - orb_Z.append({}) - for spin in orb_gb2[i]: - orb_Z[i][spin] = [np.full(np.shape(z_per_it), 'none') - for z_per_it in orb_gb2[i][spin]] - - archive['DMFT_results']['observables']['orb_Z'] = orb_Z - -def main(path='dmft_config.ini'): - """ Combines methods in the full work flow for updating the h5 archive. """ - if not os.path.isfile(path): - raise ValueError('File {} does not exist.'.format(path)) - - _backup_old_file(path) - - with HDFArchive(path, 'a') as archive: - _update_results_per_iteration(archive) - _update_observables(archive) - -if __name__ == '__main__': - if len(sys.argv) == 1: - main() - elif len(sys.argv) == 2: - main(sys.argv[1]) - else: - raise TypeError('Maximally one argument supported: the archive file name') diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 4ef1020f..e2fff573 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -8,8 +8,6 @@ set (all_pytests test_postproc_toml_dict.py test_postproc_toml_dict_integration.py test_read_config.py - test_update_dmft_config.py - test_update_results_h5.py ) foreach(test ${all_pytests}) diff --git a/test/python/test_update_dmft_config.py b/test/python/test_update_dmft_config.py deleted file mode 100755 index 479fd45b..00000000 --- a/test/python/test_update_dmft_config.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Contains unit tests for update_dmft_config.py. -""" - -from configparser import ConfigParser - -from solid_dmft.util.update_dmft_config import _update_section_names, _update_params - -CONFIG_FILE_1 = u''' -[general] -seedname = fancy_system -jobname = out_DMFT_fancy -enforce_off_diag = True -block_threshold= 0.001 -set_rot = none -solver_type = cthyb - -prec_mu = -0.001 - -h_int_type = density_density -U = 2.0 -J = 2.0 - -n_iter_dmft = 4 - -dc_type = 0 -dc = True -dc_dmft = False - -calc_energies = True -sigma_mix = 0.7 - -h5_save_freq = 5 - -n_iter_dmft_per = 5 - -[solver] -imag_threshold = 1e-5 -measure_G_l = True -n_LegCoeff = 40 - -[advanced_parameters] -dc_factor = 0.6 - -[dft] -''' - -def _print_config(config): - print('Section headers:', config.sections()) - for section in config: - print('-'*10, section) - print([(k, v) for k,v in config[section].items()]) - -def test_update_legacy_section_headers(): - config = ConfigParser() - config.read_string(CONFIG_FILE_1) - - config = _update_section_names(config) - assert all([s in ('general', 'solver', 'advanced', 'dft') for s in config.sections()]) - assert [(k, v) for k, v in config['advanced'].items()] == [('dc_factor', '0.6')] - -def test_update_params(): - config = ConfigParser() - config.read_string(CONFIG_FILE_1) - - config = _update_section_names(config) - config = _update_params(config) - - assert config['general']['h_int_type'] == 'density_density' - assert config['general']['solver_type'] == 'cthyb' - assert config['general']['n_l'] == '40' - assert 'n_LegCoeff' not in config['solver'] diff --git a/test/python/test_update_results_h5.py b/test/python/test_update_results_h5.py deleted file mode 100644 index eb8c415a..00000000 --- a/test/python/test_update_results_h5.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Contains unit tests for update_results_h5.py. -""" - -import numpy as np -from solid_dmft.util.update_results_h5 import _update_results_per_iteration, _update_observables - -def _generate_archive(): - dmft_results = {'it_2': {'DC_energ': 'test1', - 'G0_iw0': 'test2', - 'Gimp_iw_0': 'test3', - 'chemical_potential': 12.5}, - 'it_5': {'chemical_potential': 12.9}, - 'last_iter': {}, - 'observables': {'mu': [11.9, 12.0, 12.8, 12.5, 12.1, 12.3, 12.9], - 'orb_gb2': [{s: [[-.05*i, -0.02/(i+1), -.1] for i in range(7)] for s in ('up', 'down')}]}, - 'iteration_count': 6, - } - - return {'DMFT_results': dmft_results} - -def test_update_results_per_iteration(): - archive = _generate_archive() - - _update_results_per_iteration(archive) - assert 'G0_iw0' not in archive['DMFT_results']['it_2'] - assert 'Gimp_iw_0' not in archive['DMFT_results']['it_2'] - assert archive['DMFT_results']['it_2']['G0_freq_0'] == 'test2' - assert archive['DMFT_results']['it_2']['Gimp_freq_0'] == 'test3' - assert np.isclose(archive['DMFT_results']['it_2']['chemical_potential_pre'], 12.8) - assert np.isclose(archive['DMFT_results']['it_2']['chemical_potential_post'], 12.5) - assert np.isclose(archive['DMFT_results']['it_5']['chemical_potential_pre'], 12.3) - assert np.isclose(archive['DMFT_results']['it_5']['chemical_potential_post'], 12.9) - -def test_update_observables(): - archive = _generate_archive() - _update_observables(archive) - assert len(archive['DMFT_results']['observables']['orb_Z']) == 1 - assert len(archive['DMFT_results']['observables']['orb_Z'][0]) == 2 - assert len(archive['DMFT_results']['observables']['orb_Z'][0]['down']) == 7 - assert len(archive['DMFT_results']['observables']['orb_Z'][0]['down'][1]) == 3