Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a status-markers modifier #690

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions var/ramble/repos/builtin/modifiers/status-markers/modifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import os
import llnl.util.filesystem as fs

from ramble.modkit import *


class StatusMarkers(BasicModifier):
"""Modifier to create a marker file when the experiment has started and
ended.

This modifier will create a .started and .finished file within the
experiment run dir.
"""

name = "status-markers"

tags("status", "info")

_started_marker = ".started"
_finished_marker = ".finished"

maintainers("douglasjacobsen")

mode("standard", description="Standard execution mode")

register_builtin(
"write_started_marker", required=True, injection_method="prepend"
)

def write_started_marker(self):
cmds = [
'echo "Started" &> {experiment_run_dir}/' + self._started_marker,
"rm -f {experiment_run_dir}/" + self.finished_marker,
]

return cmds

register_builtin(
"write_finished_marker", required=True, injection_method="append"
)

def write_finished_marker(self):
cmds = [
'echo "Finished" &> {experiment_run_dir}/' + self._finished_marker
]

return cmds

register_phase(
"clean_markers", pipeline="setup", run_after=["make_experiments"]
)

def _clean_markers(self, workspace, app_inst=None):
exp_dir = self.expander.expand_var_name(
app_inst.keywords.experiment_run_dir
)

started_marker = os.path.join(exp_dir, self._started_marker)
finished_marker = os.path.join(exp_dir, self._finished_marker)

for marker in [started_marker, finished_marker]:
if os.path.isfile(marker):
fs.force_remove(marker)