|
| 1 | +# Copyright 2022-2024 The Ramble Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | +# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | +# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | +# option. This file may not be copied, modified, or distributed |
| 7 | +# except according to those terms. |
| 8 | + |
| 9 | +import os |
| 10 | +import llnl.util.filesystem as fs |
| 11 | + |
| 12 | +from ramble.modkit import * |
| 13 | + |
| 14 | + |
| 15 | +class StatusMarkers(BasicModifier): |
| 16 | + """Modifier to create a marker file when the experiment has started and |
| 17 | + ended. |
| 18 | +
|
| 19 | + This modifier will create a .started and .finished file within the |
| 20 | + experiment run dir. |
| 21 | + """ |
| 22 | + |
| 23 | + name = "status-markers" |
| 24 | + |
| 25 | + tags("status", "info") |
| 26 | + |
| 27 | + _started_marker = ".started" |
| 28 | + _finished_marker = ".finished" |
| 29 | + |
| 30 | + maintainers("douglasjacobsen") |
| 31 | + |
| 32 | + mode("standard", description="Standard execution mode") |
| 33 | + |
| 34 | + register_builtin( |
| 35 | + "write_started_marker", required=True, injection_method="prepend" |
| 36 | + ) |
| 37 | + |
| 38 | + def write_started_marker(self): |
| 39 | + cmds = [ |
| 40 | + 'echo "Started" &> {experiment_run_dir}/' + self._started_marker, |
| 41 | + "rm -f {experiment_run_dir}/" + self.finished_marker, |
| 42 | + ] |
| 43 | + |
| 44 | + return cmds |
| 45 | + |
| 46 | + register_builtin( |
| 47 | + "write_finished_marker", required=True, injection_method="append" |
| 48 | + ) |
| 49 | + |
| 50 | + def write_finished_marker(self): |
| 51 | + cmds = [ |
| 52 | + 'echo "Finished" &> {experiment_run_dir}/' + self._finished_marker |
| 53 | + ] |
| 54 | + |
| 55 | + return cmds |
| 56 | + |
| 57 | + register_phase( |
| 58 | + "clean_markers", pipeline="setup", run_after=["make_experiments"] |
| 59 | + ) |
| 60 | + |
| 61 | + def _clean_markers(self, workspace, app_inst=None): |
| 62 | + exp_dir = self.expander.expand_var_name( |
| 63 | + app_inst.keywords.experiment_run_dir |
| 64 | + ) |
| 65 | + |
| 66 | + started_marker = os.path.join(exp_dir, self._started_marker) |
| 67 | + finished_marker = os.path.join(exp_dir, self._finished_marker) |
| 68 | + |
| 69 | + for marker in [started_marker, finished_marker]: |
| 70 | + if os.path.isfile(marker): |
| 71 | + fs.force_remove(marker) |
0 commit comments