Skip to content

Commit

Permalink
Merge branch 'fix_kkr_imp_sub_graph' into develop
Browse files Browse the repository at this point in the history
List of changes:

- fixed issue #13 (change_struc_imp_aux is now a workfunction)

- more information in workflow_info node of kkr_imp workflow

- better graph structure for the kkr_imp_sub workflow

- new input in get_inputs_kkrimp and get_inputs_common
  • Loading branch information
fBert31 committed Nov 29, 2018
2 parents 5bfe38c + 38355ff commit ab13079
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 40 deletions.
9 changes: 6 additions & 3 deletions aiida_kkr/tools/common_workfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def get_inputs_voronoi(code, structure, options, label='', description='', param
return VoronoiProcess, inputs


def get_inputs_kkrimp(code, options, label='', description='', parameters=None, serial=False, imp_info=None, host_GF=None, imp_pot=None):
def get_inputs_kkrimp(code, options, label='', description='', parameters=None, serial=False, imp_info=None, host_GF=None, imp_pot=None, kkrimp_remote=None):
"""
Get the input for a kkrimp calc.
Wrapper for KkrimpProcess setting structure, code, options, label, description etc.
Expand All @@ -281,12 +281,12 @@ def get_inputs_kkrimp(code, options, label='', description='', parameters=None,

# then reuse common inputs setter
inputs = get_inputs_common(KkrimpProcess, code, None, None, options, label,
description, parameters, serial, imp_info, host_GF, imp_pot)
description, parameters, serial, imp_info, host_GF, imp_pot, kkrimp_remote)

return inputs


def get_inputs_common(process, code, remote, structure, options, label, description, params, serial, imp_info=None, host_GF=None, imp_pot=None):
def get_inputs_common(process, code, remote, structure, options, label, description, params, serial, imp_info=None, host_GF=None, imp_pot=None, kkrimp_remote=None):
"""
Base function common in get_inputs_* functions for different codes
"""
Expand Down Expand Up @@ -356,6 +356,9 @@ def get_inputs_common(process, code, remote, structure, options, label, descript

if imp_pot is not None:
inputs.impurity_potential = imp_pot

if kkrimp_remote is not None:
inputs.parent_calc_folder = kkrimp_remote

return inputs

Expand Down
10 changes: 6 additions & 4 deletions aiida_kkr/workflows/kkr_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from aiida.orm import Code, DataFactory, load_node
from aiida.work.workchain import WorkChain, ToContext, if_
from aiida.work.workfunctions import workfunction as wf
from aiida_kkr.calculations.voro import VoronoiCalculation
from masci_tools.io.kkr_params import kkrparams
from aiida_kkr.tools.common_workfunctions import test_and_get_codenode, neworder_potential_wf
Expand Down Expand Up @@ -512,16 +513,17 @@ def return_results(self):
outputnode_dict['gf_wc_success'] = self.ctx.gf_writeout.out.calculation_info.get_attr('successful')
else:
outputnode_dict['used_subworkflows'] = {'auxiliary_voronoi': self.ctx.last_voro_calc.pk, 'kkr_imp_sub': self.ctx.kkrimp_scf_sub.pk}
outputnode_dict['successful'] = last_calc_info.get_attr('convergence_reached')
outputnode_dict['converged'] = last_calc_info.get_attr('convergence_reached')
outputnode_dict['number_of_rms_steps'] = len(last_calc_info.get_attr('convergence_values_all_steps'))
#outputnode_dict['convergence_values_all_steps'] = last_calc_info.get_attr('convergence_values_all_steps')
outputnode_dict['impurity_info'] = self.inputs.impurity_info
outputnode_dict['convergence_values_all_steps'] = last_calc_info.get_attr('convergence_values_all_steps')
outputnode_dict['impurity_info'] = self.inputs.impurity_info.get_attrs()
outputnode_dict['voro_wc_success'] = res_voro_info.get_attr('successful')
outputnode_dict['kkrimp_wc_success'] = last_calc_info.get_attr('successful')
outputnode_dict['last_calculation_pk'] = last_calc_pk
outputnode_t = ParameterData(dict=outputnode_dict)
outputnode_t.label = 'kkrimp_wc_inform'
outputnode_t.description = 'Contains information for workflow'
self.report('INFO: workflow_info node: {}'.format(outputnode_t.get_attrs()))

self.out('workflow_info', outputnode_t)
self.out('last_calc_output_parameters', last_calc_output_params)
Expand All @@ -534,7 +536,7 @@ def return_results(self):
'|------------------------------------------------------------------------------------------------------------------|')


@wf
def change_struc_imp_aux_wf(struc, imp_info): # Note: works for single imp at center only!
from aiida.common.constants import elements as PeriodicTableElements
_atomic_numbers = {data['symbol']: num for num, data in PeriodicTableElements.iteritems()}
Expand Down
88 changes: 55 additions & 33 deletions aiida_kkr/workflows/kkr_imp_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def define(cls, spec):
spec.input("kkrimp", valid_type=Code, required=True)
spec.input("host_imp_startpot", valid_type=SinglefileData, required=True)
spec.input("GF_remote_data", valid_type=RemoteData, required=True)
spec.input("kkrimp_remote", valid_type=RemoteData, required=False)
spec.input("impurity_info", valid_type=ParameterData, required=False)
spec.input("options_parameters", valid_type=ParameterData, required=False,
default=ParameterData(dict=cls._options_default))
Expand Down Expand Up @@ -161,11 +162,11 @@ def define(cls, spec):
message="ERROR: Maximal number of KKR restarts reached. Exiting now!")
spec.exit_code(127, 'ERROR_SETTING_LAST_REMOTE',
message="ERROR: Last_remote could not be set to a previous succesful calculation")
spec.exit_code(127, 'ERROR_MISSING_PARAMS',
spec.exit_code(128, 'ERROR_MISSING_PARAMS',
message="ERROR: There are still missing calculation parameters")
spec.exit_code(128, 'ERROR_PARAMETER_UPDATE',
spec.exit_code(129, 'ERROR_PARAMETER_UPDATE',
message="ERROR: Parameters could not be updated")
spec.exit_code(129, 'ERROR_LAST_CALC_NOT_FINISHED',
spec.exit_code(130, 'ERROR_LAST_CALC_NOT_FINISHED',
message="ERROR: Last calculation is not in finished state")


Expand Down Expand Up @@ -334,10 +335,14 @@ def validate_input(self):
test_and_get_codenode(inputs.kkr, 'kkr.kkrimp', use_exceptions=True)
except ValueError:
inputs_ok = False
return self.exit_codes.ERROR_INVALID_INPUT_KKRIMP
return self.exit_codes.ERROR_INVALID_INPUT_KKRIMP

if 'kkrimp_remote' in inputs:
self.ctx.start_from_imp_remote = True
self.ctx.last_remote = inputs.kkrimp_remote

# set params and remote folder to input
self.ctx.last_remote = inputs.GF_remote_data
#self.ctx.last_remote = inputs.GF_remote_data

# set starting potential
self.ctx.last_pot = inputs.host_imp_startpot
Expand Down Expand Up @@ -429,32 +434,35 @@ def update_kkrimp_params(self):
for icalc in range(len(self.ctx.calcs))[::-1]:
self.report("INFO: last calc success? {} {}".format(icalc, self.ctx.KKR_steps_stats['success'][icalc]))
if self.ctx.KKR_steps_stats['success'][icalc]:
self.ctx.last_remote = self.ctx.calcs[icalc].out.remote_folder
if self.ctx.KKR_steps_stats['last_rms'][icalc] < self.ctx.KKR_steps_stats['first_rms'][icalc]:
self.ctx.last_remote = self.ctx.calcs[icalc].out.remote_folder
else:
self.ctx.last_remote = None
break # exit loop if last_remote was found successfully
else:
self.ctx.last_remote = None
# if no previous calculation was succesful take voronoi output
# or remote data from input (depending on the inputs)
self.report("INFO: Last_remote is None? {} {}".format(self.ctx.last_remote is None, 'structure' in self.inputs))
if self.ctx.last_remote is None:
if 'structure' in self.inputs:
self.ctx.voronoi.out.last_voronoi_remote
else:
self.ctx.last_remote = self.inputs.remote_data
if 'kkrimp_remote' in self.inputs:
self.ctx.last_remote = self.inputs.kkrimp_remote
self.report('INFO: no successful and converging calculation to take RemoteData from. Reuse RemoteData from input instead.')
elif 'impurity_info' in self.inputs or 'GF_remote_data' in self.inputs:
self.ctx.last_remote = None
# check if last_remote has finally been set and abort if this is not the case
self.report("INFO: last_remote is still None? {}".format(self.ctx.last_remote is None))
if self.ctx.last_remote is None:
error = 'ERROR: last_remote could not be set to a previous succesful calculation'
self.ctx.errors.append(error)
return self.exit_codes.ERROR_SETTING_LAST_REMOTE
self.report("INFO: restart next calculation run from initial inputs")
# if self.ctx.last_remote is None:
# error = 'ERROR: last_remote could not be set to a previous succesful calculation. Try restarting the workflow with different inputs'
# self.ctx.errors.append(error)
# return self.exit_codes.ERROR_SETTING_LAST_REMOTE

# check if mixing strategy should be changed
last_mixing_scheme = self.ctx.last_params.get_dict()['IMIX']
if last_mixing_scheme is None:
last_mixing_scheme = 0

# TODO: problem with convergence on track has to be solved, just set as true for testing
convergence_on_track = True
#convergence_on_track = True
if convergence_on_track:
last_rms = self.ctx.last_rms_all[-1]
if last_rms < self.ctx.threshold_aggressive_mixing and last_mixing_scheme == 0:
Expand Down Expand Up @@ -671,23 +679,32 @@ def run_kkrimp(self):
params = self.ctx.last_params
host_GF = self.inputs.GF_remote_data
imp_pot = self.ctx.last_pot
last_remote = self.ctx.last_remote

options = {"max_wallclock_seconds": self.ctx.walltime_sec,
"resources": self.ctx.resources,
"queue_name" : self.ctx.queue}
if self.ctx.custom_scheduler_commands:
options["custom_scheduler_commands"] = self.ctx.custom_scheduler_commands
if 'impurity_info' in self.inputs:
self.report('INFO: using impurity_info node as input for kkrimp calculation')
imp_info = self.inputs.impurity_info
label = 'KKRimp calculation step {} (IMIX={}, Zimp: {})'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme, imp_info.get_attr('Zimp'))
description = 'KKRimp calculation of step {}, using mixing scheme {}'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme)
inputs = get_inputs_kkrimp(code, options, label, description, params, not self.ctx.use_mpi, imp_info=imp_info, host_GF=host_GF, imp_pot=imp_pot)
else:
self.report('INFO: getting inpurity_info node from previous GF calculation')
label = 'KKRimp calculation step {} (IMIX={}, GF_remote: {})'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme, host_GF.pk)
description = 'KKRimp calculation of step {}, using mixing scheme {}'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme)
inputs = get_inputs_kkrimp(code, options, label, description, params, not self.ctx.use_mpi, host_GF=host_GF, imp_pot=imp_pot)

if last_remote is None:
if 'impurity_info' in self.inputs:
self.report('INFO: using impurity_info node as input for kkrimp calculation')
imp_info = self.inputs.impurity_info
label = 'KKRimp calculation step {} (IMIX={}, Zimp: {})'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme, imp_info.get_attr('Zimp'))
description = 'KKRimp calculation of step {}, using mixing scheme {}'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme)
inputs = get_inputs_kkrimp(code, options, label, description, params, not self.ctx.use_mpi, imp_info=imp_info, host_GF=host_GF, imp_pot=imp_pot)
else:
self.report('INFO: getting inpurity_info node from previous GF calculation')
label = 'KKRimp calculation step {} (IMIX={}, GF_remote: {})'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme, host_GF.pk)
description = 'KKRimp calculation of step {}, using mixing scheme {}'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme)
inputs = get_inputs_kkrimp(code, options, label, description, params, not self.ctx.use_mpi, host_GF=host_GF, imp_pot=imp_pot)
elif last_remote is not None:
# fix to get Zimp properly
self.report('INFO: using RemoteData from previous kkrimp calculation as input')
label = 'KKRimp calculation step {} (IMIX={}, Zimp: {})'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme, None)
description = 'KKRimp calculation of step {}, using mixing scheme {}'.format(self.ctx.loop_count, self.ctx.last_mixing_scheme)
inputs = get_inputs_kkrimp(code, options, label, description, params, not self.ctx.use_mpi, host_GF=host_GF, kkrimp_remote=last_remote)

# run the KKR calculation
self.report('INFO: doing calculation')
Expand All @@ -711,6 +728,8 @@ def inspect_kkrimp(self):
self.ctx.kkrimp_step_success = False
self.report('ERROR: {}', self.exit_codes.ERROR_LAST_CALC_NOT_FINISHED)
return self.exit_codes.ERROR_LAST_CALC_NOT_FINISHED

self.report("INFO: kkrimp_step_success: {}".format(self.ctx.kkrimp_step_success))

# get potential from last calculation
retrieved_path = self.ctx.kkr.out.retrieved.get_abs_path() # retrieved path
Expand All @@ -728,15 +747,18 @@ def inspect_kkrimp(self):

# try yo extract remote folder
try:
if self.convergence_on_track():
self.ctx.last_remote = self.ctx.kkr.out.remote_folder
else:
self.ctx.last_remote = self.inputs.remote_data
self.ctx.last_remote = self.ctx.kkr.out.remote_folder
# elif 'kkrimp_remote' in self.inputs:
# self.ctx.last_remote = self.inputs.kkrimp_remote
#else:
# self.ctx.last_remote = None
#self.ctx.kkrimp_step_success = False
#else:
# self.ctx.last_remote = self.inputs.GF_remote_data
except:
self.ctx.last_remote = None
self.ctx.kkrimp_step_success = False

self.report("INFO: kkrimp_step_success: {}".format(self.ctx.kkrimp_step_success))
self.report("INFO: last_remote: {}".format(self.ctx.last_remote))

if self.ctx.kkrimp_step_success and found_last_calc_output:
Expand Down

0 comments on commit ab13079

Please sign in to comment.