MatRiFFlow 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- IMDgroup/__init__.py +82 -0
- matrifflow/__init__.py +39 -0
- matrifflow/common.py +150 -0
- matrifflow/gorun/__init__.py +36 -0
- matrifflow/gorun/adapters/__init__.py +32 -0
- matrifflow/gorun/adapters/_mace_train_masked.py +218 -0
- matrifflow/gorun/adapters/atat_local.py +156 -0
- matrifflow/gorun/adapters/base.py +128 -0
- matrifflow/gorun/adapters/gpu.py +205 -0
- matrifflow/gorun/adapters/mace.py +873 -0
- matrifflow/gorun/adapters/maps_adapter.py +177 -0
- matrifflow/gorun/adapters/vasp.py +386 -0
- matrifflow/gorun/cleanVASP.py +334 -0
- matrifflow/gorun/core/__init__.py +28 -0
- matrifflow/gorun/core/files.py +168 -0
- matrifflow/gorun/core/incar.py +334 -0
- matrifflow/gorun/core/pipeline.py +345 -0
- matrifflow/gorun/data/gorun-config.example.toml +230 -0
- matrifflow/gorun/gorun.py +744 -0
- matrifflow/gorun/gorun_atat_local.py +230 -0
- matrifflow/gorun/gorun_maps.py +42 -0
- matrifflow/gorun/sbatch.py +253 -0
- matrifflow/gorun/slurm.py +226 -0
- matrifflow/gorun/vasp_calculator.py +80 -0
- matrifflow/pymatgen/__init__.py +28 -0
- matrifflow/pymatgen/cli/__init__.py +30 -0
- matrifflow/pymatgen/cli/mrf.py +281 -0
- matrifflow/pymatgen/cli/mrf_analyze.py +392 -0
- matrifflow/pymatgen/cli/mrf_create.py +185 -0
- matrifflow/pymatgen/cli/mrf_derive.py +1609 -0
- matrifflow/pymatgen/cli/mrf_diff.py +419 -0
- matrifflow/pymatgen/cli/mrf_run.py +69 -0
- matrifflow/pymatgen/cli/mrf_status.py +842 -0
- matrifflow/pymatgen/cli/mrf_visualize.py +1808 -0
- matrifflow/pymatgen/core/__init__.py +28 -0
- matrifflow/pymatgen/core/structure.py +870 -0
- matrifflow/pymatgen/diffusion/__init__.py +28 -0
- matrifflow/pymatgen/diffusion/neb.py +832 -0
- matrifflow/pymatgen/io/__init__.py +28 -0
- matrifflow/pymatgen/io/atat.py +131 -0
- matrifflow/pymatgen/io/vasp/__init__.py +30 -0
- matrifflow/pymatgen/io/vasp/diagnostics.py +224 -0
- matrifflow/pymatgen/io/vasp/functionals.yaml +48 -0
- matrifflow/pymatgen/io/vasp/incar_toml.py +250 -0
- matrifflow/pymatgen/io/vasp/inputs.py +228 -0
- matrifflow/pymatgen/io/vasp/outputs.py +803 -0
- matrifflow/pymatgen/io/vasp/sets.py +1092 -0
- matrifflow/pymatgen/io/vasp/vaspdir.py +1514 -0
- matrifflow/pymatgen/transformations/__init__.py +28 -0
- matrifflow/pymatgen/transformations/insert_molecule.py +661 -0
- matrifflow/pymatgen/transformations/symmetry_clone.py +309 -0
- matrifflow/utils/__init__.py +28 -0
- matrifflow/utils/mpl.py +106 -0
- matrifflow-2.0.1.data/scripts/gorun-all-ready.sh +245 -0
- matrifflow-2.0.1.dist-info/METADATA +136 -0
- matrifflow-2.0.1.dist-info/RECORD +60 -0
- matrifflow-2.0.1.dist-info/WHEEL +5 -0
- matrifflow-2.0.1.dist-info/entry_points.txt +8 -0
- matrifflow-2.0.1.dist-info/licenses/LICENSE +9 -0
- matrifflow-2.0.1.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2024-2026 Inverse Materials Design Group
|
|
4
|
+
#
|
|
5
|
+
# Author: Ihor Radchenko <yantar92@posteo.net>
|
|
6
|
+
#
|
|
7
|
+
# This file is a part of MatRiFFlow package
|
|
8
|
+
#
|
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
# in the Software without restriction, including without limitation the rights
|
|
12
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
# furnished to do so, subject to the following conditions:
|
|
15
|
+
#
|
|
16
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
# copies or substantial portions of the Software.
|
|
18
|
+
#
|
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
# SOFTWARE.
|
|
26
|
+
|
|
27
|
+
"""ATAT-local adapter for gorun — run VASP in an ATAT-generated directory."""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
from matrifflow.gorun.adapters.vasp import VaspAdapter
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AtatLocalAdapter:
|
|
37
|
+
"""``gorun atat-local`` backend for processing a single ATAT structure.
|
|
38
|
+
|
|
39
|
+
Called by ``pollmach`` from inside the maps wrapper. Always
|
|
40
|
+
runs locally (``--local``). Generates a Python heredoc that
|
|
41
|
+
derives ATAT inputs, runs VASP relaxation and SCF, and writes
|
|
42
|
+
an ``energy`` file. VASP subprocesses inherit
|
|
43
|
+
``GORUN_SKIP_SETUP=1`` from the maps wrapper.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
name = "atat-local"
|
|
47
|
+
log_file = "atat-local.out"
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self, *,
|
|
51
|
+
kpoints: str,
|
|
52
|
+
frac_tol: float = 0,
|
|
53
|
+
max_strain: float = 0.1,
|
|
54
|
+
skip_relax: bool = False,
|
|
55
|
+
sublattice_cutoff: float | None = None,
|
|
56
|
+
) -> None:
|
|
57
|
+
self.kpoints = kpoints
|
|
58
|
+
self.frac_tol = frac_tol
|
|
59
|
+
self.max_strain = max_strain
|
|
60
|
+
self.skip_relax = skip_relax
|
|
61
|
+
self.sublattice_cutoff = sublattice_cutoff
|
|
62
|
+
|
|
63
|
+
# ------------------------------------------------------------------
|
|
64
|
+
# Environment
|
|
65
|
+
# ------------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
def validate_environment(self) -> None:
|
|
68
|
+
"""No additional checks — pollmach calls gorun, which handles VASP."""
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
# ------------------------------------------------------------------
|
|
72
|
+
# Directory inspection
|
|
73
|
+
# ------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
def is_valid_input(self, path: Path) -> bool:
|
|
76
|
+
"""True when str.out exists."""
|
|
77
|
+
return (path / "str.out").is_file()
|
|
78
|
+
|
|
79
|
+
def is_converged(self, path: Path) -> bool:
|
|
80
|
+
"""True when the energy file exists."""
|
|
81
|
+
return (path / "energy").is_file()
|
|
82
|
+
|
|
83
|
+
def has_previous_output(self, path: Path) -> bool:
|
|
84
|
+
"""True when the ATAT directory or error markers exist."""
|
|
85
|
+
markers = [
|
|
86
|
+
path / "ATAT",
|
|
87
|
+
path / "energy",
|
|
88
|
+
path / "error",
|
|
89
|
+
]
|
|
90
|
+
return any(m.exists() for m in markers)
|
|
91
|
+
|
|
92
|
+
# ------------------------------------------------------------------
|
|
93
|
+
# Preparation
|
|
94
|
+
# ------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
def prepare_inputs(
|
|
97
|
+
self,
|
|
98
|
+
path: Path, *,
|
|
99
|
+
keep: set[str] | None = None,
|
|
100
|
+
force: bool = False,
|
|
101
|
+
**kwargs,
|
|
102
|
+
) -> None:
|
|
103
|
+
"""No preparation — ATAT input is derived inside the run command."""
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
# ------------------------------------------------------------------
|
|
107
|
+
# Script generation
|
|
108
|
+
# ------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
def setup_commands(self, server_config: dict) -> str:
|
|
111
|
+
"""Inherit VASP environment from config.
|
|
112
|
+
|
|
113
|
+
The code executing inside the heredoc calls ``gorun vasp
|
|
114
|
+
--local``, which needs the same module environment. Since
|
|
115
|
+
maps already exported ``GORUN_SKIP_SETUP=1``, this normally
|
|
116
|
+
returns empty (dispatch_run skips it). If run stand-alone
|
|
117
|
+
for testing, the VASP environment is set up.
|
|
118
|
+
"""
|
|
119
|
+
return VaspAdapter().setup_commands(server_config)
|
|
120
|
+
|
|
121
|
+
def generate_run_commands(self, path: Path, server_config: dict | None = None) -> str:
|
|
122
|
+
"""Return a Python heredoc calling ``run_atat_structure``.
|
|
123
|
+
|
|
124
|
+
Produces::
|
|
125
|
+
|
|
126
|
+
python3 <<'PYEOF'
|
|
127
|
+
from matrifflow.gorun.gorun_atat_local import run_atat_structure
|
|
128
|
+
import sys
|
|
129
|
+
sys.exit(run_atat_structure(kpoints=..., frac_tol=...))
|
|
130
|
+
PYEOF
|
|
131
|
+
"""
|
|
132
|
+
sublattice = (
|
|
133
|
+
repr(self.sublattice_cutoff)
|
|
134
|
+
if self.sublattice_cutoff is not None
|
|
135
|
+
else "None"
|
|
136
|
+
)
|
|
137
|
+
return (
|
|
138
|
+
"python3 <<'PYEOF'\n"
|
|
139
|
+
"from matrifflow.gorun.gorun_atat_local import run_atat_structure\n"
|
|
140
|
+
"import sys\n"
|
|
141
|
+
f"sys.exit(run_atat_structure(\n"
|
|
142
|
+
f" kpoints={self.kpoints!r},\n"
|
|
143
|
+
f" frac_tol={self.frac_tol!r},\n"
|
|
144
|
+
f" max_strain={self.max_strain!r},\n"
|
|
145
|
+
f" skip_relax={self.skip_relax!r},\n"
|
|
146
|
+
f" sublattice_cutoff={sublattice},\n"
|
|
147
|
+
"))\n"
|
|
148
|
+
"PYEOF"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# ------------------------------------------------------------------
|
|
152
|
+
# Backup excludes
|
|
153
|
+
# ------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
def backup_excludes(self) -> list[str]:
|
|
156
|
+
return ["WAVECAR"]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2024-2026 Inverse Materials Design Group
|
|
4
|
+
#
|
|
5
|
+
# Author: Ihor Radchenko <yantar92@posteo.net>
|
|
6
|
+
#
|
|
7
|
+
# This file is a part of MatRiFFlow package
|
|
8
|
+
#
|
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
# in the Software without restriction, including without limitation the rights
|
|
12
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
# furnished to do so, subject to the following conditions:
|
|
15
|
+
#
|
|
16
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
# copies or substantial portions of the Software.
|
|
18
|
+
#
|
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
# SOFTWARE.
|
|
26
|
+
|
|
27
|
+
"""Protocol that every software backend must implement for gorun."""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from typing import Protocol
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SoftwareAdapter(Protocol):
|
|
36
|
+
"""Interface for a computational backend supported by gorun.
|
|
37
|
+
|
|
38
|
+
Each backend (VASP, MACE, etc.) provides an implementation of
|
|
39
|
+
this protocol. The gorun dispatch pipeline calls methods in the
|
|
40
|
+
order defined by `dispatch_run`.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
# -- identity --
|
|
44
|
+
name: str
|
|
45
|
+
"""Unique short name, e.g. ``"vasp"``, ``"mace"``.
|
|
46
|
+
|
|
47
|
+
Used for subcommand dispatch and config namespace lookup."""
|
|
48
|
+
|
|
49
|
+
# -- environment --
|
|
50
|
+
def validate_environment(self) -> None:
|
|
51
|
+
"""Check that everything needed to run is available.
|
|
52
|
+
|
|
53
|
+
Raise an exception if required environment variables, files,
|
|
54
|
+
or commands are missing. Called before any other method.
|
|
55
|
+
"""
|
|
56
|
+
...
|
|
57
|
+
|
|
58
|
+
# -- directory inspection --
|
|
59
|
+
def is_valid_input(self, path: Path) -> bool:
|
|
60
|
+
"""Return True when *path* contains the input files needed to start."""
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def is_converged(self, path: Path) -> bool:
|
|
64
|
+
"""Return True when the computation in *path* has finished successfully."""
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
def has_previous_output(self, path: Path) -> bool:
|
|
68
|
+
"""Return True when *path* contains output from a previous run.
|
|
69
|
+
|
|
70
|
+
Controls whether the pipeline creates a backup before
|
|
71
|
+
re-running.
|
|
72
|
+
"""
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
# -- preparation --
|
|
76
|
+
def prepare_inputs(
|
|
77
|
+
self,
|
|
78
|
+
path: Path, *,
|
|
79
|
+
keep: set[str] | None = None,
|
|
80
|
+
force: bool = False,
|
|
81
|
+
**kwargs,
|
|
82
|
+
) -> None:
|
|
83
|
+
"""Make *path* ready to run.
|
|
84
|
+
|
|
85
|
+
Called after backup. The adapter should:
|
|
86
|
+
- clean or regenerate input files;
|
|
87
|
+
- generate files missing from the directory;
|
|
88
|
+
- skip files listed in *keep* if they already exist.
|
|
89
|
+
|
|
90
|
+
*force* propagates the ``--force`` flag from the CLI.
|
|
91
|
+
*kwargs* carry adapter-specific flags.
|
|
92
|
+
"""
|
|
93
|
+
...
|
|
94
|
+
|
|
95
|
+
# -- script generation --
|
|
96
|
+
def setup_commands(self, server_config: dict) -> str:
|
|
97
|
+
"""Return shell commands to configure the environment.
|
|
98
|
+
|
|
99
|
+
*server_config* is the full server section from the TOML
|
|
100
|
+
config (e.g. ``config["lumi"]``). The adapter extracts its
|
|
101
|
+
own subsection using ``self.name``, falling back to flat keys
|
|
102
|
+
for backward compatibility.
|
|
103
|
+
"""
|
|
104
|
+
...
|
|
105
|
+
|
|
106
|
+
def generate_run_commands(self, path: Path, server_config: dict) -> str:
|
|
107
|
+
"""Return the bash body that executes the computation.
|
|
108
|
+
|
|
109
|
+
*server_config* is the full server section from the TOML
|
|
110
|
+
config (e.g. ``config["lumi"]``), the same dict passed to
|
|
111
|
+
``setup_commands``. Adapters that need a launcher prefix
|
|
112
|
+
(e.g. ``mpiexec``/``srun`` for VASP) read it from here.
|
|
113
|
+
|
|
114
|
+
The pipeline wraps this inside RUNNING-file management and
|
|
115
|
+
(for Slurm) sbatch headers.
|
|
116
|
+
"""
|
|
117
|
+
...
|
|
118
|
+
|
|
119
|
+
# -- backup & cleanup --
|
|
120
|
+
def backup_excludes(self) -> list[str]:
|
|
121
|
+
"""Return rsync ``--exclude`` patterns for the backup step.
|
|
122
|
+
|
|
123
|
+
Adapter-specific patterns only. The pipeline unconditionally
|
|
124
|
+
excludes ``gorun_*`` (previous backups) on top of these.
|
|
125
|
+
|
|
126
|
+
Return patterns like ``["WAVECAR"]`` or ``["__*"]``.
|
|
127
|
+
"""
|
|
128
|
+
...
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2024-2026 Inverse Materials Design Group
|
|
4
|
+
#
|
|
5
|
+
# Author: Ihor Radchenko <yantar92@posteo.net>
|
|
6
|
+
#
|
|
7
|
+
# This file is a part of MatRiFFlow package
|
|
8
|
+
#
|
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
# in the Software without restriction, including without limitation the rights
|
|
12
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
# furnished to do so, subject to the following conditions:
|
|
15
|
+
#
|
|
16
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
# copies or substantial portions of the Software.
|
|
18
|
+
#
|
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
# SOFTWARE.
|
|
26
|
+
|
|
27
|
+
"""Generic GPU adapter for gorun.
|
|
28
|
+
|
|
29
|
+
Provides ``GpuAdapter``, a base class for GPU-accelerated backends
|
|
30
|
+
that only require a ``RUNFILE.sh`` or ``RUNFILE.py`` in the working
|
|
31
|
+
directory. Derived adapters (e.g. MACE) can override
|
|
32
|
+
``generate_run_commands`` to add canned fallback stages after the
|
|
33
|
+
RUNFILE check.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ---------------------------------------------------------------------------
|
|
42
|
+
# Wrapper helper
|
|
43
|
+
# ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
def _wrap_command(command: str) -> str:
|
|
46
|
+
"""Wrap *command* in a heredoc passed to ``GORUN_WRAPPER``.
|
|
47
|
+
|
|
48
|
+
``${GORUN_WRAPPER:-bash}`` ensures the heredoc is always piped to
|
|
49
|
+
a shell: the configured wrapper when ``GORUN_WRAPPER`` is set, or
|
|
50
|
+
plain ``bash`` otherwise. This avoids duplicating *command* in
|
|
51
|
+
an ``if/else`` branch.
|
|
52
|
+
|
|
53
|
+
The heredoc is quoted (``<<'EOF'``) so the outer shell does not
|
|
54
|
+
expand ``${GORUN_INNER_SETUP}`` before passing it through; the
|
|
55
|
+
inner shell expands it. Both variables are expected to be exported
|
|
56
|
+
by the config's ``setup`` commands.
|
|
57
|
+
"""
|
|
58
|
+
return (
|
|
59
|
+
"${GORUN_WRAPPER:-bash} <<'EOF'\n"
|
|
60
|
+
"${GORUN_INNER_SETUP:-}\n"
|
|
61
|
+
f"{command}\n"
|
|
62
|
+
"EOF"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
# GpuAdapter
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class GpuAdapter:
|
|
72
|
+
"""Generic GPU backend for gorun.
|
|
73
|
+
|
|
74
|
+
Requires only a ``RUNFILE.sh`` or ``RUNFILE.py`` in the working
|
|
75
|
+
directory to define the computation. GPU environment setup is
|
|
76
|
+
read from the server config under ``[<name>]`` → ``setup``.
|
|
77
|
+
|
|
78
|
+
Derived classes override ``name``, ``DEFAULTS``, ``REQUIRED``,
|
|
79
|
+
``validate_environment``, ``is_valid_input``, ``is_converged``,
|
|
80
|
+
``has_previous_output``, and ``prepare_inputs`` for their
|
|
81
|
+
specific needs. ``generate_run_commands`` can be overridden to
|
|
82
|
+
add canned fallback stages after the RUNFILE check (see
|
|
83
|
+
``MaceMultiheadFinetuneAdapter`` for an example).
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
name = "gpu"
|
|
87
|
+
|
|
88
|
+
def __init__(self, *, script_name: str | None = None) -> None:
|
|
89
|
+
"""*script_name* overrides the default RUNFILE.sh/py lookup.
|
|
90
|
+
|
|
91
|
+
When set, ``generate_run_commands`` looks for *script_name*
|
|
92
|
+
instead of RUNFILE.sh / RUNFILE.py. The runner is inferred
|
|
93
|
+
from the extension: ``.py`` → ``python -u``, anything else
|
|
94
|
+
(including ``.sh`` or no extension) → ``bash``.
|
|
95
|
+
"""
|
|
96
|
+
self._script_name = script_name
|
|
97
|
+
|
|
98
|
+
#: Hardcoded defaults for shared GPU parameters.
|
|
99
|
+
DEFAULTS: dict[str, object] = {
|
|
100
|
+
"device": "cuda",
|
|
101
|
+
"default_dtype": "float64",
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#: Parameters that must be non-empty for a valid run.
|
|
105
|
+
REQUIRED: frozenset[str] = frozenset()
|
|
106
|
+
|
|
107
|
+
# ------------------------------------------------------------------
|
|
108
|
+
# Environment
|
|
109
|
+
# ------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
def validate_environment(self) -> None:
|
|
112
|
+
"""No default checks. Override in derived classes."""
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
def setup_commands(self, server_config: dict) -> str:
|
|
116
|
+
"""Read GPU environment setup from the server config.
|
|
117
|
+
|
|
118
|
+
Looks for ``server_config[self.name]["setup"]`` — a raw shell
|
|
119
|
+
string that typically exports ``GORUN_WRAPPER`` and
|
|
120
|
+
``GORUN_INNER_SETUP``, along with PyTorch flags, cache
|
|
121
|
+
directories, ``OMP_NUM_THREADS``, etc.
|
|
122
|
+
"""
|
|
123
|
+
return server_config.get(self.name, {}).get("setup", "")
|
|
124
|
+
|
|
125
|
+
# ------------------------------------------------------------------
|
|
126
|
+
# Directory inspection
|
|
127
|
+
# ------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
def is_valid_input(self, path: Path) -> bool:
|
|
130
|
+
"""True when the configured script or RUNFILE.sh/py exists."""
|
|
131
|
+
if self._script_name:
|
|
132
|
+
return (path / self._script_name).is_file()
|
|
133
|
+
return (path / "RUNFILE.sh").is_file() or (path / "RUNFILE.py").is_file()
|
|
134
|
+
|
|
135
|
+
def is_converged(self, path: Path) -> bool:
|
|
136
|
+
"""Must be overridden. Returns ``False`` by default."""
|
|
137
|
+
return False
|
|
138
|
+
|
|
139
|
+
def has_previous_output(self, path: Path) -> bool:
|
|
140
|
+
"""Must be overridden. Returns ``False`` by default."""
|
|
141
|
+
return False
|
|
142
|
+
|
|
143
|
+
# ------------------------------------------------------------------
|
|
144
|
+
# Preparation
|
|
145
|
+
# ------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
def prepare_inputs(
|
|
148
|
+
self,
|
|
149
|
+
path: Path, *,
|
|
150
|
+
keep: set[str] | None = None,
|
|
151
|
+
force: bool = False,
|
|
152
|
+
**kwargs,
|
|
153
|
+
) -> None:
|
|
154
|
+
"""No default preparation. Override in derived classes."""
|
|
155
|
+
pass
|
|
156
|
+
|
|
157
|
+
# ------------------------------------------------------------------
|
|
158
|
+
# Script generation
|
|
159
|
+
# ------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
def generate_run_commands(self, path: Path, server_config: dict | None = None) -> str:
|
|
162
|
+
"""Return the RUNFILE command, or raise if none is found.
|
|
163
|
+
|
|
164
|
+
When ``_script_name`` is set on the instance, that file is used
|
|
165
|
+
instead of RUNFILE.sh / RUNFILE.py. ``.py`` files are run with
|
|
166
|
+
``python -u``; everything else with ``bash``.
|
|
167
|
+
|
|
168
|
+
All commands are wrapped through ``_wrap_command`` for
|
|
169
|
+
``GORUN_WRAPPER`` / ``GORUN_INNER_SETUP`` support.
|
|
170
|
+
|
|
171
|
+
Raises ``FileNotFoundError`` when no script is found.
|
|
172
|
+
"""
|
|
173
|
+
if self._script_name:
|
|
174
|
+
script = path / self._script_name
|
|
175
|
+
if not script.is_file():
|
|
176
|
+
raise FileNotFoundError(
|
|
177
|
+
f"{self._script_name} not found in {path}."
|
|
178
|
+
)
|
|
179
|
+
runner = (
|
|
180
|
+
"python -u"
|
|
181
|
+
if self._script_name.endswith(".py")
|
|
182
|
+
else "bash"
|
|
183
|
+
)
|
|
184
|
+
return _wrap_command(f"{runner} {script}")
|
|
185
|
+
|
|
186
|
+
runfile_sh = path / "RUNFILE.sh"
|
|
187
|
+
runfile_py = path / "RUNFILE.py"
|
|
188
|
+
|
|
189
|
+
if runfile_sh.is_file():
|
|
190
|
+
return _wrap_command(f"bash {runfile_sh}")
|
|
191
|
+
|
|
192
|
+
if runfile_py.is_file():
|
|
193
|
+
return _wrap_command(f"python -u {runfile_py}")
|
|
194
|
+
|
|
195
|
+
raise FileNotFoundError(
|
|
196
|
+
"No RUNFILE.sh or RUNFILE.py found in the working directory. "
|
|
197
|
+
"Place one to define the computation."
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# ------------------------------------------------------------------
|
|
201
|
+
# Backup excludes
|
|
202
|
+
# ------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
def backup_excludes(self) -> list[str]:
|
|
205
|
+
return []
|