From c9b7c9d77eb699542ab5d9c4f0f1fcdd7aa3afae Mon Sep 17 00:00:00 2001 From: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> Date: Thu, 22 Aug 2024 20:49:34 +0800 Subject: [PATCH] Fix: calling functions for the default value of argument. (#253) ## Summary by CodeRabbit - **New Features** - Enhanced flexibility in parameter handling by allowing `prep_config` and `run_config` to be optional inputs across multiple classes. - Improved clarity of intent in the constructors by utilizing default values of `None` for configuration parameters. - **Bug Fixes** - Ensured that `prep_config` and `run_config` are initialized to a valid dictionary structure if not provided, enhancing robustness. --------- Signed-off-by: zjgemi Co-authored-by: zjgemi Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Han Wang --- dpgen2/superop/prep_run_calypso.py | 6 ++++-- dpgen2/superop/prep_run_diffcsp.py | 6 ++++-- dpgen2/superop/prep_run_dp_train.py | 6 ++++-- dpgen2/superop/prep_run_fp.py | 6 ++++-- dpgen2/superop/prep_run_lmp.py | 6 ++++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/dpgen2/superop/prep_run_calypso.py b/dpgen2/superop/prep_run_calypso.py index d8bc686a..daa48143 100644 --- a/dpgen2/superop/prep_run_calypso.py +++ b/dpgen2/superop/prep_run_calypso.py @@ -58,10 +58,12 @@ def __init__( prep_caly_model_devi_op: Type[OP], run_caly_model_devi_op: Type[OP], expl_mode: str = "default", - prep_config: dict = normalize_step_dict({}), - run_config: dict = normalize_step_dict({}), + prep_config: Optional[dict] = None, + run_config: Optional[dict] = None, upload_python_packages: Optional[List[os.PathLike]] = None, ): + prep_config = normalize_step_dict({}) if prep_config is None else prep_config + run_config = normalize_step_dict({}) if run_config is None else run_config self._input_parameters = { "block_id": InputParameter(type=str, value=""), "expl_task_grp": InputParameter(), diff --git a/dpgen2/superop/prep_run_diffcsp.py b/dpgen2/superop/prep_run_diffcsp.py index c7978e10..c4d3bd87 100644 --- a/dpgen2/superop/prep_run_diffcsp.py +++ b/dpgen2/superop/prep_run_diffcsp.py @@ -53,10 +53,12 @@ def __init__( diffcsp_gen_op: Type[OP], prep_relax_op: Type[OP], run_relax_op: Type[OP], - prep_config: dict = normalize_step_dict({}), - run_config: dict = normalize_step_dict({}), + prep_config: Optional[dict] = None, + run_config: Optional[dict] = None, upload_python_packages: Optional[List[os.PathLike]] = None, ): + prep_config = normalize_step_dict({}) if prep_config is None else prep_config + run_config = normalize_step_dict({}) if run_config is None else run_config self._input_parameters = { "block_id": InputParameter(type=str, value=""), "expl_task_grp": InputParameter(), diff --git a/dpgen2/superop/prep_run_dp_train.py b/dpgen2/superop/prep_run_dp_train.py index 006ff562..0fd988e4 100644 --- a/dpgen2/superop/prep_run_dp_train.py +++ b/dpgen2/superop/prep_run_dp_train.py @@ -60,12 +60,14 @@ def __init__( name: str, prep_train_op: Type[OP], run_train_op: Type[RunDPTrain], - prep_config: dict = normalize_step_dict({}), - run_config: dict = normalize_step_dict({}), + prep_config: Optional[dict] = None, + run_config: Optional[dict] = None, upload_python_packages: Optional[List[os.PathLike]] = None, valid_data: Optional[S3Artifact] = None, optional_files: Optional[List[str]] = None, ): + prep_config = normalize_step_dict({}) if prep_config is None else prep_config + run_config = normalize_step_dict({}) if run_config is None else run_config self._input_parameters = { "block_id": InputParameter(type=str, value=""), "numb_models": InputParameter(type=int), diff --git a/dpgen2/superop/prep_run_fp.py b/dpgen2/superop/prep_run_fp.py index d8085ea3..6203e755 100644 --- a/dpgen2/superop/prep_run_fp.py +++ b/dpgen2/superop/prep_run_fp.py @@ -52,10 +52,12 @@ def __init__( name: str, prep_op: Type[OP], run_op: Type[OP], - prep_config: dict = normalize_step_dict({}), - run_config: dict = normalize_step_dict({}), + prep_config: Optional[dict] = None, + run_config: Optional[dict] = None, upload_python_packages: Optional[List[os.PathLike]] = None, ): + prep_config = normalize_step_dict({}) if prep_config is None else prep_config + run_config = normalize_step_dict({}) if run_config is None else run_config self._input_parameters = { "block_id": InputParameter(type=str, value=""), "fp_config": InputParameter(), diff --git a/dpgen2/superop/prep_run_lmp.py b/dpgen2/superop/prep_run_lmp.py index cc8e02c3..6b4de94a 100644 --- a/dpgen2/superop/prep_run_lmp.py +++ b/dpgen2/superop/prep_run_lmp.py @@ -52,10 +52,12 @@ def __init__( name: str, prep_op: Type[OP], run_op: Type[OP], - prep_config: dict = normalize_step_dict({}), - run_config: dict = normalize_step_dict({}), + prep_config: Optional[dict] = None, + run_config: Optional[dict] = None, upload_python_packages: Optional[List[os.PathLike]] = None, ): + prep_config = normalize_step_dict({}) if prep_config is None else prep_config + run_config = normalize_step_dict({}) if run_config is None else run_config self._input_parameters = { "block_id": InputParameter(type=str, value=""), "explore_config": InputParameter(),