Skip to content

Commit

Permalink
Fix issue with invalid characters in output file names
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundGoodman committed Feb 25, 2024
1 parent 40a66b6 commit 112a94e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/hpc_multibench/run_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,29 @@ def sbatch_contents(self) -> str:
@property
def output_file(self) -> Path:
"""Get the path to the output file to write to."""
instantation_str = (
f"__{RunConfiguration.get_instantiation_repr(self.instantiation)}"
if self.instantiation is not None
else ""
)
return self.output_directory / f"{self.name}{instantation_str}__%j.out"
# instantation_str = (
# f"__{RunConfiguration.get_instantiation_repr(self.instantiation)}"
# if self.instantiation is not None
# else ""
# )
return self.output_directory / f"{self.name}__%j.out"

@classmethod
def get_instantiation_repr(cls, instantiation: dict[str, Any]) -> str:
"""Get a string representation of a run instantiation."""
# TODO: Better representation of sbatch etc than stringifying
# instantiation_items: list[str] = []
# for name, value in instantiation.items():
# if name == "args":
# instantiation_items.append(
# f"{name}={str(value).replace('/','').replace(' ','_')}"
# )
# # elif name == "run_command":
# # elif name == "build_commands":
# # elif name == "module_loads":
# # elif name == "sbatch_config":
# # elif name == "environment_variables":
# return ",".join(instantiation_items)
return ",".join(
f"{name}={str(value).replace('/','').replace(' ','_')}"
for name, value in instantiation.items()
Expand All @@ -113,8 +125,7 @@ def run(self, dependencies: list[int] | None = None) -> int | None:

# Create and run the temporary sbatch file via slurm
with NamedTemporaryFile(
prefix=self.name,
suffix=".sbatch", dir=Path("./"), mode="w+"
prefix=self.name, suffix=".sbatch", dir=Path("./"), mode="w+"
) as sbatch_tmp:
sbatch_tmp.write(self.sbatch_contents)
sbatch_tmp.flush()
Expand All @@ -123,7 +134,7 @@ def run(self, dependencies: list[int] | None = None) -> int | None:
dependencies_string = ",".join(str(job_id) for job_id in dependencies)
command_list.insert(1, f"--dependency=afterok:{dependencies_string}")
result = subprocess_run( # nosec
command_list, # noqa: S603, S607
command_list, # type: ignore # noqa: S603, PGH003
check=True,
stdout=PIPE,
)
Expand Down
3 changes: 3 additions & 0 deletions src/hpc_multibench/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def record(self, args: Namespace) -> None:
print(run_configuration, end="\n\n")
return

# TODO: Need to account for case where build commands is in the
# matrix, then just needs to be a long chain of dependencies

# Run all run configurations and store their slurm job ids
run_configuration_job_ids: dict[RunConfiguration, int | None] = {}
for run_configurations in realised_run_configurations.values():
Expand Down

0 comments on commit 112a94e

Please sign in to comment.