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

Fix relative log paths in FOM and success criteria definitions #815

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,11 @@ def _analysis_dicts(self, criteria_list):
# Extract file paths for all criteria
for criteria in criteria_list.all_criteria():
log_path = self.expander.expand_var(criteria.file)

# Ensure log path is absolute. If not, prepend the experiment run directory
if not os.path.isabs(log_path) and self.expander.experiment_run_dir not in log_path:
log_path = os.path.join(self.expander.experiment_run_dir, log_path)

if log_path not in files and os.path.exists(log_path):
files[log_path] = self._new_file_dict()

Expand Down Expand Up @@ -2094,6 +2099,10 @@ def _analysis_dicts(self, criteria_list):
for fom, conf in fom_definitions.items():
log_path = self.expander.expand_var(conf["log_file"])

# Ensure log path is absolute. If not, prepend the experiment run directory
if not os.path.isabs(log_path) and self.expander.experiment_run_dir not in log_path:
log_path = os.path.join(self.expander.experiment_run_dir, log_path)

if log_path not in files:
files[log_path] = self._new_file_dict()

Expand Down
59 changes: 59 additions & 0 deletions lib/ramble/ramble/test/end_to_end/fom_log_file_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022-2025 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 pytest

import ramble.workspace
import ramble.config
import ramble.software_environments
from ramble.main import RambleCommand


# everything here uses the mock_workspace_path
pytestmark = pytest.mark.usefixtures(
"mutable_config", "mutable_mock_workspace_path", "mock_applications"
)

on = RambleCommand("on")
workspace = RambleCommand("workspace")


def test_relative_fom_log_works(mutable_config, mutable_mock_workspace_path, request):
workspace_name = request.node.name

global_args = ["-w", workspace_name]

ws = ramble.workspace.create(workspace_name)
workspace(
"manage",
"experiments",
"fom-log-path",
"-v",
"n_nodes=1",
"-v",
"n_ranks=1",
"-v",
"batch_submit={execute_experiment}",
global_args=global_args,
)
ws._re_read()

workspace("setup", global_args=global_args)

on(global_args=global_args)

workspace("analyze", global_args=global_args)

with open(os.path.join(ws.root, "results.latest.txt")) as f:
data = f.read()

assert "FAILED" not in data
assert "SUCCESS" in data
assert "test_fom = test" in data
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022-2025 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.

from ramble.appkit import *


class FomLogPath(ExecutableApplication):
name = "fom-log-path"

executable(
"write-fom", "echo 'fom: test'", redirect="log.file", use_mpi=False
)

workload("test", executable="write-fom")

figure_of_merit(
"test_fom",
fom_regex=r"fom: (?P<test>.*)",
group_name="test",
log_file="log.file",
units="",
)

success_criteria(
"found_test",
mode="string",
match=r"fom: test",
file="log.file",
)
Loading