• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stfc / aiida-mlip / 9096383187

15 May 2024 01:15PM UTC coverage: 77.778% (-15.7%) from 93.432%
9096383187

Pull #123

github

web-flow
Merge f5bfba8f9 into 18695f779
Pull Request #123: 121 add training

0 of 95 new or added lines in 2 files covered. (0.0%)

441 of 567 relevant lines covered (77.78%)

3.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/aiida_mlip/parsers/train_parser.py
1
"""
2
Parser for mlip train.
3
"""
4

NEW
5
from pathlib import Path
×
6

NEW
7
from ase.io import read
×
8

NEW
9
from aiida.engine import ExitCode
×
NEW
10
from aiida.orm import Dict, FolderData
×
NEW
11
from aiida.orm.nodes.process.process import ProcessNode
×
NEW
12
from aiida.parsers.parser import Parser
×
13

NEW
14
from aiida_mlip.data.model import ModelData
×
NEW
15
from aiida_mlip.helpers.converters import convert_numpy
×
16

17

NEW
18
class TrainParser(Parser):
×
19
    """
20
    Parser class for parsing output of calculation.
21

22
    Parameters
23
    ----------
24
    node : aiida.orm.nodes.process.process.ProcessNode
25
        ProcessNode of calculation.
26

27
    Methods
28
    -------
29
    __init__(node: aiida.orm.nodes.process.process.ProcessNode)
30
        Initialize the SPParser instance.
31

32
    parse(**kwargs: Any) -> int:
33
        Parse outputs, store results in the database.
34

35
    Returns
36
    -------
37
    int
38
        An exit code.
39

40
    Raises
41
    ------
42
    exceptions.ParsingError
43
        If the ProcessNode being passed was not produced by a singlePointCalculation.
44
    """
45

NEW
46
    def __init__(self, node: ProcessNode):
×
47
        """
48
        Check that the ProcessNode being passed was produced by a `Singlepoint`.
49

50
        Parameters
51
        ----------
52
        node : aiida.orm.nodes.process.process.ProcessNode
53
            ProcessNode of calculation.
54
        """
NEW
55
        super().__init__(node)
×
56

57
    # disable for now
58
    # pylint: disable=too-many-locals
NEW
59
    def parse(self, **kwargs) -> int:
×
60
        """
61
        Parse outputs, store results in the database.
62

63
        Parameters
64
        ----------
65
        **kwargs : Any
66
            Any keyword arguments.
67

68
        Returns
69
        -------
70
        int
71
            An exit code.
72
        """
NEW
73
        remote_dir = Path(self.node.get_remote_workdir())
×
NEW
74
        mlip_dict = self.node.get_option("mlip_config").as_dictionary()
×
NEW
75
        remote_dirs = {typ: remote_dir / mlip_dict.get(f"{typ}_dir", default)
×
76
                       for typ, default in (("log", "logs"), 
77
                                            ("checkpoint", "checkpoints"),
78
                                            ("results", "results"),
79
                                            ("model", ""))}
80

NEW
81
        output_filename = self.node.get_option("output_filename")
×
NEW
82
        model_output = model_dir / f"{mlip_dict['name']}.model"
×
NEW
83
        compiled_model_output = model_dir / f"{mlip_dict['name']}_compiled.model"
×
NEW
84
        result_name = results_dir / f"{mlip_dict['name']}_run-2024.txt"
×
85

86
        # Check that folder content is as expected
NEW
87
        files_retrieved = self.retrieved.list_object_names()
×
88

NEW
89
        files_expected = {output_filename}
×
NEW
90
        if not files_expected.issubset(files_retrieved):
×
NEW
91
            self.logger.error(
×
92
                f"Found files '{files_retrieved}', expected to find '{files_expected}'"
93
            )
NEW
94
            return self.exit_codes.ERROR_MISSING_OUTPUT_FILES
×
95

96
        # Need to change the architecture
NEW
97
        architecture = "mace_mp"
×
NEW
98
        model = ModelData.local_file(model_output, architecture=architecture)
×
NEW
99
        compiled_model = ModelData.local_file(
×
100
            compiled_model_output, architecture=architecture
101
        )
NEW
102
        self.out("model", model)
×
NEW
103
        self.out("compiled_model", compiled_model)
×
104

NEW
105
        content = read(result_name)
×
NEW
106
        results = convert_numpy(content.todict())
×
NEW
107
        results_node = Dict(results)
×
NEW
108
        self.out("results_dict", results_node)
×
109

NEW
110
        log_node = FolderData(log_dir)
×
NEW
111
        self.out("logs", log_node)
×
112

NEW
113
        checkpoint_node = FolderData(checkpoint_dir)
×
NEW
114
        self.out("checkpoints", checkpoint_node)
×
115

NEW
116
        return ExitCode(0)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc