Skip to content

Commit 721f786

Browse files
Update example submission script (#227)
1 parent 5376f86 commit 721f786

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

docs/source/user_guide/calculations.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ They will be converted to AiiDA data types by the script itself.
123123
124124
verdi run submit_singlepoint.py "janus@localhost" --structure "path/to/structure" --model "path/to/model" --device "cpu"
125125
126-
The ``submit_using_config.py`` script can be used to facilitate submission using a config file.
126+
The ``submit_using_config.py`` script provides an example of submission using a config file.
127+
128+
.. note::
129+
130+
The structure and model are hard-coded into ``submit_using_config.py`` to avoid
131+
issues with relative paths. These should be modified, or removed and set through
132+
the configuration file, for your structure and model of interest.
133+
127134

128135
Geometry Optimisation calculation
129136
---------------------------------

examples/calculations/submit_using_config.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,45 @@
22

33
from __future__ import annotations
44

5+
from pathlib import Path
6+
57
from aiida.engine import run_get_node
68
from aiida.orm import load_code
79
from aiida.plugins import CalculationFactory
810

11+
import aiida_mlip
912
from aiida_mlip.data.config import JanusConfigfile
10-
from aiida_mlip.helpers.help_load import load_structure
13+
from aiida_mlip.helpers.help_load import load_model, load_structure
14+
15+
# __file__ changes depending on where verdi run is called
16+
DATA_PATH = Path(aiida_mlip.__file__).parent.parent / "tests" / "calculations"
1117

1218
# Add the required inputs for aiida
1319
metadata = {"options": {"resources": {"num_machines": 1}}}
1420
code = load_code("janus@localhost")
1521

1622
# This structure will overwrite the one in the config file if present
17-
structure = load_structure("../tests/calculations/structures/NaCl.cif")
23+
structure = load_structure(DATA_PATH / "structures" / "NaCl.cif")
24+
25+
# This model will overwrite the one in the config file if present
26+
model = load_model(
27+
model="https://github.com/stfc/janus-core/raw/main/tests/models/mace_mp_small.model",
28+
architecture="mace_mp",
29+
)
1830

1931
# All the other paramenters we want them from the config file
2032
# We want to pass it as a AiiDA data type for the provenance
21-
config = JanusConfigfile("../tests/calculations/configs/config_janus.yaml")
33+
config = JanusConfigfile(DATA_PATH / "configs" / "config_janus.yml")
2234

2335
# Define calculation to run
24-
SinglepointCalc = CalculationFactory("mlip.sp")
36+
SinglePointCalc = CalculationFactory("mlip.sp")
2537

2638
# Run calculation
2739
result, node = run_get_node(
28-
SinglepointCalc,
40+
SinglePointCalc,
2941
code=code,
3042
struct=structure,
43+
model=model,
3144
metadata=metadata,
3245
config=config,
3346
)

tests/calculations/test_singlepoint.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,22 @@ def test_output_files(fixture_sandbox, generate_calc_job, janus_code, model_fold
278278
assert isinstance(calc_info.codes_info[0], datastructures.CodeInfo)
279279
assert sorted(calc_info.codes_info[0].cmdline_params) == sorted(cmdline_params)
280280
assert sorted(calc_info.retrieve_list) == sorted(retrieve_list)
281+
282+
283+
def test_submit_config_example(example_path, janus_code):
284+
"""Test running calculation using the example submit with config file."""
285+
example_file_path = example_path / "submit_using_config.py"
286+
command = [
287+
"verdi",
288+
"run",
289+
example_file_path,
290+
f"{janus_code.label}@{janus_code.computer.label}",
291+
]
292+
293+
# Execute the command
294+
result = subprocess.run(command, capture_output=True, text=True, check=False)
295+
assert result.stderr == ""
296+
assert result.returncode == 0
297+
assert "results from calculation:" in result.stdout
298+
assert "'results_dict': <Dict: uuid:" in result.stdout
299+
assert "'xyz_output': <SinglefileData: uuid:" in result.stdout

0 commit comments

Comments
 (0)