-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_singlepoint.py
164 lines (132 loc) · 5.59 KB
/
test_singlepoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"""Tests for singlepoint calculation."""
import subprocess
from ase.build import bulk
import pytest
from aiida.common import InputValidationError, datastructures
from aiida.engine import run
from aiida.orm import Str, StructureData
from aiida.plugins import CalculationFactory
from aiida_mlip.data.config import JanusConfigfile
from aiida_mlip.data.model import ModelData
def test_singlepoint(fixture_sandbox, generate_calc_job, janus_code, model_folder):
"""Test generating singlepoint calculation job"""
entry_point_name = "mlip.sp"
model_file = model_folder / "mace_mp_small.model"
inputs = {
"metadata": {"options": {"resources": {"num_machines": 1}}},
"code": janus_code,
"arch": Str("mace"),
"precision": Str("float64"),
"struct": StructureData(ase=bulk("NaCl", "rocksalt", 5.63)),
"model": ModelData.from_local(model_file, architecture="mace"),
"device": Str("cpu"),
}
calc_info = generate_calc_job(fixture_sandbox, entry_point_name, inputs)
cmdline_params = [
"singlepoint",
"--arch",
"mace",
"--struct",
"aiida.xyz",
"--device",
"cpu",
"--log",
"aiida.log",
"--out",
"aiida-results.xyz",
"--calc-kwargs",
"{'default_dtype': 'float64', 'model': 'mlff.model'}",
]
retrieve_list = [
calc_info.uuid,
"aiida.log",
"aiida-results.xyz",
"aiida-stdout.txt",
]
# Check the attributes of the returned `CalcInfo`
assert sorted(fixture_sandbox.get_content_list()) == sorted(
["aiida.xyz", "mlff.model"]
)
assert isinstance(calc_info, datastructures.CalcInfo)
assert isinstance(calc_info.codes_info[0], datastructures.CodeInfo)
assert sorted(calc_info.codes_info[0].cmdline_params) == sorted(cmdline_params)
assert sorted(calc_info.retrieve_list) == sorted(retrieve_list)
def test_sp_nostruct(fixture_sandbox, generate_calc_job, model_folder, janus_code):
"""Test singlepoint calculation with error input"""
entry_point_name = "mlip.sp"
model_file = model_folder / "mace_mp_small.model"
# pylint:disable=line-too-long
inputs = {
"metadata": {"options": {"resources": {"num_machines": 1}}},
"code": janus_code,
"arch": Str("mace"),
"precision": Str("float64"),
"model": ModelData.from_local(model_file, architecture="mace"),
"device": Str("cpu"),
}
with pytest.raises(InputValidationError):
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
def test_sp_nomodel(fixture_sandbox, generate_calc_job, config_folder, janus_code):
"""Test singlepoint calculation with missing model"""
entry_point_name = "mlip.sp"
inputs = {
"code": janus_code,
"metadata": {"options": {"resources": {"num_machines": 1}}},
"config": JanusConfigfile(config_folder / "config_nomodel.yml"),
"struct": StructureData(ase=bulk("NaCl", "rocksalt", 5.63)),
}
with pytest.raises(InputValidationError):
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
def test_sp_noarch(fixture_sandbox, generate_calc_job, config_folder, janus_code):
"""Test singlepoint calculation with missing architecture"""
entry_point_name = "mlip.sp"
inputs = {
"code": janus_code,
"metadata": {"options": {"resources": {"num_machines": 1}}},
"config": JanusConfigfile(config_folder / "config_noarch.yml"),
"struct": StructureData(ase=bulk("NaCl", "rocksalt", 5.63)),
}
with pytest.raises(InputValidationError):
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
def test_two_arch(fixture_sandbox, generate_calc_job, model_folder, janus_code):
"""Test singlepoint calculation with two defined architectures"""
entry_point_name = "mlip.sp"
model_file = model_folder / "mace_mp_small.model"
inputs = {
"code": janus_code,
"metadata": {"options": {"resources": {"num_machines": 1}}},
"model": ModelData.from_local(model_file, architecture="mace_mp"),
"arch": Str("chgnet"),
"struct": StructureData(ase=bulk("NaCl", "rocksalt", 5.63)),
}
with pytest.raises(InputValidationError):
generate_calc_job(fixture_sandbox, entry_point_name, inputs)
def test_run_sp(model_folder, janus_code):
"""Test running singlepoint calculation"""
model_file = model_folder / "mace_mp_small.model"
inputs = {
"metadata": {"options": {"resources": {"num_machines": 1}}},
"code": janus_code,
"arch": Str("mace"),
"precision": Str("float64"),
"struct": StructureData(ase=bulk("NaCl", "rocksalt", 5.63)),
"model": ModelData.from_local(model_file, architecture="mace"),
"device": Str("cpu"),
}
singlePointCalculation = CalculationFactory("mlip.sp")
result = run(singlePointCalculation, **inputs)
assert "results_dict" in result
obtained_res = result["results_dict"].get_dict()
assert "xyz_output" in result
assert obtained_res["info"]["mace_energy"] == pytest.approx(-6.7575203839729)
assert obtained_res["info"]["mace_stress"][0] == pytest.approx(-0.005816546985101)
def test_example(example_path):
"""
Test function to run md calculation through the use of the example file provided.
"""
example_file_path = example_path / "submit_singlepoint.py"
command = ["verdi", "run", example_file_path, "janus@localhost"]
# Execute the command
result = subprocess.run(command, capture_output=True, text=True, check=False)
assert result.stderr == ""
assert result.returncode == 0