diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 5f0225c0cd..5f4e758f0b 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -67,7 +67,6 @@ def test( model: str, system: str, datafile: str, - set_prefix: str, numb_test: int, rand_seed: Optional[int], shuffle_test: bool, @@ -86,8 +85,6 @@ def test( system directory datafile : str the path to the list of systems to test - set_prefix : str - string prefix of set numb_test : int munber of tests to do. 0 means all data. rand_seed : Optional[int] @@ -137,7 +134,7 @@ def test( tmap = dp.get_type_map() if isinstance(dp, DeepPot) else None data = DeepmdData( system, - set_prefix, + set_prefix="set", shuffle_test=shuffle_test, type_map=tmap, sort_atoms=False, diff --git a/deepmd/infer/model_devi.py b/deepmd/infer/model_devi.py index a37dfd34c5..477acf0282 100644 --- a/deepmd/infer/model_devi.py +++ b/deepmd/infer/model_devi.py @@ -350,7 +350,6 @@ def make_model_devi( *, models: list, system: str, - set_prefix: str, output: str, frequency: int, real_error: bool = False, @@ -367,8 +366,6 @@ def make_model_devi( A list of paths of models to use for making model deviation system : str The path of system to make model deviation calculation - set_prefix : str - The set prefix of the system output : str The output file for model deviation results frequency : int @@ -410,7 +407,7 @@ def make_model_devi( for system in all_sys: # create data-system dp_data = DeepmdData( - system, set_prefix, shuffle_test=False, type_map=tmap, sort_atoms=False + system, "set", shuffle_test=False, type_map=tmap, sort_atoms=False ) if first_dp.get_dim_fparam() > 0: dp_data.add( diff --git a/deepmd/main.py b/deepmd/main.py index 9d023221a6..e9e7b0fcad 100644 --- a/deepmd/main.py +++ b/deepmd/main.py @@ -9,6 +9,7 @@ import logging import os import textwrap +import warnings from collections import ( defaultdict, ) @@ -69,6 +70,24 @@ def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, BACKEND_TABLE[values]) +class DeprecateAction(argparse.Action): + # See https://stackoverflow.com/a/69052677/9567349 by Ibolit under CC BY-SA 4.0 + def __init__(self, *args, **kwargs): + self.call_count = 0 + if "help" in kwargs: + kwargs["help"] = f'[DEPRECATED] {kwargs["help"]}' + super().__init__(*args, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + if self.call_count == 0: + warnings.warn( + f"The option `{option_string}` is deprecated. It will be ignored.", + FutureWarning, + ) + delattr(namespace, self.dest) + self.call_count += 1 + + def main_parser() -> argparse.ArgumentParser: """DeePMD-Kit commandline options argument parser. @@ -355,9 +374,8 @@ def main_parser() -> argparse.ArgumentParser: parser_tst.add_argument( "-S", "--set-prefix", - default="set", - type=str, - help="(Supported backend: TensorFlow) The set prefix", + action=DeprecateAction, + help="Deprecated argument.", ) parser_tst.add_argument( "-n", @@ -528,7 +546,7 @@ def main_parser() -> argparse.ArgumentParser: help="The system directory. Recursively detect systems in this directory.", ) parser_model_devi.add_argument( - "-S", "--set-prefix", default="set", type=str, help="The set prefix" + "-S", "--set-prefix", action=DeprecateAction, help="Deprecated argument." ) parser_model_devi.add_argument( "-o", diff --git a/deepmd/tf/nvnmd/data/data.py b/deepmd/tf/nvnmd/data/data.py index 7f2c9ef5e9..55e7c51bc7 100644 --- a/deepmd/tf/nvnmd/data/data.py +++ b/deepmd/tf/nvnmd/data/data.py @@ -319,7 +319,7 @@ "disp_training": True, "time_training": True, "profiling": False, - "training_data": {"systems": "dataset", "set_prefix": "set", "batch_size": 1}, + "training_data": {"systems": "dataset", "batch_size": 1}, }, } @@ -385,7 +385,7 @@ "disp_training": True, "time_training": True, "profiling": False, - "training_data": {"systems": "dataset", "set_prefix": "set", "batch_size": 1}, + "training_data": {"systems": "dataset", "batch_size": 1}, }, } diff --git a/deepmd/utils/argcheck.py b/deepmd/utils/argcheck.py index c817536b92..f6dbada56c 100644 --- a/deepmd/utils/argcheck.py +++ b/deepmd/utils/argcheck.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import json import logging +import warnings from typing import ( Callable, List, @@ -54,6 +55,24 @@ def make_link(content, ref_key): ) +def deprecate_argument_extra_check(key: str) -> Callable[[dict], bool]: + """Generate an extra check to deprecate an argument in sub fields. + + Parameters + ---------- + key : str + The name of the deprecated argument. + """ + + def deprecate_something(data: Optional[dict]): + if data is not None and key in data: + warnings.warn(f"{key} has been removed and takes no effect.", FutureWarning) + data.pop(key) + return True + + return deprecate_something + + def type_embedding_args(): doc_neuron = "Number of neurons in each hidden layers of the embedding net. When two layers are of the same size or one layer is twice as large as the previous layer, a skip connection is built." doc_resnet_dt = 'Whether to use a "Timestep" in the skip connection' @@ -1951,7 +1970,6 @@ def training_data_args(): # ! added by Ziyao: new specification style for data "This key can be provided with a list that specifies the systems, or be provided with a string " "by which the prefix of all systems are given and the list of the systems is automatically generated." ) - doc_set_prefix = f"The prefix of the sets in the {link_sys}." doc_batch_size = f'This key can be \n\n\ - list: the length of which is the same as the {link_sys}. The batch size of each system is given by the elements of the list.\n\n\ - int: all {link_sys} use the same batch size.\n\n\ @@ -1973,7 +1991,6 @@ def training_data_args(): # ! added by Ziyao: new specification style for data Argument( "systems", [List[str], str], optional=False, default=".", doc=doc_systems ), - Argument("set_prefix", str, optional=True, default="set", doc=doc_set_prefix), Argument( "batch_size", [List[int], int, str], @@ -2009,6 +2026,7 @@ def training_data_args(): # ! added by Ziyao: new specification style for data sub_fields=args, sub_variants=[], doc=doc_training_data, + extra_check=deprecate_argument_extra_check("set_prefix"), ) @@ -2019,7 +2037,6 @@ def validation_data_args(): # ! added by Ziyao: new specification style for dat "This key can be provided with a list that specifies the systems, or be provided with a string " "by which the prefix of all systems are given and the list of the systems is automatically generated." ) - doc_set_prefix = f"The prefix of the sets in the {link_sys}." doc_batch_size = f'This key can be \n\n\ - list: the length of which is the same as the {link_sys}. The batch size of each system is given by the elements of the list.\n\n\ - int: all {link_sys} use the same batch size.\n\n\ @@ -2040,7 +2057,6 @@ def validation_data_args(): # ! added by Ziyao: new specification style for dat Argument( "systems", [List[str], str], optional=False, default=".", doc=doc_systems ), - Argument("set_prefix", str, optional=True, default="set", doc=doc_set_prefix), Argument( "batch_size", [List[int], int, str], @@ -2090,6 +2106,7 @@ def validation_data_args(): # ! added by Ziyao: new specification style for dat sub_fields=args, sub_variants=[], doc=doc_validation_data, + extra_check=deprecate_argument_extra_check("set_prefix"), ) diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 5f9c14e6d8..11f5e639dc 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -263,7 +263,8 @@ def _jcopy(src: Dict[str, Any], dst: Dict[str, Any], keys: Sequence[str]): list of keys to copy """ for k in keys: - dst[k] = src[k] + if k in src: + dst[k] = src[k] def remove_decay_rate(jdata: Dict[str, Any]): diff --git a/doc/nvnmd/nvnmd.md b/doc/nvnmd/nvnmd.md index 67cfb5e22d..c415b275ec 100644 --- a/doc/nvnmd/nvnmd.md +++ b/doc/nvnmd/nvnmd.md @@ -153,7 +153,6 @@ The "training" section is defined as "save_freq": 10000, "training_data": { "systems": ["system1_path", "system2_path", "..."], - "set_prefix": "set", "batch_size": ["batch_size_of_system1", "batch_size_of_system2", "..."] } } @@ -171,7 +170,6 @@ where items are defined as: | save_ckpt | path prefix of check point files | a string | | save_freq | save frequency | a positive integer | | systems | a list of data directory which contains the dataset | string list | -| set_prefix | the prefix of dataset | a string | | batch_size | a list of batch size of corresponding dataset | a integer list | ## Training diff --git a/doc/train/tensorboard.md b/doc/train/tensorboard.md index 7b41c004ce..32ecdd0ab2 100644 --- a/doc/train/tensorboard.md +++ b/doc/train/tensorboard.md @@ -28,7 +28,6 @@ directory by modifying the input script, setting {ref}`tensorboard