Skip to content

Commit

Permalink
feat(config): add partition in application.yaml and use it in get_load
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jul 25, 2023
1 parent d549e16 commit 0c948e8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions antarest/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class SlurmConfig:
default_n_cpu: int = 1
default_json_db_name: str = ""
slurm_script_path: str = ""
partition: str = ""
max_cores: int = 64
antares_versions_on_remote_server: List[str] = field(
default_factory=lambda: []
Expand All @@ -205,6 +206,7 @@ def from_dict(data: JSON) -> "SlurmConfig":
default_n_cpu=data["default_n_cpu"],
default_json_db_name=data["default_json_db_name"],
slurm_script_path=data["slurm_script_path"],
partition=data["partition"],
antares_versions_on_remote_server=data[
"antares_versions_on_remote_server"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def _init_launcher_parameters(
json_dir=local_workspace or self.slurm_config.local_workspace,
default_json_db_name=self.slurm_config.default_json_db_name,
slurm_script_path=self.slurm_config.slurm_script_path,
partition=self.slurm_config.partition,
antares_versions_on_remote_server=self.slurm_config.antares_versions_on_remote_server,
default_ssh_dict={
"username": self.slurm_config.username,
Expand Down
3 changes: 2 additions & 1 deletion antarest/launcher/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ def get_load(self) -> LauncherLoadDTO:
key_password=slurm_config.key_password,
password=slurm_config.password,
)
slurm_load = calculates_slurm_load(ssh_config)
partition = slurm_config.partition
slurm_load = calculates_slurm_load(ssh_config, partition)
return LauncherLoadDTO(
allocated_cpu_rate=slurm_load[0],
cluster_load_rate=slurm_load[1],
Expand Down
8 changes: 4 additions & 4 deletions antarest/launcher/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def parse_cpu_load(sinfo_output: str) -> float:


def calculates_slurm_load(
ssh_config: SSHConfigDTO,
ssh_config: SSHConfigDTO, partition: str
) -> Tuple[float, float, int]:
# allocated cpus
sinfo_cpus_used = execute_command(
ssh_config,
["sinfo", "--partition", "calin1", "-O", "NodeAIOT", "--noheader"],
["sinfo", "--partition", partition, "-O", "NodeAIOT", "--noheader"],
)
allocated_cpus = 100 * parse_cpu_used(sinfo_cpus_used)
# cluster load
Expand All @@ -81,7 +81,7 @@ def calculates_slurm_load(
[
"sinfo",
"--partition",
"calin1",
partition,
"-N",
"-O",
"CPUsLoad",
Expand All @@ -96,7 +96,7 @@ def calculates_slurm_load(
[
"squeue",
"--partition",
"calin1",
partition,
"--noheader",
"-t",
"pending",
Expand Down
1 change: 1 addition & 0 deletions resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ launcher:
# default_n_cpu: 12
# default_json_db_name: launcher_db.json
# slurm_script_path: /path/to/launchantares_v1.1.3.sh
# partition: specific_partition_for_the_resource_allocation
# db_primary_key: name
# antares_versions_on_remote_server :
# - "610"
Expand Down
4 changes: 4 additions & 0 deletions tests/launcher/test_slurm_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def launcher_config(tmp_path: Path) -> Config:
local_workspace=tmp_path,
default_json_db_name="default_json_db_name",
slurm_script_path="slurm_script_path",
partition="fake_partition",
antares_versions_on_remote_server=["42", "45"],
username="username",
hostname="hostname",
Expand Down Expand Up @@ -111,6 +112,7 @@ def test_init_slurm_launcher_parameters(tmp_path: Path):
local_workspace=tmp_path,
default_json_db_name="default_json_db_name",
slurm_script_path="slurm_script_path",
partition="faek_partition",
antares_versions_on_remote_server=["42"],
username="username",
hostname="hostname",
Expand All @@ -136,6 +138,7 @@ def test_init_slurm_launcher_parameters(tmp_path: Path):
main_parameters.slurm_script_path
== config.launcher.slurm.slurm_script_path
)
assert main_parameters.partition == config.launcher.slurm.partition
assert (
main_parameters.antares_versions_on_remote_server
== config.launcher.slurm.antares_versions_on_remote_server
Expand Down Expand Up @@ -516,6 +519,7 @@ def test_kill_job(
json_dir=Path(tmp_path),
default_json_db_name="default_json_db_name",
slurm_script_path="slurm_script_path",
partition="fake_partition",
antares_versions_on_remote_server=["42", "45"],
default_ssh_dict={
"username": "username",
Expand Down
2 changes: 1 addition & 1 deletion tests/launcher/test_ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def test_parse_cpu_load():
def test_calculates_slurm_load_whithout_pkey_fails():
ssh_config = Mock()
with pytest.raises(SlurmError):
calculates_slurm_load(ssh_config)
calculates_slurm_load(ssh_config, "fake_partition")

0 comments on commit 0c948e8

Please sign in to comment.