Skip to content

Commit

Permalink
Remove unnecessary passthrough properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Aug 22, 2023
1 parent c6982c2 commit f6fa2b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
24 changes: 3 additions & 21 deletions smartsim/_core/launcher/step/lsfStep.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,10 @@ def __init__(self, name: str, cwd: str, run_settings: RunSettings):
super().__init__(name, cwd, run_settings)
self.alloc: t.Optional[str] = None
self.managed = True
self.run_settings = run_settings
if not self.run_settings.in_batch:
self._set_alloc()

@property
def run_settings(self) -> RunSettings:
"""Get the run settings attached to this step"""
if isinstance(self.step_settings, RunSettings):
return self.step_settings
raise TypeError("Run settings must be of type RunSettings")

def _jsrun_settings(
self, ignore_type_mismatch: bool = False
) -> t.Optional[JsrunSettings]:
"""Get attached run settings if they are of type JsrunSettings.
Raise an exception on incorrect run settings type, unless
ignore_type_mismatch is True"""
if isinstance(self.step_settings, JsrunSettings):
return self.step_settings
if not ignore_type_mismatch:
raise TypeError("Run settings must be of type JsrunSettings")
return None

def get_output_files(self) -> t.Tuple[str, str]:
"""Return two paths to error and output files based on cwd"""
output = self.get_step_file(ending=".out")
Expand Down Expand Up @@ -232,8 +214,8 @@ def _set_alloc(self) -> None:
def _get_mpmd(self) -> t.List[RunSettings]:
"""Temporary convenience function to return a typed list
of attached RunSettings"""
if jsrs := self._jsrun_settings(ignore_type_mismatch=True):
return jsrs.mpmd
if isinstance(self.step_settings, JsrunSettings):
return self.step_settings.mpmd
return []

def _build_exe(self) -> t.List[str]:
Expand Down
35 changes: 7 additions & 28 deletions smartsim/_core/launcher/step/slurmStep.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,10 @@ def __init__(self, name: str, cwd: str, run_settings: SrunSettings) -> None:
super().__init__(name, cwd, run_settings)
self.alloc: t.Optional[str] = None
self.managed = True
self.run_settings = run_settings
if not self.run_settings.in_batch:
self._set_alloc()

@property
def run_settings(self) -> RunSettings:
"""Get the run settings attached to this step"""
if isinstance(self.step_settings, RunSettings):
return self.step_settings
raise TypeError("Run settings must be of type RunSettings")

def _srun_settings(
self, ignore_type_mismatch: bool = False
) -> t.Optional[SrunSettings]:
"""Get attached run settings if they are of type SrunSettings.
Raise an exception on incorrect run settings type, unless
ignore_type_mismatch is True"""
if isinstance(self.step_settings, SrunSettings):
return self.step_settings
if not ignore_type_mismatch:
raise TypeError("Run settings must be of type SrunSettings")
return None

def get_launch_cmd(self) -> t.List[str]:
"""Get the command to launch this step
Expand All @@ -158,14 +140,13 @@ def get_launch_cmd(self) -> t.List[str]:
srun_cmd += ["--jobid", str(self.alloc)]

if self.run_settings.env_vars:
if srs := self._srun_settings():
env_vars, csv_env_vars = srs.format_comma_sep_env_vars()
env_vars, csv_env_vars = self.run_settings.format_comma_sep_env_vars()

if len(env_vars) > 0:
srun_cmd += ["--export", f"ALL,{env_vars}"]
if len(env_vars) > 0:
srun_cmd += ["--export", f"ALL,{env_vars}"]

if csv_env_vars:
compound_env = compound_env.union(csv_env_vars)
if csv_env_vars:
compound_env = compound_env.union(csv_env_vars)

srun_cmd += self.run_settings.format_run_args()

Expand Down Expand Up @@ -209,9 +190,7 @@ def _set_alloc(self) -> None:
def _get_mpmd(self) -> t.List[RunSettings]:
"""Temporary convenience function to return a typed list
of attached RunSettings"""
if srs := self._srun_settings(ignore_type_mismatch=True):
return srs.mpmd
return []
return self.run_settings.mpmd

@staticmethod
def _get_exe_args_list(run_setting: RunSettings) -> t.List[str]:
Expand Down

0 comments on commit f6fa2b5

Please sign in to comment.