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

bugfix replace-output-directory #37

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion a3fe/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1"
__version__ = "0.3.2"
9 changes: 5 additions & 4 deletions a3fe/run/leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ def setup(
relative_simulation_cost=self.relative_simulation_cost,
ensemble_size=self.ensemble_size,
lambda_values=cfg.lambda_values[self.leg_type][stage_type],
base_dir=self.stage_input_dirs[stage_type].replace("/input", ""),
base_dir=self.stage_input_dirs[stage_type].rsplit("/input", 1)[0],
input_dir=self.stage_input_dirs[stage_type],
output_dir=self.stage_input_dirs[stage_type].replace(
"input", "output"
),
output_dir="/".join(
self.stage_input_dirs[stage_type].split("/")[:-1]
)
+ "/output",
stream_log_level=self.stream_log_level,
)
)
Expand Down
44 changes: 44 additions & 0 deletions a3fe/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import BioSimSpace.Sandpit.Exscientia as BSS
import numpy as np
import pytest
import shutil

import a3fe as a3
from a3fe.analyse.detect_equil import dummy_check_equil_multiwindow
Expand Down Expand Up @@ -348,6 +349,38 @@ def setup_calc(mock_run_process):
setup_calc.setup(bound_leg_sysprep_config=cfg, free_leg_sysprep_config=cfg)
yield setup_calc

@pytest.fixture
def setup_calc_with_input_path(self, setup_calc):
"""Based on the setup_calc fixture,
create a new calculation with a temporary directory containing "input"."""
temp_parent_dir = "input_temp_a3fe"
os.makedirs(temp_parent_dir, exist_ok=True)

with TemporaryDirectory(prefix="temp_input_", dir=temp_parent_dir) as dirname:
# Copy the example input directory to the temporary directory
subprocess.run(
[
"cp",
"-r",
"a3fe/data/example_run_dir/input",
f"{dirname}/input",
]
)

calc = a3.Calculation(
base_dir=dirname,
input_dir=f"{dirname}/input",
ensemble_size=1,
stream_log_level=logging.CRITICAL,
)
cfg = SystemPreparationConfig()
cfg.slurm = False
calc.setup(bound_leg_sysprep_config=cfg, free_leg_sysprep_config=cfg)
yield calc

if os.path.exists(temp_parent_dir):
shutil.rmtree(temp_parent_dir, ignore_errors=True)

def test_setup_calc_overall(self, setup_calc, mock_run_process):
"""Test that setting up the calculation was successful at a high level."""
assert setup_calc.setup_complete
Expand Down Expand Up @@ -463,6 +496,17 @@ def test_setup_calc_sims(self, setup_calc):
base_dir_files = set(os.listdir(sim.base_dir))
assert base_dir_files == expected_base_files

def test_stage_output_path_replacement(self, setup_calc_with_input_path):
"""Test that stage output paths are correctly derived from input paths by only
replacing the last 'input' with 'output'."""
for leg in setup_calc_with_input_path.legs:
for stage in leg.stages:
if leg.leg_type == a3.LegType.BOUND:
expected_output_dir = "output".join(
stage.input_dir.rsplit("input", 1)
)
assert stage.output_dir == expected_output_dir


######################## Tests Requiring SLURM ########################

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log
0.3.2
====================
- Fix bug which caused somd.rst7 files in the ensemble equilibration directories to be incorrectly numbered in some cases.
- Fix bug which caused the output directory to be incorrectly replaced with "output" in some cases.

0.3.1
====================
Expand Down