From 9ab95b09c168bc299860f652241fa2377378696b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 28 Oct 2021 17:43:06 -0400 Subject: [PATCH 1/2] deprecate `numb_test` See #1243. --- deepmd/utils/argcheck.py | 2 -- deepmd/utils/compat.py | 45 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/deepmd/utils/argcheck.py b/deepmd/utils/argcheck.py index db31469c29..36e9eb2ee6 100644 --- a/deepmd/utils/argcheck.py +++ b/deepmd/utils/argcheck.py @@ -605,7 +605,6 @@ def training_args(): # ! modified by Ziyao: data configuration isolated. doc_seed = 'The random seed for getting frames from the training data set.' doc_disp_file = 'The file for printing learning curve.' doc_disp_freq = 'The frequency of printing learning curve.' - doc_numb_test = 'Number of frames used for the test during training.' doc_save_freq = 'The frequency of saving check point.' doc_save_ckpt = 'The file name of saving check point.' doc_disp_training = 'Displaying verbose information during training.' @@ -626,7 +625,6 @@ def training_args(): # ! modified by Ziyao: data configuration isolated. Argument("seed", [int,None], optional=True, doc=doc_seed), Argument("disp_file", str, optional=True, default='lcurve.out', doc=doc_disp_file), Argument("disp_freq", int, optional=True, default=1000, doc=doc_disp_freq), - Argument("numb_test", [list,int,str], optional=True, default=1, doc=doc_numb_test), Argument("save_freq", int, optional=True, default=1000, doc=doc_save_freq), Argument("save_ckpt", str, optional=True, default='model.ckpt', doc=doc_save_ckpt), Argument("disp_training", bool, optional=True, default=True, doc=doc_disp_training), diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 66387bf0b8..4711a98427 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -316,6 +316,43 @@ def _warning_input_v1_v2(fname: Optional[Union[str, Path]]): warnings.warn(msg) +def deprecate_numb_test(jdata: Dict[str, Any], + warning: bool = True, + dump: Optional[Union[str, Path]] = None) -> Dict[str, Any]: + """Deprecate `numb_test` since v2.1. It has taken no effect since v2.0. + + See `#1243 `_. + + Parameters + ---------- + jdata : Dict[str, Any] + loaded json/yaml file + warning : bool, optional + whether to show deprecation warning, by default True + dump : Optional[Union[str, Path]], optional + whether to dump converted file, by default None + + Returns + ------- + Dict[str, Any] + converted output + """ + try: + jdata.get("training", {}).pop("numb_test") + except KeyError: + pass + else: + if warning: + warnings.warn( + "The argument training->numb_test has been deprecated since v2.0.0. " + "Use training->validation_data->batch_size instead." + ) + + if dump is not None: + with open(dump, "w") as fp: + json.dump(jdata, fp, indent=4) + + def updata_deepmd_input(jdata: Dict[str, Any], warning: bool = True, dump: Optional[Union[str, Path]] = None) -> Dict[str, Any]: @@ -327,10 +364,12 @@ def is_deepmd_v1_input(jdata): if is_deepmd_v0_input(jdata): jdata = convert_input_v0_v1(jdata, warning, None) - jdata = convert_input_v1_v2(jdata, False, dump) + jdata = convert_input_v1_v2(jdata, False, None) + jdata = deprecate_numb_test(jdata, False, dump) elif is_deepmd_v1_input(jdata): - jdata = convert_input_v1_v2(jdata, warning, dump) + jdata = convert_input_v1_v2(jdata, warning, None) + jdata = deprecate_numb_test(jdata, False, dump) else: - pass + jdata = deprecate_numb_test(jdata, warning, dump) return jdata From 9598442871516caed31a9cfa5d17ae9b3fcd277a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 28 Oct 2021 17:49:41 -0400 Subject: [PATCH 2/2] bugfix --- deepmd/utils/compat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 4711a98427..bae778e426 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -351,6 +351,7 @@ def deprecate_numb_test(jdata: Dict[str, Any], if dump is not None: with open(dump, "w") as fp: json.dump(jdata, fp, indent=4) + return jdata def updata_deepmd_input(jdata: Dict[str, Any],