|
| 1 | +import unittest |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +from dpgen.data import reaction, surf |
| 5 | + |
| 6 | + |
| 7 | +class TestInitApiVersionDefaults(unittest.TestCase): |
| 8 | + def test_reaction_stages_default_to_supported_api(self): |
| 9 | + mdata = { |
| 10 | + "reaxff_command": "lmp", |
| 11 | + "reaxff_machine": {}, |
| 12 | + "reaxff_resources": {}, |
| 13 | + "build_command": "build", |
| 14 | + "build_machine": {}, |
| 15 | + "build_resources": {"cpu_per_node": 1}, |
| 16 | + "fp_command": "fp", |
| 17 | + "fp_machine": {}, |
| 18 | + "fp_resources": {"cpu_per_node": 1}, |
| 19 | + "fp_group_size": 1, |
| 20 | + } |
| 21 | + jdata = { |
| 22 | + "type_map": ["H"], |
| 23 | + "cutoff": 3.0, |
| 24 | + "dataset_size": 1, |
| 25 | + "qmkeywords": "force", |
| 26 | + } |
| 27 | + |
| 28 | + with ( |
| 29 | + patch.object(reaction.glob, "glob", return_value=["task.000"]), |
| 30 | + patch.object(reaction, "make_submission_compat") as submit, |
| 31 | + ): |
| 32 | + reaction.run_reaxff(jdata, mdata) |
| 33 | + reaction.run_build_dataset(jdata, mdata) |
| 34 | + reaction.run_fp(jdata, mdata) |
| 35 | + |
| 36 | + self.assertEqual(submit.call_count, 3) |
| 37 | + for call in submit.call_args_list: |
| 38 | + self.assertEqual(call.kwargs["api_version"], "1.0") |
| 39 | + |
| 40 | + def test_surface_relaxation_defaults_to_supported_api(self): |
| 41 | + jdata = {"out_dir": "out"} |
| 42 | + mdata = { |
| 43 | + "fp_command": "vasp", |
| 44 | + "fp_group_size": 1, |
| 45 | + "fp_resources": {}, |
| 46 | + "fp_machine": {}, |
| 47 | + } |
| 48 | + |
| 49 | + with ( |
| 50 | + patch.object( |
| 51 | + surf.glob, |
| 52 | + "glob", |
| 53 | + side_effect=[[], ["out/02.md/sys-0000/scale-1.000/000000"]], |
| 54 | + ), |
| 55 | + patch.object(surf, "_vasp_check_fin", return_value=False), |
| 56 | + patch.object(surf, "make_submission_compat") as submit, |
| 57 | + ): |
| 58 | + surf.run_vasp_relax(jdata, mdata) |
| 59 | + |
| 60 | + self.assertEqual(submit.call_args.kwargs["api_version"], "1.0") |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + unittest.main() |
0 commit comments