Skip to content

Commit

Permalink
Adaptive lower trust level (#118)
Browse files Browse the repository at this point in the history
This PR introduce **breaking** change:
- introduce `convergence` key in the `explore` session of the input
script. This key provides the method of checking exploration
convergence. Now the options are `fixed-levels` and `adaptive-lower`.

Main changes of this PR:
- implement the adaptive lower trust level 
- convergence is reached when the lower trust level does not change much
over iterations.
- remove TrustLevel
- new interface of `ExplorationReportTrustLevels`

Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
  • Loading branch information
wanghan-iapcm and Han Wang committed Jan 27, 2023
1 parent dc21dfe commit b51c9ac
Show file tree
Hide file tree
Showing 24 changed files with 879 additions and 338 deletions.
50 changes: 29 additions & 21 deletions dpgen2/entrypoint/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from dpgen2.fp import fp_styles
from dpgen2.conf import conf_styles
from dpgen2.exploration.report import conv_styles

def dp_train_args():
doc_numb_models = "Number of models trained for evaluating the model deviation"
Expand All @@ -34,34 +35,51 @@ def variant_train():
Argument("dp", dict, dp_train_args()),
], doc=doc)


def variant_conv():
doc = "the type of the convergence check"
var_list = []
for kk in conv_styles.keys():
var_list.append(
Argument(kk, dict, conv_styles[kk].args())
)
return Variant("type", var_list, doc=doc,)


def variant_conf():
doc = "the type of the configuration generator"
var_list = []
for kk in conf_styles.keys():
var_list.append(
Argument(kk, dict, conf_styles[kk].args())
)
return Variant("type", var_list, doc=doc,)


def lmp_args():
doc_config = "Configuration of lmp exploration"
doc_max_numb_iter = "Maximum number of iterations per stage"
doc_conv_accuracy = "Convergence accuracy"
doc_fatal_at_max = "Fatal when the number of iteration per stage reaches the `max_numb_iter`"
doc_f_trust_lo = "Lower trust level of force model deviation"
doc_f_trust_hi = "Higher trust level of force model deviation"
doc_v_trust_lo = "Lower trust level of virial model deviation"
doc_v_trust_hi = "Higher trust level of virial model deviation"
doc_output_nopbc = "Remove pbc of the output configurations"
doc_convergence = "The method of convergence check."
doc_configuration_prefix = "The path prefix of lmp initial configurations"
doc_configuration = "A list of initial configurations."
doc_stages = "A list of exploration stages."

return [
Argument("config", dict, RunLmp.lmp_args(), optional=True, default=RunLmp.normalize_config({}), doc=doc_config),
Argument("max_numb_iter", int, optional=True, default=10, doc=doc_max_numb_iter),
Argument("conv_accuracy", float, optional=True, default=0.9, doc=doc_conv_accuracy),
Argument("fatal_at_max", bool, optional=True, default=True, doc=doc_fatal_at_max),
Argument("f_trust_lo", float, optional=False, doc=doc_f_trust_lo),
Argument("f_trust_hi", float, optional=False, doc=doc_f_trust_hi),
Argument("v_trust_lo", float, optional=True, default=None, doc=doc_v_trust_lo),
Argument("v_trust_hi", float, optional=True, default=None, doc=doc_v_trust_hi),
Argument("output_nopbc", bool, optional=True, default=False, doc=doc_output_nopbc),
Argument("convergence", list,
[], [variant_conv()],
optional=False,
doc=doc_convergence
),
Argument("configuration_prefix", str, optional=True, default=None, doc=doc_configuration_prefix),
Argument("configurations", list,
[], [variant_conf()],
optional=False, repeat=True,
optional=False, repeat=True,
doc=doc_configuration, alias=["configuration"]),
Argument("stages", list, optional=False, doc=doc_stages),
]
Expand Down Expand Up @@ -108,16 +126,6 @@ def variant_fp():
return Variant("type", fp_list, doc=doc)


def variant_conf():
doc = "the type of the configuration generator"
var_list = []
for kk in conf_styles.keys():
var_list.append(
Argument(kk, dict, conf_styles[kk].args())
)
return Variant("type", var_list, doc=doc,)


