Skip to content

Commit

Permalink
Fix bug in get_slurm_file_base so = is correctly handled
Browse files Browse the repository at this point in the history
This partially addresses #6.
Now both = and spaces are correctly handled when reading the slurm
script to extract the output file name.
  • Loading branch information
fjclark committed Sep 16, 2024
1 parent 1c0376a commit cb0d532
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion a3fe/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
16 changes: 16 additions & 0 deletions a3fe/data/alternative_input/alternative_run_somd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

#SBATCH --account=qt
#SBATCH --nodes=1
#SBATCH --time=24:00:00
#SBATCH --gres=gpu:1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=2
#SBATCH --exclude=node018
#SBATCH --mem=50G
#SBATCH --output=somd-array-gpu-%A.%a.out

lam=$1
echo "lambda is: " $lam

srun somd-freenrg -C somd.cfg -l $lam -p CUDA
3 changes: 2 additions & 1 deletion a3fe/read/_process_slurm_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Functionality for processing slurm files."""

import os as _os
import re as _re


def get_slurm_file_base(slurm_file: str) -> str:
Expand All @@ -22,7 +23,7 @@ def get_slurm_file_base(slurm_file: str) -> str:
# Find the slurm output file
with open(slurm_file, "r") as f:
for line in f:
split_line = line.split()
split_line = _re.split(" |=", line)
if len(split_line) > 0 and split_line[0] == "#SBATCH":
if split_line[1] == "--output" or split_line[1] == "-o":
slurm_pattern = split_line[2]
Expand Down
13 changes: 13 additions & 0 deletions a3fe/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
write_truncated_sim_datafile,
)

from ..read._process_slurm_files import get_slurm_file_base


def test_read_mbar_result():
"""Test that the read_mbar_result function works correctly"""
Expand Down Expand Up @@ -112,3 +114,14 @@ def test_write_truncated_sim_datafile_end_and_start():
lines = f.readlines()
assert lines[13].split()[0] == "5000"
assert lines[-2].split()[0] == "9000"

def test_process_slurm_file_base():
"""
Test that the SLURM file base name is correctly extracted from a SLURM file.
"""
slurm_file_base = get_slurm_file_base("a3fe/data/example_run_dir/input/run_somd.sh")
assert slurm_file_base == "a3fe/data/example_run_dir/input/somd-array-gpu-"

# Test alternative formatting
slurm_file_base = get_slurm_file_base("a3fe/data/alternative_input/alternative_run_somd.sh")
assert slurm_file_base == "a3fe/data/alternative_input/somd-array-gpu-"
6 changes: 6 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
Change Log
===============

0.1.2
====================

- Fixed bug in ``get_slurm_file_base`` which caused the function to fail to read the output name if an "=" instead of a space was used to separate the argument and value.

v0.1.1
====================

- Ensured that ``simulation_runner`` objects only get pickled once they've been fully initialised. This avoids issues where an error occurs during initialisation and the object is pickled in an incomplete state. Addresses https://github.com/michellab/a3fe/issues/1.

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
"Documentation" = "https://a3fe.readthedocs.io/"

[metadata]
version = "0.1.1"
version = "0.1.2"

[project.optional-dependencies]
test = [
Expand Down Expand Up @@ -97,7 +97,7 @@ distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
method = "git" # <- The method name
# Parameters to pass to the method:
match = ["*"]
default-tag = "0.1.1"
default-tag = "0.1.2"

[tool.versioningit.write]
file = "a3fe/_version.py"
Expand Down

0 comments on commit cb0d532

Please sign in to comment.