diff --git a/deepmd/common.py b/deepmd/common.py index aa76c5dd08..85e6bf74c6 100644 --- a/deepmd/common.py +++ b/deepmd/common.py @@ -40,7 +40,6 @@ __all__ = [ "select_idx_map", "make_default_mesh", - "j_must_have", "j_loader", "expand_sys_str", "get_np_precision", @@ -127,15 +126,20 @@ def make_default_mesh(pbc: bool, mixed_type: bool) -> np.ndarray: return default_mesh -# TODO: rename j_must_have to j_deprecated and only warn about deprecated keys -# maybe rename this to j_deprecated and only warn about deprecated keys, -# if the deprecated_key argument is left empty function puppose is only custom -# error since dict[key] already raises KeyError when the key is missing -def j_must_have( +def j_deprecated( jdata: Dict[str, "_DICT_VAL"], key: str, deprecated_key: List[str] = [] ) -> "_DICT_VAL": """Assert that supplied dictionary conaines specified key. + Parameters + ---------- + jdata : Dict[str, _DICT_VAL] + dictionary to check + key : str + key to check + deprecated_key : List[str], optional + list of deprecated keys, by default [] + Returns ------- _DICT_VAL diff --git a/deepmd/tf/common.py b/deepmd/tf/common.py index f4c6d5b0ce..9244b4f7ee 100644 --- a/deepmd/tf/common.py +++ b/deepmd/tf/common.py @@ -26,7 +26,6 @@ expand_sys_str, get_np_precision, j_loader, - j_must_have, make_default_mesh, select_idx_map, ) @@ -47,7 +46,6 @@ # from deepmd.common "select_idx_map", "make_default_mesh", - "j_must_have", "j_loader", "expand_sys_str", "get_np_precision", diff --git a/deepmd/tf/entrypoints/train.py b/deepmd/tf/entrypoints/train.py index dfe1f3db91..3c4decbe8c 100755 --- a/deepmd/tf/entrypoints/train.py +++ b/deepmd/tf/entrypoints/train.py @@ -15,7 +15,6 @@ from deepmd.tf.common import ( j_loader, - j_must_have, ) from deepmd.tf.env import ( reset_default_tf_session_config, @@ -211,7 +210,7 @@ def _do_work(jdata: Dict[str, Any], run_opt: RunOptions, is_compress: bool = Fal modifier.build_fv_graph() # get training info - stop_batch = j_must_have(jdata["training"], "numb_steps") + stop_batch = jdata["training"]["numb_steps"] origin_type_map = jdata["model"].get("origin_type_map", None) if ( origin_type_map is not None and not origin_type_map diff --git a/deepmd/tf/train/trainer.py b/deepmd/tf/train/trainer.py index dda79afea6..60a468be3e 100644 --- a/deepmd/tf/train/trainer.py +++ b/deepmd/tf/train/trainer.py @@ -29,7 +29,6 @@ ) from deepmd.tf.common import ( get_precision, - j_must_have, ) from deepmd.tf.env import ( GLOBAL_ENER_FLOAT_PRECISION, @@ -91,7 +90,7 @@ def __init__(self, jdata, run_opt, is_compress=False): def _init_param(self, jdata): # model config - model_param = j_must_have(jdata, "model") + model_param = jdata["model"] # nvnmd self.nvnmd_param = jdata.get("nvnmd", {}) @@ -123,7 +122,7 @@ def get_lr_and_coef(lr_param): return lr, scale_lr_coef # learning rate - lr_param = j_must_have(jdata, "learning_rate") + lr_param = jdata["learning_rate"] self.lr, self.scale_lr_coef = get_lr_and_coef(lr_param) # loss # infer loss type by fitting_type diff --git a/deepmd/utils/compat.py b/deepmd/utils/compat.py index 11f5e639dc..edd01b8291 100644 --- a/deepmd/utils/compat.py +++ b/deepmd/utils/compat.py @@ -17,7 +17,7 @@ import numpy as np from deepmd.common import ( - j_must_have, + j_deprecated, ) @@ -127,8 +127,8 @@ def _smth_descriptor(jdata: Dict[str, Any]) -> Dict[str, Any]: descriptor["sel"] = jdata["sel_a"] _jcopy(jdata, descriptor, ("rcut",)) descriptor["rcut_smth"] = jdata.get("rcut_smth", descriptor["rcut"]) - descriptor["neuron"] = j_must_have(jdata, "filter_neuron") - descriptor["axis_neuron"] = j_must_have(jdata, "axis_neuron", ["n_axis_neuron"]) + descriptor["neuron"] = jdata["filter_neuron"] + descriptor["axis_neuron"] = j_deprecated(jdata, "axis_neuron", ["n_axis_neuron"]) descriptor["resnet_dt"] = False if "resnet_dt" in jdata: descriptor["resnet_dt"] = jdata["filter_resnet_dt"] @@ -154,7 +154,7 @@ def _fitting_net(jdata: Dict[str, Any]) -> Dict[str, Any]: seed = jdata.get("seed", None) if seed is not None: fitting_net["seed"] = seed - fitting_net["neuron"] = j_must_have(jdata, "fitting_neuron", ["n_neuron"]) + fitting_net["neuron"] = j_deprecated(jdata, "fitting_neuron", ["n_neuron"]) fitting_net["resnet_dt"] = True if "resnet_dt" in jdata: fitting_net["resnet_dt"] = jdata["resnet_dt"] @@ -237,16 +237,16 @@ def _training(jdata: Dict[str, Any]) -> Dict[str, Any]: training["disp_file"] = "lcurve.out" if "disp_file" in jdata: training["disp_file"] = jdata["disp_file"] - training["disp_freq"] = j_must_have(jdata, "disp_freq") - training["numb_test"] = j_must_have(jdata, "numb_test") - training["save_freq"] = j_must_have(jdata, "save_freq") - training["save_ckpt"] = j_must_have(jdata, "save_ckpt") - training["disp_training"] = j_must_have(jdata, "disp_training") - training["time_training"] = j_must_have(jdata, "time_training") + training["disp_freq"] = jdata["disp_freq"] + training["numb_test"] = jdata["numb_test"] + training["save_freq"] = jdata["save_freq"] + training["save_ckpt"] = jdata["save_ckpt"] + training["disp_training"] = jdata["disp_training"] + training["time_training"] = jdata["time_training"] if "profiling" in jdata: training["profiling"] = jdata["profiling"] if training["profiling"]: - training["profiling_file"] = j_must_have(jdata, "profiling_file") + training["profiling_file"] = jdata["profiling_file"] return training @@ -378,7 +378,7 @@ def is_deepmd_v0_input(jdata): return "model" not in jdata.keys() def is_deepmd_v1_input(jdata): - return "systems" in j_must_have(jdata, "training").keys() + return "systems" in jdata["training"].keys() if is_deepmd_v0_input(jdata): jdata = convert_input_v0_v1(jdata, warning, None) diff --git a/deepmd/utils/data_system.py b/deepmd/utils/data_system.py index b657781d3c..f02398278f 100644 --- a/deepmd/utils/data_system.py +++ b/deepmd/utils/data_system.py @@ -18,7 +18,6 @@ import deepmd.utils.random as dp_random from deepmd.common import ( expand_sys_str, - j_must_have, make_default_mesh, ) from deepmd.env import ( @@ -792,10 +791,10 @@ def get_data( DeepmdDataSystem The data system """ - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] systems = process_systems(systems) - batch_size = j_must_have(jdata, "batch_size") + batch_size = jdata["batch_size"] sys_probs = jdata.get("sys_probs", None) auto_prob = jdata.get("auto_prob", "prob_sys_size") optional_type_map = not multi_task_mode diff --git a/source/tests/tf/test_data_large_batch.py b/source/tests/tf/test_data_large_batch.py index 1232f8b1db..1b19d664dd 100644 --- a/source/tests/tf/test_data_large_batch.py +++ b/source/tests/tf/test_data_large_batch.py @@ -5,9 +5,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeAtten, ) @@ -50,11 +47,11 @@ def test_data_mixed_type(self): jfile = "water_se_atten_mixed_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - type_map = j_must_have(jdata["model"], "type_map") + rcut = jdata["model"]["descriptor"]["rcut"] + type_map = jdata["model"]["type_map"] data = DeepmdDataSystem(systems, batch_size, test_size, rcut, type_map=type_map) data_requirement = { @@ -248,11 +245,11 @@ def test_stripped_data_mixed_type(self): jfile = "water_se_atten_mixed_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - type_map = j_must_have(jdata["model"], "type_map") + rcut = jdata["model"]["descriptor"]["rcut"] + type_map = jdata["model"]["type_map"] data = DeepmdDataSystem(systems, batch_size, test_size, rcut, type_map=type_map) data_requirement = { @@ -446,11 +443,11 @@ def test_compressible_data_mixed_type(self): jfile = "water_se_atten_mixed_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - type_map = j_must_have(jdata["model"], "type_map") + rcut = jdata["model"]["descriptor"]["rcut"] + type_map = jdata["model"]["type_map"] data = DeepmdDataSystem(systems, batch_size, test_size, rcut, type_map=type_map) data_requirement = { diff --git a/source/tests/tf/test_data_modifier.py b/source/tests/tf/test_data_modifier.py index e618b8716d..890de86034 100644 --- a/source/tests/tf/test_data_modifier.py +++ b/source/tests/tf/test_data_modifier.py @@ -3,9 +3,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.env import ( GLOBAL_NP_FLOAT_PRECISION, tf, @@ -61,12 +58,12 @@ def _setUp(self): rcut = model.model.get_rcut() # init data system - systems = j_must_have(jdata["training"], "systems") + systems = jdata["training"]["systems"] # systems[0] = tests_path / systems[0] systems = [tests_path / ii for ii in systems] set_pfx = "set" - batch_size = j_must_have(jdata["training"], "batch_size") - test_size = j_must_have(jdata["training"], "numb_test") + batch_size = jdata["training"]["batch_size"] + test_size = jdata["training"]["numb_test"] data = DeepmdDataSystem( systems, batch_size, test_size, rcut, set_prefix=set_pfx ) diff --git a/source/tests/tf/test_data_modifier_shuffle.py b/source/tests/tf/test_data_modifier_shuffle.py index 97e11685e9..b79f1b5706 100644 --- a/source/tests/tf/test_data_modifier_shuffle.py +++ b/source/tests/tf/test_data_modifier_shuffle.py @@ -4,9 +4,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.env import ( GLOBAL_NP_FLOAT_PRECISION, tf, @@ -64,10 +61,10 @@ def _setUp(self): rcut = model.model.get_rcut() # init data system - systems = j_must_have(jdata["training"], "systems") + systems = jdata["training"]["systems"] set_pfx = "set" - batch_size = j_must_have(jdata["training"], "batch_size") - test_size = j_must_have(jdata["training"], "numb_test") + batch_size = jdata["training"]["batch_size"] + test_size = jdata["training"]["numb_test"] data = DeepmdDataSystem( systems, batch_size, test_size, rcut, set_prefix=set_pfx ) diff --git a/source/tests/tf/test_descrpt_hybrid.py b/source/tests/tf/test_descrpt_hybrid.py index 4023521fca..76c0932316 100644 --- a/source/tests/tf/test_descrpt_hybrid.py +++ b/source/tests/tf/test_descrpt_hybrid.py @@ -4,9 +4,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptHybrid, ) @@ -40,10 +37,8 @@ def test_descriptor_hybrid(self): jfile = "water_hybrid.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 2 test_size = 1 rcut = 6 diff --git a/source/tests/tf/test_descrpt_se_a_mask.py b/source/tests/tf/test_descrpt_se_a_mask.py index 7f2461a6f4..b495072c7d 100644 --- a/source/tests/tf/test_descrpt_se_a_mask.py +++ b/source/tests/tf/test_descrpt_se_a_mask.py @@ -3,9 +3,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeAMask, ) @@ -231,12 +228,12 @@ def test_descriptor_se_a_mask(self): jdata["training"]["validation_data"]["systems"] = [ str(tests_path / "data_dp_mask") ] - systems = j_must_have(jdata["training"]["validation_data"], "systems") + systems = jdata["training"]["validation_data"]["systems"] set_pfx = "set" batch_size = 2 test_size = 1 rcut = 20.0 # For DataSystem interface compatibility, not used in this test. - sel = j_must_have(jdata["model"]["descriptor"], "sel") + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) total_atom_num = np.cumsum(sel)[-1] diff --git a/source/tests/tf/test_descrpt_se_a_type.py b/source/tests/tf/test_descrpt_se_a_type.py index d321183c54..5bc4680d6d 100644 --- a/source/tests/tf/test_descrpt_se_a_type.py +++ b/source/tests/tf/test_descrpt_se_a_type.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -33,15 +30,12 @@ def test_descriptor_two_sides(self): jfile = "water_se_a_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 2 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -197,15 +191,14 @@ def test_descriptor_one_side(self): jfile = "water_se_a_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_descrpt_se_atten.py b/source/tests/tf/test_descrpt_se_atten.py index 610788d32e..84325cadc9 100644 --- a/source/tests/tf/test_descrpt_se_atten.py +++ b/source/tests/tf/test_descrpt_se_atten.py @@ -5,9 +5,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeAtten, ) @@ -42,15 +39,14 @@ def test_descriptor_two_sides(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 2 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(jdata["model"]["type_map"]) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -219,15 +215,14 @@ def test_descriptor_one_side(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(jdata["model"]["type_map"]) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -397,15 +392,14 @@ def test_stripped_type_embedding_descriptor_two_sides(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 2 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(jdata["model"]["type_map"]) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -568,15 +562,14 @@ def test_compressible_descriptor_two_sides(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 2 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(jdata["model"]["type_map"]) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_dipole_se_a.py b/source/tests/tf/test_dipole_se_a.py index 5764861ca3..77e8fc4f0a 100644 --- a/source/tests/tf/test_dipole_se_a.py +++ b/source/tests/tf/test_dipole_se_a.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -38,14 +35,13 @@ def test_model(self): jfile = "polar_se_a.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_dipole_se_a_tebd.py b/source/tests/tf/test_dipole_se_a_tebd.py index 769a715346..66be544e78 100644 --- a/source/tests/tf/test_dipole_se_a_tebd.py +++ b/source/tests/tf/test_dipole_se_a_tebd.py @@ -4,9 +4,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -48,14 +45,13 @@ def test_model(self): jfile = "polar_se_a_tebd.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_fitting_dos.py b/source/tests/tf/test_fitting_dos.py index c414c543fe..e66f0078c6 100644 --- a/source/tests/tf/test_fitting_dos.py +++ b/source/tests/tf/test_fitting_dos.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -33,15 +30,14 @@ def test_fitting(self): jfile = "train_dos.json" jdata = j_loader(jfile) - systems = j_must_have(jdata["training"], "systems") + systems = jdata["training"]["systems"] set_pfx = "set" - batch_size = j_must_have(jdata["training"], "batch_size") - test_size = j_must_have(jdata["training"], "numb_test") + batch_size = jdata["training"]["batch_size"] + test_size = jdata["training"]["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata["training"], "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_fitting_ener_type.py b/source/tests/tf/test_fitting_ener_type.py index 5c3027924b..94ee99c386 100644 --- a/source/tests/tf/test_fitting_ener_type.py +++ b/source/tests/tf/test_fitting_ener_type.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -33,15 +30,14 @@ def test_fitting(self): jfile = "water_se_a_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_dos.py b/source/tests/tf/test_model_dos.py index 6ba1d73a0c..fc6e4fdb2d 100644 --- a/source/tests/tf/test_model_dos.py +++ b/source/tests/tf/test_model_dos.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -40,14 +37,13 @@ def test_model(self): jfile = "train_dos.json" jdata = j_loader(jfile) - systems = j_must_have(jdata["training"], "systems") + systems = jdata["training"]["systems"] set_pfx = "set" - batch_size = j_must_have(jdata["training"], "batch_size") - test_size = j_must_have(jdata["training"], "numb_test") + batch_size = jdata["training"]["batch_size"] + test_size = jdata["training"]["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata["training"], "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_loc_frame.py b/source/tests/tf/test_model_loc_frame.py index 91d38bab52..a043d16677 100644 --- a/source/tests/tf/test_model_loc_frame.py +++ b/source/tests/tf/test_model_loc_frame.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptLocFrame, ) @@ -35,14 +32,14 @@ def setUp(self): def test_model(self): jfile = "water.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + stop_batch = jdata["stop_batch"] + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_pairtab.py b/source/tests/tf/test_model_pairtab.py index 5835d67343..5caeb0a053 100644 --- a/source/tests/tf/test_model_pairtab.py +++ b/source/tests/tf/test_model_pairtab.py @@ -2,9 +2,6 @@ import numpy as np import scipy.spatial.distance -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.env import ( tf, ) @@ -30,7 +27,7 @@ def setUp(self): def test_model(self): jfile = "water.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" batch_size = 1 test_size = 1 @@ -42,7 +39,7 @@ def test_model(self): "rcut": 6, "sel": [6], } - rcut = j_must_have(jdata["model"], "rcut") + rcut = jdata["model"]["rcut"] def pair_pot(r: float): # LJ, as exmaple diff --git a/source/tests/tf/test_model_se_a.py b/source/tests/tf/test_model_se_a.py index 039ead3a09..1d67ef5fab 100644 --- a/source/tests/tf/test_model_se_a.py +++ b/source/tests/tf/test_model_se_a.py @@ -2,9 +2,6 @@ import dpdata import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -59,14 +56,13 @@ def test_model_atom_ener(self): sys.data["forces"] = np.zeros([nframes, natoms, 3]) sys.to_deepmd_npy("system", prec=np.float64) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() @@ -140,14 +136,13 @@ def test_model(self): jfile = "water_se_a.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -289,14 +284,13 @@ def test_model_atom_ener_type_embedding(self): sys.data["forces"] = np.zeros([nframes, natoms, 3]) sys.to_deepmd_npy("system", prec=np.float64) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() diff --git a/source/tests/tf/test_model_se_a_aparam.py b/source/tests/tf/test_model_se_a_aparam.py index 2485d1e674..fcc7dd52d1 100644 --- a/source/tests/tf/test_model_se_a_aparam.py +++ b/source/tests/tf/test_model_se_a_aparam.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -38,14 +35,13 @@ def setUp(self): def test_model(self): jfile = "water_se_a_aparam.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_a_ebd.py b/source/tests/tf/test_model_se_a_ebd.py index 8f91295f26..9f48076de8 100644 --- a/source/tests/tf/test_model_se_a_ebd.py +++ b/source/tests/tf/test_model_se_a_ebd.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor.se_a_ebd import ( DescrptSeAEbd, ) @@ -36,14 +33,14 @@ def test_model(self): jfile = "water_se_a_ebd.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + stop_batch = jdata["stop_batch"] + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_a_ebd_v2.py b/source/tests/tf/test_model_se_a_ebd_v2.py index 6156455402..1aa4fdb92b 100644 --- a/source/tests/tf/test_model_se_a_ebd_v2.py +++ b/source/tests/tf/test_model_se_a_ebd_v2.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor.se_a_ebd_v2 import ( DescrptSeAEbdV2, ) @@ -39,14 +36,13 @@ def test_model(self): jfile = "water_se_a_ebd.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_a_fparam.py b/source/tests/tf/test_model_se_a_fparam.py index efcd3f44c8..7529873e83 100644 --- a/source/tests/tf/test_model_se_a_fparam.py +++ b/source/tests/tf/test_model_se_a_fparam.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -39,14 +36,13 @@ def test_model(self): jfile = "water_se_a_fparam.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_a_srtab.py b/source/tests/tf/test_model_se_a_srtab.py index ae192b09ec..dddd007006 100644 --- a/source/tests/tf/test_model_se_a_srtab.py +++ b/source/tests/tf/test_model_se_a_srtab.py @@ -3,9 +3,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -53,14 +50,13 @@ def test_model(self): jfile = "water_se_a_srtab.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_a_type.py b/source/tests/tf/test_model_se_a_type.py index f92fdaa2a7..b0f5da6b7e 100644 --- a/source/tests/tf/test_model_se_a_type.py +++ b/source/tests/tf/test_model_se_a_type.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -39,14 +36,13 @@ def test_model(self): jfile = "water_se_a_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_atten.py b/source/tests/tf/test_model_se_atten.py index e1143d8c2e..06945fab9c 100644 --- a/source/tests/tf/test_model_se_atten.py +++ b/source/tests/tf/test_model_se_atten.py @@ -5,9 +5,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeAtten, ) @@ -50,14 +47,12 @@ def test_model(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -204,13 +199,11 @@ def test_exclude_types(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] ntypes = 2 data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -277,14 +270,11 @@ def test_compressible_model(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -433,13 +423,12 @@ def test_compressible_exclude_types(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] ntypes = 2 data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -508,14 +497,12 @@ def test_stripped_type_embedding_model(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -667,13 +654,13 @@ def test_stripped_type_embedding_exclude_types(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] ntypes = 2 data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -747,14 +734,11 @@ def test_smoothness_of_stripped_type_embedding_smooth_model(self): jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -896,11 +880,11 @@ def test_smoothness_of_stripped_type_embedding_smooth_model_excluded_types(self) jfile = "water_se_atten.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_r.py b/source/tests/tf/test_model_se_r.py index 90976b9d47..628a59d320 100644 --- a/source/tests/tf/test_model_se_r.py +++ b/source/tests/tf/test_model_se_r.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeR, ) @@ -36,14 +33,14 @@ def test_model(self): jfile = "water_se_r.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + stop_batch = jdata["stop_batch"] + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_se_t.py b/source/tests/tf/test_model_se_t.py index 1948c8b54b..6167e2e224 100644 --- a/source/tests/tf/test_model_se_t.py +++ b/source/tests/tf/test_model_se_t.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeT, ) @@ -36,14 +33,11 @@ def test_model(self): jfile = "water_se_t.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_model_spin.py b/source/tests/tf/test_model_spin.py index 65a866b021..0e9c0678c2 100644 --- a/source/tests/tf/test_model_spin.py +++ b/source/tests/tf/test_model_spin.py @@ -3,9 +3,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -48,18 +45,16 @@ def test_model_spin(self): # set system information set_pfx = "set" - batch_size = j_must_have(jdata["training"]["training_data"], "batch_size") batch_size = 2 - test_size = j_must_have(jdata["training"]["validation_data"], "numb_btch") - stop_batch = j_must_have(jdata["training"], "numb_steps") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + test_size = jdata["training"]["validation_data"]["numb_btch"] + rcut = jdata["model"]["descriptor"]["rcut"] jdata["training"]["training_data"]["systems"] = [ str(tests_path / "model_spin/") ] jdata["training"]["validation_data"]["systems"] = [ str(tests_path / "model_spin/") ] - systems = j_must_have(jdata["training"]["training_data"], "systems") + systems = jdata["training"]["training_data"]["systems"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() diff --git a/source/tests/tf/test_pairwise_dprc.py b/source/tests/tf/test_pairwise_dprc.py index 7a0f28b092..3a5836ce45 100644 --- a/source/tests/tf/test_pairwise_dprc.py +++ b/source/tests/tf/test_pairwise_dprc.py @@ -13,7 +13,6 @@ ) from deepmd.tf.common import ( j_loader, - j_must_have, ) from deepmd.tf.env import ( GLOBAL_ENER_FLOAT_PRECISION, @@ -437,7 +436,7 @@ def test_model_ener(self): idxs = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]) np.save("system/set.000/aparam.npy", idxs) - systems = j_must_have(jdata["training"]["training_data"], "systems") + systems = jdata["training"]["training_data"]["systems"] batch_size = 1 test_size = 1 rcut = model.get_rcut() @@ -625,7 +624,7 @@ def test_nloc(self): idxs = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]) np.save("system/set.000/aparam.npy", idxs) - systems = j_must_have(jdata["training"]["training_data"], "systems") + systems = jdata["training"]["training_data"]["systems"] batch_size = 1 test_size = 1 rcut = model.get_rcut() diff --git a/source/tests/tf/test_polar_se_a.py b/source/tests/tf/test_polar_se_a.py index 63f4bfa589..f71ead0d0f 100644 --- a/source/tests/tf/test_polar_se_a.py +++ b/source/tests/tf/test_polar_se_a.py @@ -5,9 +5,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -45,14 +42,11 @@ def test_model(self): jfile = "polar_se_a.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -229,7 +223,7 @@ def test_data_stat(self): batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DeepmdDataSystem(systems, batch_size, test_size, rcut) data.add( diff --git a/source/tests/tf/test_polar_se_a_tebd.py b/source/tests/tf/test_polar_se_a_tebd.py index f9f4954d74..2abaedd40a 100644 --- a/source/tests/tf/test_polar_se_a_tebd.py +++ b/source/tests/tf/test_polar_se_a_tebd.py @@ -4,9 +4,6 @@ import numpy as np from packaging.version import parse as parse_version -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( DescrptSeA, ) @@ -48,14 +45,12 @@ def test_model(self): jfile = "polar_se_a_tebd.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - stop_batch = j_must_have(jdata, "stop_batch") - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") + rcut = jdata["model"]["descriptor"]["rcut"] data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_type_one_side.py b/source/tests/tf/test_type_one_side.py index e2f992f212..2ab7cc03a7 100644 --- a/source/tests/tf/test_type_one_side.py +++ b/source/tests/tf/test_type_one_side.py @@ -1,9 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.descriptor import ( Descriptor, ) @@ -41,14 +38,14 @@ def test_descriptor_one_side_exclude_types(self): jfile = "water_se_a.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) @@ -148,14 +145,14 @@ def test_se_r_one_side_exclude_types(self): jfile = "water_se_r.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] set_pfx = "set" - batch_size = j_must_have(jdata, "batch_size") - test_size = j_must_have(jdata, "numb_test") + batch_size = jdata["batch_size"] + test_size = jdata["numb_test"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - sel = j_must_have(jdata["model"]["descriptor"], "sel") + rcut = jdata["model"]["descriptor"]["rcut"] + sel = jdata["model"]["descriptor"]["sel"] ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) diff --git a/source/tests/tf/test_virtual_type.py b/source/tests/tf/test_virtual_type.py index a3e87a35ed..40ec2674dd 100644 --- a/source/tests/tf/test_virtual_type.py +++ b/source/tests/tf/test_virtual_type.py @@ -6,9 +6,6 @@ import numpy as np -from deepmd.tf.common import ( - j_must_have, -) from deepmd.tf.infer import ( DeepPot, ) @@ -130,11 +127,11 @@ def test_data_mixed_type(self): jfile = "water_se_atten_mixed_type.json" jdata = j_loader(jfile) - systems = j_must_have(jdata, "systems") + systems = jdata["systems"] batch_size = 1 test_size = 1 - rcut = j_must_have(jdata["model"]["descriptor"], "rcut") - type_map = j_must_have(jdata["model"], "type_map") + rcut = jdata["model"]["descriptor"]["rcut"] + type_map = jdata["model"]["type_map"] data = DeepmdDataSystem(systems, batch_size, test_size, rcut, type_map=type_map) data.get_batch()