def input_args():
doc_type_map = 'The type map. e.g. ["Al", "Mg"]. Al and Mg will have type 0 and 1, respectively.'
doc_mass_map = "The mass map. e.g. [27., 24.]. Al and Mg will be set with mass 27. and 24. amu, respectively."
Expand Down
22 changes: 9 additions & 13 deletions dpgen2/entrypoint/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
from dpgen2.conf import (
conf_styles,
)
from dpgen2.exploration.report import (
conv_styles,
)
from dpgen2.exploration.scheduler import (
ExplorationScheduler,
ConvergenceCheckStageScheduler,
Expand All @@ -62,7 +65,6 @@
)
from dpgen2.exploration.selector import (
ConfSelectorFrames,
TrustLevel,
)
from dpgen2.exploration.render import (
TrajRenderLammps,
Expand Down Expand Up @@ -194,16 +196,16 @@ def make_naive_exploration_scheduler(
mass_map = config['mass_map'] if old_style else config['inputs']['mass_map']
type_map = config['type_map'] if old_style else config['inputs']['type_map']
numb_models = config['numb_models'] if old_style else config['train']['numb_models']
fp_task_max = config['fp_task_max'] if old_style else config['fp']['task_max']
conv_accuracy = config['conv_accuracy'] if old_style else config['explore']['conv_accuracy']
fp_task_max = config['fp_task_max'] if old_style else config['fp']['task_max']
max_numb_iter = config['max_numb_iter'] if old_style else config['explore']['max_numb_iter']
output_nopbc = False if old_style else config['explore']['output_nopbc']
fatal_at_max = config.get('fatal_at_max', True) if old_style else config['explore']['fatal_at_max']
convergence = config['explore']['convergence']
output_nopbc = False if old_style else config['explore']['output_nopbc']
scheduler = ExplorationScheduler()

sys_configs_lmp = []
for sys_config in sys_configs:
conf_style = sys_config.pop("type")
conf_style = sys_config.pop("type")
generator = conf_styles[conf_style](**sys_config)
sys_configs_lmp.append(generator.get_file_content(type_map))

Expand Down Expand Up @@ -234,15 +236,9 @@ def make_naive_exploration_scheduler(
)
tasks = tgroup.make_task()
stage.add_task_group(tasks)
# trust level
trust_level = TrustLevel(
config['model_devi_f_trust_lo'] if old_style else config['explore']['f_trust_lo'],
config['model_devi_f_trust_hi'] if old_style else config['explore']['f_trust_hi'],
level_v_lo=config.get('model_devi_v_trust_lo') if old_style else config['explore']['v_trust_lo'],
level_v_hi=config.get('model_devi_v_trust_hi') if old_style else config['explore']['v_trust_hi'],
)
# report
report = ExplorationReportTrustLevels(trust_level, conv_accuracy)
conv_style = convergence.pop("type")
report = conv_styles[conv_style](**convergence)
render = TrajRenderLammps(nopbc=output_nopbc)
# selector
selector = ConfSelectorFrames(
Expand Down
8 changes: 8 additions & 0 deletions dpgen2/exploration/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
from .report_trust_levels import (
ExplorationReportTrustLevels,
)
from .report_adaptive_lower import (
ExplorationReportAdaptiveLower,
)

conv_styles = {
"fixed-levels" : ExplorationReportTrustLevels,
"adaptive-lower" : ExplorationReportAdaptiveLower,
}
18 changes: 16 additions & 2 deletions dpgen2/exploration/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ def record(
pass

@abstractmethod
def converged(self) -> bool :
r"""If the exploration is converged"""
def converged(
self,
reports,
)->bool:
r"""Check if the exploration is converged.
Parameters
----------
reports List[ExplorationReportTrustLevels]
Historical reports
Returns
-------
converged bool
If the exploration is converged.
"""
pass

def no_candidate(self) -> bool:
Expand Down

0 comments on commit b51c9ac

Please sign in to comment.