From e5e174b649d717cde6a1b5282e2ee7d6474877ee Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:30:41 +0800 Subject: [PATCH 1/5] support using a list of systems to do dp test --- deepmd/entrypoints/main.py | 7 +++++++ deepmd/entrypoints/test.py | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index 35273bf4f7..b588853461 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -271,6 +271,13 @@ def main_parser() -> argparse.ArgumentParser: type=str, help="The system dir. Recursively detect systems in this directory", ) + parser_tst.add_argument( + "-l", + "--datalist", + default=None, + type=str, + help="The list of systems to test.", + ) parser_tst.add_argument( "-S", "--set-prefix", default="set", type=str, help="The set prefix" ) diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 76057419f3..25a47d5b0e 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -23,6 +23,7 @@ def test( *, model: str, system: str, + datalist: str, set_prefix: str, numb_test: int, rand_seed: Optional[int], @@ -39,6 +40,8 @@ def test( path where model is stored system : str system directory + datalist: str + the path to the list of systems to test set_prefix : str string prefix of set numb_test : int @@ -57,11 +60,15 @@ def test( RuntimeError if no valid system was found """ - all_sys = expand_sys_str(system) - if len(all_sys) == 0: - raise RuntimeError("Did not find valid system") - err_coll = [] - siz_coll = [] + if(datalist is not None): + all_sys = open(datalist, 'r') + all_sys = [i.strip() for i in all_sys.readlines()] + else: + all_sys = expand_sys_str(system) + if len(all_sys) == 0: + raise RuntimeError("Did not find valid system") + err_coll = [] + siz_coll = [] # init random seed if rand_seed is not None: From dcee21ce3f6660272fc9b3ddef4497aebfe3c337 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Tue, 10 Jan 2023 10:51:44 +0800 Subject: [PATCH 2/5] use -f to avoid conflict --- deepmd/entrypoints/main.py | 4 ++-- deepmd/entrypoints/test.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index b588853461..492c95404c 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -272,8 +272,8 @@ def main_parser() -> argparse.ArgumentParser: help="The system dir. Recursively detect systems in this directory", ) parser_tst.add_argument( - "-l", - "--datalist", + "-f", + "--datafile", default=None, type=str, help="The list of systems to test.", diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 25a47d5b0e..ed1855dab9 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -23,7 +23,7 @@ def test( *, model: str, system: str, - datalist: str, + datafile: str, set_prefix: str, numb_test: int, rand_seed: Optional[int], @@ -40,7 +40,7 @@ def test( path where model is stored system : str system directory - datalist: str + datafile: str the path to the list of systems to test set_prefix : str string prefix of set @@ -60,15 +60,15 @@ def test( RuntimeError if no valid system was found """ - if(datalist is not None): - all_sys = open(datalist, 'r') + if(datafile is not None): + all_sys = open(datafile, 'r') all_sys = [i.strip() for i in all_sys.readlines()] else: all_sys = expand_sys_str(system) if len(all_sys) == 0: raise RuntimeError("Did not find valid system") - err_coll = [] - siz_coll = [] + err_coll = [] + siz_coll = [] # init random seed if rand_seed is not None: From 91ed0ec087e7f8423b10deb733f0e799f3e307c9 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:05:01 +0800 Subject: [PATCH 3/5] use subgroup --- deepmd/entrypoints/main.py | 5 +++-- deepmd/entrypoints/test.py | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index 492c95404c..d50f3b9051 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -264,14 +264,15 @@ def main_parser() -> argparse.ArgumentParser: type=str, help="Frozen model file to import", ) - parser_tst.add_argument( + parser_tst_subgroup = parser_tst.add_mutually_exclusive_group() + parser_tst_subgroup.add_argument( "-s", "--system", default=".", type=str, help="The system dir. Recursively detect systems in this directory", ) - parser_tst.add_argument( + parser_tst_subgroup.add_argument( "-f", "--datafile", default=None, diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index ed1855dab9..7583a11f3e 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -60,13 +60,15 @@ def test( RuntimeError if no valid system was found """ - if(datafile is not None): + if datafile is not None: all_sys = open(datafile, 'r') all_sys = [i.strip() for i in all_sys.readlines()] + datafile.close() else: all_sys = expand_sys_str(system) - if len(all_sys) == 0: - raise RuntimeError("Did not find valid system") + + if len(all_sys) == 0: + raise RuntimeError("Did not find valid system") err_coll = [] siz_coll = [] From 120def1c3d23e93f1daa805934822f5f43813213 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:09:28 +0800 Subject: [PATCH 4/5] improve --- deepmd/entrypoints/main.py | 2 +- deepmd/entrypoints/test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index d50f3b9051..5a674fe3d7 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -277,7 +277,7 @@ def main_parser() -> argparse.ArgumentParser: "--datafile", default=None, type=str, - help="The list of systems to test.", + help="The path to file of test list.", ) parser_tst.add_argument( "-S", "--set-prefix", default="set", type=str, help="The set prefix" diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 7583a11f3e..0e4bb8ba76 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -40,7 +40,7 @@ def test( path where model is stored system : str system directory - datafile: str + datafile : str the path to the list of systems to test set_prefix : str string prefix of set @@ -62,7 +62,7 @@ def test( """ if datafile is not None: all_sys = open(datafile, 'r') - all_sys = [i.strip() for i in all_sys.readlines()] + all_sys = all_sys.read().splitlines() datafile.close() else: all_sys = expand_sys_str(system) From f7360a62c2010904956ac62b605d18d49da4268c Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:24:22 +0800 Subject: [PATCH 5/5] fix --- deepmd/entrypoints/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 0e4bb8ba76..a4feaa88f6 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -61,9 +61,9 @@ def test( if no valid system was found """ if datafile is not None: - all_sys = open(datafile, 'r') - all_sys = all_sys.read().splitlines() - datafile.close() + datalist = open(datafile, 'r') + all_sys = datalist.read().splitlines() + datalist.close() else: all_sys = expand_sys_str(system)