Skip to content

Commit befe0e1

Browse files
authored
Merge pull request #815 from douglasjacobsen/fix-relative-log-path
Fix relative log paths in FOM and success criteria definitions
2 parents 418a9a6 + 6821cd3 commit befe0e1

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

lib/ramble/ramble/application.py

+9
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,11 @@ def _analysis_dicts(self, criteria_list):
20622062
# Extract file paths for all criteria
20632063
for criteria in criteria_list.all_criteria():
20642064
log_path = self.expander.expand_var(criteria.file)
2065+
2066+
# Ensure log path is absolute. If not, prepend the experiment run directory
2067+
if not os.path.isabs(log_path) and self.expander.experiment_run_dir not in log_path:
2068+
log_path = os.path.join(self.expander.experiment_run_dir, log_path)
2069+
20652070
if log_path not in files and os.path.exists(log_path):
20662071
files[log_path] = self._new_file_dict()
20672072

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

2102+
# Ensure log path is absolute. If not, prepend the experiment run directory
2103+
if not os.path.isabs(log_path) and self.expander.experiment_run_dir not in log_path:
2104+
log_path = os.path.join(self.expander.experiment_run_dir, log_path)
2105+
20972106
if log_path not in files:
20982107
files[log_path] = self._new_file_dict()
20992108

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2022-2025 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+
11+
import pytest
12+
13+
import ramble.workspace
14+
import ramble.config
15+
import ramble.software_environments
16+
from ramble.main import RambleCommand
17+
18+
19+
# everything here uses the mock_workspace_path
20+
pytestmark = pytest.mark.usefixtures(
21+
"mutable_config", "mutable_mock_workspace_path", "mock_applications"
22+
)
23+
24+
on = RambleCommand("on")
25+
workspace = RambleCommand("workspace")
26+
27+
28+
def test_relative_fom_log_works(mutable_config, mutable_mock_workspace_path, request):
29+
workspace_name = request.node.name
30+
31+
global_args = ["-w", workspace_name]
32+
33+
ws = ramble.workspace.create(workspace_name)
34+
workspace(
35+
"manage",
36+
"experiments",
37+
"fom-log-path",
38+
"-v",
39+
"n_nodes=1",
40+
"-v",
41+
"n_ranks=1",
42+
"-v",
43+
"batch_submit={execute_experiment}",
44+
global_args=global_args,
45+
)
46+
ws._re_read()
47+
48+
workspace("setup", global_args=global_args)
49+
50+
on(global_args=global_args)
51+
52+
workspace("analyze", global_args=global_args)
53+
54+
with open(os.path.join(ws.root, "results.latest.txt")) as f:
55+
data = f.read()
56+
57+
assert "FAILED" not in data
58+
assert "SUCCESS" in data
59+
assert "test_fom = test" in data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2022-2025 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+
from ramble.appkit import *
10+
11+
12+
class FomLogPath(ExecutableApplication):
13+
name = "fom-log-path"
14+
15+
executable(
16+
"write-fom", "echo 'fom: test'", redirect="log.file", use_mpi=False
17+
)
18+
19+
workload("test", executable="write-fom")
20+
21+
figure_of_merit(
22+
"test_fom",
23+
fom_regex=r"fom: (?P<test>.*)",
24+
group_name="test",
25+
log_file="log.file",
26+
units="",
27+
)
28+
29+
success_criteria(
30+
"found_test",
31+
mode="string",
32+
match=r"fom: test",
33+
file="log.file",
34+
)

0 commit comments

Comments
 (0)