Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip parameters in dcore_pre #141

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions src/dcore/dcore_bse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from dcore._dispatcher import HDFArchive, dyson
from dcore.dmft_core import DMFTCoreSolver
from dcore.program_options import create_parser, parse_parameters, delete_parameters, print_parameters
from dcore.program_options import create_parser, parse_parameters, print_parameters, delete_parameters
from dcore.tools import *
from dcore import impurity_solvers
from .sumkdft_workers.launcher import run_sumkdft
Expand All @@ -42,13 +42,10 @@ def to_str(x):
return x


def compare_str_list(list1, list2):
if len(list1) != len(list2):
return False
def _compare_str_list(list1, list2):
assert len(list1) == len(list2), f"len({list1}) != len({list2})"
for x, y in zip(list1, list2):
if to_str(x) != to_str(y):
return False
return True
assert to_str(x) == to_str(y), f"{to_str(x)} != {to_str(y)}"


def calc_g2_in_impurity_model(solver_name, solver_params, mpirun_command, basis_rot, Umat, gf_struct, beta, n_iw,
Expand Down Expand Up @@ -279,7 +276,7 @@ def __init__(self, h5_file, bse_info, n_corr_shells, n_flavors, use_spin_orbit,
assert n_block == len(spin_names)

# NOTE: change the order of spins in HDF5 to meet SumkDFTChi
self.block2 = IndexPair2(list(range(n_corr_shells)), sorted(spin_names), only_diagonal1=only_diagonal)
self.block2 = IndexPair2(list(range(n_corr_shells)), spin_names, only_diagonal1=only_diagonal)
self.inner2 = IndexPair(list(range(n_inner)), convert_to_int=True)
print(" block2 namelist =", self.block2.namelist)
print(" inner2 namelist =", self.inner2.namelist)
Expand All @@ -289,8 +286,8 @@ def __init__(self, h5_file, bse_info, n_corr_shells, n_flavors, use_spin_orbit,
self.h5bse = h5BSE(h5_file, bse_grp)
if bse_info == 'check':
# check equivalence of info
#assert compare_str_list(h5bse.get(key=('block_name',)), self.block2.namelist)
#assert compare_str_list(h5bse.get(key=('inner_name',)), self.inner2.namelist)
_compare_str_list(self.h5bse.get(key=('block_name',)), self.block2.namelist)
_compare_str_list(self.h5bse.get(key=('inner_name',)), self.inner2.namelist)
assert self.h5bse.get(key=('beta',)) == beta
elif bse_info == 'save':
# save info
Expand Down Expand Up @@ -342,7 +339,7 @@ def save_xloc(self, xloc_ijkl, icrsh):
self._save_common(xloc_ijkl, icrsh, 'X_loc')

def save_chiloc(self, chiloc_ijkl, icrsh):
self._save_common(chiloc_ijkl, icrsh, 'chi_loc')
self._save_common(chiloc_ijkl, icrsh, 'chi_loc_in')

def save_gamma0(self, u_mat, icrsh):

Expand Down Expand Up @@ -411,7 +408,7 @@ def _calc_bse_x0q(self):
Calc X_0(q)
"""
print("\n--- dcore_bse - X_0(q)")
if self._params['bse']['skip_X0q_if_exists'] and os.path.exists(self._params['bse']['h5_output_file']):
if self._params['bse']['skip_X0q']:
print(" skip")
return

Expand Down Expand Up @@ -457,10 +454,16 @@ def calc_num_flavors(_ish):
# init for saving data into HDF5
#
print("\n--- dcore_bse - invoking h5BSE...")

if os.path.isfile(self._params['bse']['h5_output_file']):
bse_info = 'check'
else:
bse_info = 'save'

bse = SaveBSE(
n_corr_shells=self._n_corr_shells,
h5_file=os.path.abspath(self._params['bse']['h5_output_file']),
bse_info='check',
bse_info=bse_info,
nonlocal_order_parameter=False,
use_spin_orbit=self._use_spin_orbit,
beta=self._beta,
Expand Down Expand Up @@ -627,28 +630,29 @@ def dcore_bse(filename, np=1):
#
# Construct a parser with default values
#
pars = create_parser(['model', 'system', 'impurity_solver', 'mpi', 'bse'])

pars = create_parser(["model", "system", "impurity_solver", "mpi", "bse"])
#
# Parse keywords and store
#
pars.read(filename)
p = pars.as_dict()
parse_parameters(p)
seedname = p["model"]["seedname"]
p["mpi"]["num_processes"] = np
params = pars.as_dict()
parse_parameters(params)

params["mpi"]["num_processes"] = np

# Delete unnecessary parameters
delete_parameters(p, block='model', delete=['bvec'])
delete_parameters(p, block='system', retain=['beta', 'n_iw', 'mu', 'fix_mu', 'prec_mu', 'with_dc', 'no_tail_fit'])
delete_parameters(params, block='model', delete=['interaction', 'density_density', 'kanamori', 'slater_f', 'slater_uj', 'slater_basis', 'interaction_file', 'local_potential_matrix', 'local_potential_factor'])
delete_parameters(params, block='model', delete=['bvec'])
delete_parameters(params, block='system', retain=['beta', 'n_iw', 'mu', 'fix_mu', 'prec_mu', 'with_dc', 'no_tail_fit'])

# Summary of input parameters
print_parameters(p)
print_parameters(params)

#
# Load DMFT data
#
solver = DMFTBSESolver(seedname, p, output_file=seedname + '.out.h5')
seedname = params["model"]["seedname"]
solver = DMFTBSESolver(seedname, params, output_file=seedname + '.out.h5')
if solver.iteration_number == 0:
raise RuntimeError("Number of iterations is zero!")
print("Number of iterations :", solver.iteration_number)
Expand Down
2 changes: 1 addition & 1 deletion src/dcore/dcore_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def dcore_post(filename, np=1, prefix=None):
#
# Delete unnecessary parameters
#
delete_parameters(p, block='model', delete=['interaction', 'density_density', 'kanamori', 'slater_f', 'slater_uj', 'slater_basis', 'local_potential_matrix', 'local_potential_factor'])
delete_parameters(p, block='model', delete=['interaction', 'density_density', 'kanamori', 'slater_f', 'slater_uj', 'slater_basis', 'interaction_file', 'local_potential_matrix', 'local_potential_factor'])

# Summary of input parameters
print_parameters(p)
Expand Down
58 changes: 46 additions & 12 deletions src/dcore/dcore_pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def __generate_local_potential(p):
spin_orbit = p["model"]["spin_orbit"]

# read parameters from DFT data
skc = SumkDFTCompat(p["model"]["seedname"] + '.h5')
try:
skc = SumkDFTCompat(p["model"]["seedname"] + '.h5')
except RuntimeError as e:
print(f"\nERROR: {e}", file=sys.stderr)
print("Generate lattice model by running dcore_pre with skip_lattice=False (default) before generating local potential.", file=sys.stderr)
sys.exit(1)

assert skc.n_inequiv_shells == n_inequiv_shells

Expand Down Expand Up @@ -122,7 +127,7 @@ def dcore_pre(input_filenames):
#
# Construct a parser with default values
#
pars = create_parser(['model'])
pars = create_parser(['model', 'pre'])
#
# Parse keywords and store
#
Expand All @@ -140,44 +145,73 @@ def dcore_pre(input_filenames):
#
print_parameters(p)

print("\n@@@@@@@@@@@@@@@@@@@ Generate Model-HDF5 File @@@@@@@@@@@@@@@@@@@@")
#
# remove HDF5 file if exists
#
h5_file = p['model']['seedname'] + '.h5'
if p['model']['lattice'] != 'external':
if os.path.exists(h5_file):
print("\nRemoving the existing model HDF5 file...")
if os.path.exists(h5_file):
print(f"\nFile '{h5_file}' found")
if p['pre']['overwrite']:
print(" --> overwritten (overwrite=True)")
else:
print(" --> replaced (overwrite=False)")
os.remove(h5_file)
else:
print(f"\nFile '{h5_file}' is created")


#
# Lattice information
# -> create h5_file/dft_input
#
print("\n@@@@@@@@@@@@@@@@@@@ Generate Model-HDF5 File @@@@@@@@@@@@@@@@@@@@\n")
lattice_model = create_lattice_model(p)
lattice_model.generate_model_file()
print("\nGenerating lattice model including H(k)")
print(f" in {h5_file}/dft_input")
if p['pre']['skip_lattice']:
print("skip")
else:
lattice_model = create_lattice_model(p)
lattice_model.generate_model_file()

#
# Interaction
# -> create h5_file/DCore/umat
#
print("\nGenerating U-matrix")
generate_umat(p)
print(f" in {h5_file}/DCore/Umat")
if p['pre']['skip_umat']:
print("skip")
else:
generate_umat(p)

#
# Local potential
# -> create h5_file/DCore/local_potential
#
print("\nGenerating local potential")
__generate_local_potential(p)
print(f" in {h5_file}/DCore/LocalPotential")
if p['pre']['skip_local_potential']:
print("skip")
else:
__generate_local_potential(p)

#
# Check HDF5 file
#
print('')
print('@@@@@@@@@@@@@@@@@@@ Check Model-HDF5 file @@@@@@@@@@@@@@@@@@@@')
__check_if_Hk_is_hermite(h5_file)
print_local_fields(h5_file)

print("\nChecking H(k)")
if p['pre']['skip_lattice']:
print("skip")
else:
__check_if_Hk_is_hermite(h5_file)

print("\nLocal Fields")
if p['pre']['skip_lattice']:
print("skip")
else:
print_local_fields(h5_file)

#
# Finish
Expand Down
11 changes: 9 additions & 2 deletions src/dcore/program_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def create_parser(target_sections=None):
parser.add_option("model", "local_potential_matrix", str, "None", "dict of {ish: 'filename'} to specify local potential matrix of ish-th shell")
parser.add_option("model", "local_potential_factor", str, "1.0", "Prefactors to the local potential matrix (float or list with len=ncor)")

# [pre]
parser.add_option("pre", "skip_lattice", bool, False, "Skip generation of lattice model including H(k) in dcore_pre. If True, data in seedname.h5/dft_input are kept.")
parser.add_option("pre", "skip_umat", bool, False, "Skip generation of U matrix in dcore_pre. If True, data in seedname.h5/DCore/Umat are kept.")
parser.add_option("pre", "skip_local_potential", bool, False, "Skip generation of local potential in dcore_pre. If True, data in seedname.h5/DCore/LocalPotential are kept.")
parser.add_option("pre", "overwrite", bool, True, "Whether seedname.h5 is overwritten. If False, the existing seedname.h5 is repalced.")

# [system]
parser.add_option("system", "beta", float, 1.0, "Inverse temperature. This parameter is overwritten, if T is given.")
parser.add_option("system", "T", float, -1.0, "Temperature. If this parameter is given, beta is overwritten by 1/T.")
Expand Down Expand Up @@ -148,9 +154,10 @@ def create_parser(target_sections=None):
parser.add_option("bse", "num_wb", int, 1, "Number of bosonic frequencies (>0)")
parser.add_option("bse", "num_wf", int, 10, "Number of fermionic frequencies (>0)")
parser.add_option("bse", "h5_output_file", str, 'dmft_bse.h5', "Output HDF5 file for bse data")
parser.add_option("bse", "skip_X0q_if_exists", bool, False, "Skip X_0(q) calc if file already exists")
parser.add_option("bse", "skip_X0q_if_exists", bool, False, "[NOT USED] Skip X_0(q) calc if file already exists", OptionStatus.RETIRED)
parser.add_option("bse", "skip_X0q", bool, False, "Skip X_0(q) calc")
parser.add_option("bse", "skip_Xloc", bool, False, "Skip X_loc calc (for RPA)")
parser.add_option("bse", "calc_only_chiloc", bool, False, "Calculate only chi_loc but no X_loc (for SCL, rRPA).")
parser.add_option("bse", "calc_only_chiloc", bool, False, "Calculate only chi_loc but no X_loc (for SCL, rRPA). Do not activate skip_Xloc when using this option.")
parser.add_option("bse", "use_temp_file", bool, False, "Whether or not temporary file is used in computing X0_q. This option will reduce the memory footprints.")
parser.add_option("bse", "X0q_qpoints_saved", str, 'quadrant', "Specifies for which q points X0q are saved in a HDF file. quadrant or path to a q_path.dat file.")

Expand Down
2 changes: 1 addition & 1 deletion src/dcore/sumkdft_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def read_dft_input_data(file, subgrp, things_to_read):
values = {}
with HDFArchive(file, 'r') as ar:
if not subgrp in ar:
raise RuntimeError("subrp " + subgrp + "does not exist in " + file + "!")
raise RuntimeError("subgrp " + subgrp + " does not exist in " + file + "!")
# first read the necessary things:
for it in things_to_read:
values[it] = ar[subgrp][it]
Expand Down
Loading