Skip to content

Commit bb0fdbc

Browse files
committed
[feat] add mpi_exe flag and update to latest vasp h5 interface
1 parent 26aebd3 commit bb0fdbc

5 files changed

Lines changed: 55 additions & 12 deletions

File tree

python/solid_dmft/csc_flow.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _full_qe_run(seedname, dft_params, mode):
9898

9999
# runs a full iteration of DFT
100100
qe_wrapper = lambda calc_type: qe.run(dft_params['n_cores'], calc_type, dft_params['dft_exec'],
101-
dft_params['mpi_env'], seedname)
101+
dft_params['mpi_env'], dft_params['mpi_exe'], seedname)
102102

103103
# Initially run an scf calculation
104104
if mode == 'initial':
@@ -179,15 +179,23 @@ def _full_vasp_run(general_params, dft_params, initial_run, n_iter_dft=1, sum_k=
179179
if initial_run:
180180
assert n_iter_dft == 1
181181
else:
182+
dft_iter_init = vasp.read_dft_iter()
182183
assert n_iter_dft == 1 or sum_k is not None, 'Sumk object needed to run multiple DFT iterations'
183184

184185
for i in range(n_iter_dft):
185186
if initial_run:
186187
vasp_process_id = vasp.run_initial_scf(dft_params['n_cores'], dft_params['dft_exec'],
187-
dft_params['mpi_env'])
188+
dft_params['mpi_exe'], dft_params['mpi_env'])
188189
else:
189190
vasp_process_id = None
190191
vasp.run_charge_update()
192+
dft_iter = vasp.read_dft_iter()
193+
mpi.report(f'\nDFT SCF iteration {dft_iter} finished. Running converter:')
194+
if not dft_iter == dft_iter_init+i+1:
195+
mpi.report(f'DFT iteration number did not increase. Aborting.\n \
196+
DFT iteration {dft_iter} != {dft_iter_init+i+1}')
197+
vasp.kill(vasp_process_id)
198+
exit()
191199

192200
if dft_params['projector_type'] == 'plo':
193201
_run_plo_converter(general_params, dft_params)
@@ -221,7 +229,7 @@ def _full_vasp_run(general_params, dft_params, initial_run, n_iter_dft=1, sum_k=
221229
sum_k.calc_mu(precision=general_params['prec_mu'])
222230

223231
# Writes out GAMMA file
224-
sum_k.calc_density_correction(dm_type='vasp', kpts_to_write=irred_indices)
232+
sum_k.calc_density_correction(dm_type='vasp', kpts_to_write=irred_indices)
225233

226234
return vasp_process_id, irred_indices
227235

python/solid_dmft/dft_managers/mpi_helpers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def find_path_to_mpi_command(env_vars, mpi_exe):
9393
string: absolute path to mpi command
9494
"""
9595

96+
# first check if mpi_exe is already full path to executable
97+
if os.path.isfile(mpi_exe):
98+
return mpi_exe
99+
100+
# otherwise, check if mpi_exe is in PATH
96101
for path_directory in env_vars.get('PATH').split(os.pathsep):
97102
if path_directory:
98103
potential_path = os.path.join(path_directory, mpi_exe)

python/solid_dmft/dft_managers/qe_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _start_with_piping(mpi_exe, mpi_arguments, qe_file_ext, env_vars, seedname):
8282
subprocess.check_call(mpi_arguments + [seedname], env=env_vars, shell=False)
8383

8484

85-
def run(number_cores, qe_file_ext, qe_exec, mpi_profile, seedname):
85+
def run(number_cores, qe_file_ext, qe_exec, mpi_profile, mpi_exe_param, seedname):
8686
"""
8787
Starts the VASP child process. Takes care of initializing a clean
8888
environment for the child process. This is needed so that VASP does not
@@ -111,7 +111,8 @@ def run(number_cores, qe_file_ext, qe_exec, mpi_profile, seedname):
111111
env_vars[var_name] = var
112112

113113
# assuming that mpirun points to the correct mpi env
114-
mpi_exe = mpi_helpers.find_path_to_mpi_command(env_vars, 'mpirun')
114+
mpi_exe = mpi_helpers.find_path_to_mpi_command(env_vars, mpi_exe_param)
115+
print('\nMPI executable for QE:', mpi_exe)
115116

116117
if qe_file_ext in ['scf', 'nscf', 'mod_scf', 'bnd']:
117118
qe_exec += f'pw.x -nk {number_cores}'

python/solid_dmft/dft_managers/vasp_manager.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def remove_legacy_projections_suppressed():
9999
mpi.barrier()
100100

101101

102-
def run_initial_scf(number_cores, vasp_command, cluster_name):
102+
def run_initial_scf(number_cores, vasp_command, mpi_exe_param, cluster_name):
103103
"""
104104
Starts the VASP child process. Takes care of initializing a clean
105105
environment for the child process. This is needed so that VASP does not
@@ -133,7 +133,8 @@ def run_initial_scf(number_cores, vasp_command, cluster_name):
133133
env_vars[var_name] = var
134134

135135
# assuming that mpirun points to the correct mpi env
136-
mpi_exe = mpi_helpers.find_path_to_mpi_command(env_vars, 'mpirun')
136+
mpi_exe = mpi_helpers.find_path_to_mpi_command(env_vars, mpi_exe_param)
137+
print('\nMPI executable for Vasp:', mpi_exe)
137138

138139
arguments = mpi_helpers.get_mpi_arguments(cluster_name, mpi_exe, number_cores, vasp_command, hostfile)
139140
vasp_process_id = _fork_and_start_vasp(mpi_exe, arguments, env_vars)
@@ -171,17 +172,44 @@ def run_charge_update():
171172

172173
def read_dft_energy():
173174
"""
174-
Reads DFT energy from the last line of Vasp's OSZICAR.
175+
Reads DFT energy from the last line of Vasp's OSZICAR or from vasptriqs.h5
175176
"""
176-
with open('OSZICAR', 'r') as file:
177-
nextline = file.readline()
178-
while nextline.strip():
179-
line = nextline
177+
h5_energy = False
178+
if os.path.isfile('vaspout.h5'):
179+
with HDFArchive('vaspout.h5', 'r') as h5:
180+
if 'oszicar' in h5['intermediate/ion_dynamics']:
181+
dft_energy = h5['intermediate/ion_dynamics/oszicar'][-1,1]
182+
h5_energy = True
183+
184+
# as backup use OSZICAR file
185+
if not h5_energy:
186+
with open('OSZICAR', 'r') as file:
180187
nextline = file.readline()
181188
dft_energy = float(line.split()[2])
182189

183190
return dft_energy
184191

192+
def read_dft_iter():
193+
"""
194+
Reads DFT iteration number from the last line of the OSZICAR or from Vasp's vasptriqs.h5
195+
"""
196+
h5_iter = False
197+
if os.path.isfile('vaspout.h5'):
198+
with HDFArchive('vaspout.h5', 'r') as h5:
199+
if 'oszicar' in h5['intermediate/ion_dynamics']:
200+
dft_iter = int(h5['intermediate/ion_dynamics/oszicar'][-1,0])
201+
h5_iter = True
202+
203+
# as backup use OSZICAR file
204+
if not h5_iter:
205+
with open('OSZICAR', 'r') as file:
206+
nextline = file.readline()
207+
while nextline.strip():
208+
line = nextline
209+
nextline = file.readline()
210+
dft_iter = int(line.split()[1])
211+
212+
return dft_iter
185213

186214
def read_irred_kpoints(kpts):
187215
""" Reads the indices of the irreducible k-points from the OUTCAR. """

python/solid_dmft/io_tools/default.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ with_fock = false
178178
dft_code = "<none>"
179179
dft_exec = "vasp_std"
180180
mpi_env = "default"
181+
mpi_exe = "mpirun"
181182
n_cores = "<none>"
182183
n_iter = 4
183184
n_iter_first = "<dft.n_iter>"

0 commit comments

Comments
 (0)