Skip to content

Commit

Permalink
Get everything working except storing slurm job ids
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundGoodman committed Feb 24, 2024
1 parent d0fb501 commit e8c3b18
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/hpc_multibench/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def main() -> None: # pragma: no cover
args: Namespace = get_parser().parse_args()

test_plan = TestPlan(args.yaml_path)
test_plan.report_all()
test_plan.record_all()
23 changes: 11 additions & 12 deletions src/hpc_multibench/run_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
class RunConfiguration:
"""A builder class for a test run on batch compute."""

def __init__(self, name: str, run_command: str, output_file: Path):
def __init__(
self, name: str, run_command: str, output_directory: Path = Path("./")
):
"""Initialise the run configuration file as a empty bash file."""
self.name = name
self.output_file: Path = output_file
self.output_directory: Path = output_directory
self.sbatch_config: dict[str, str] = {}
self.module_loads: list[str] = []
self.environment_variables: dict[str, str] = {}
Expand Down Expand Up @@ -71,19 +73,15 @@ def sbatch_contents(self) -> str:

return sbatch_file

@classmethod
def get_output_file_name(
cls, run_configuration_name: str, instantiation: dict[str, Any] | None = None
) -> str:
"""Construct an output file name for a run."""
# TODO: If instantiation is now class member, can this be a true method/property?
# -> Would remove parameter into __init__...
@property
def output_file(self) -> Path:
"""Get the path to the output file to write to."""
instantation_str = (
f"__{BenchModel.get_instantiation_repr(instantiation)}"
if instantiation is not None
f"__{RunConfiguration.get_instantiation_repr(self.instantiation)}"
if self.instantiation is not None
else ""
)
return f"{run_configuration_name}{instantation_str}__%j.out"
return self.output_directory / f"{self.name}{instantation_str}__%j.out"

@classmethod
def get_instantiation_repr(cls, instantiation: dict[str, Any]) -> str:
Expand Down Expand Up @@ -125,6 +123,7 @@ def collect(self, slurm_id: int) -> str | None:
)
if SLURM_UNQUEUED_SUBSTRING in result.stdout.decode("utf-8"):
return None

# Return the contents of the specified output file
output_file = (
self.output_file.parent / f"{self.output_file.name[:-8]}__{slurm_id}.out"
Expand Down
12 changes: 7 additions & 5 deletions src/hpc_multibench/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def instantiations(self) -> list[dict[str, Any]]:
]

def record(
self, clobber: bool = False, dry_run: bool = False, no_wait: bool = False
self,
clobber: bool = False, # noqa: FBT001, FBT002
dry_run: bool = False, # noqa: FBT001, FBT002
no_wait: bool = False, # noqa: FBT001, FBT002
) -> None:
"""Spawn run configurations for the test bench."""
print(f"Recording data from test bench '{self.name}'")
Expand All @@ -73,12 +76,9 @@ def record(
if clobber:
rmtree(self.output_directory)

# Get instantiations from variable matrix
print(self.instantiations)

# Realise run configurations from list of instantiations
self.run_configurations = [
run_model.realise(self.name, run_name, instantiation)
run_model.realise(run_name, self.output_directory, instantiation)
for instantiation in self.instantiations
for run_name, run_model in self.run_configuration_models.items()
]
Expand All @@ -97,6 +97,8 @@ def record(
# Store slurm job id mappings

# TODO: Optionally wait for all run configurations to dequeue/terminate
if not no_wait:
pass

def report(self) -> None:
"""Analyse completed run configurations for the test bench."""
Expand Down
2 changes: 1 addition & 1 deletion src/hpc_multibench/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def record_all(self) -> None:
"""Run all the enabled test benches in the plan."""
for bench in self.benches:
if bench.bench_model.enabled:
bench.record()
bench.record(dry_run=True)

def report_all(self) -> None:
"""Analyse all the enabled test benches in the plan."""
Expand Down
21 changes: 8 additions & 13 deletions src/hpc_multibench/yaml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@ class RunConfigurationModel(BaseModel):
args: str | None = None

def realise(
self, bench_name: str, run_configuration_name: str, variables: dict[str, Any]
self,
name: str,
output_directory: Path,
instantiation: dict[str, Any],
) -> RunConfiguration:
"""Construct a run configuration from its data model."""
# Get the output file path
output_file_name = RunConfiguration.get_output_file_name(
run_configuration_name, variables
)
output_file = BASE_OUTPUT_DIRECTORY / bench_name / output_file_name

# TODO: Modify contents based on variables keys here

run = RunConfiguration(run_configuration_name, self.run_command, output_file)
run = RunConfiguration(name, self.run_command, output_directory)
run.sbatch_config = self.sbatch_config
run.module_loads = self.module_loads
run.environment_variables = self.environment_variables
run.directory = Path(self.directory)
run.build_commands = self.build_commands
run.args = self.args

# Fix this to work for more things than args...
for key, value in variables.items():
# Update the run configuration based on the instantiation
for key, value in instantiation.items():
# TODO: Error checking on keys
setattr(run, key, value)

Expand All @@ -56,7 +51,7 @@ class PlotModel(BaseModel):

x: str
y: str

# TODO: Needs work to expand capability


Expand Down

0 comments on commit e8c3b18

Please sign in to comment.