Skip to content

Commit edb8364

Browse files
BatchSettings, LaunchSettings, Command, CommandList and LaunchCommand Refactor (#587)
1 parent d058213 commit edb8364

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3891
-3277
lines changed

conftest.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@
5858
from smartsim.entity import Application
5959
from smartsim.error import SSConfigError, SSInternalError
6060
from smartsim.log import get_logger
61-
from smartsim.settings import (
62-
AprunSettings,
63-
DragonRunSettings,
64-
JsrunSettings,
65-
MpiexecSettings,
66-
MpirunSettings,
67-
PalsMpiexecSettings,
68-
RunSettings,
69-
SrunSettings,
70-
)
61+
# Mock imports
62+
class AprunSettings: pass
63+
class DragonRunSettings: pass
64+
class JsrunSettings: pass
65+
class MpiexecSettings: pass
66+
class MpirunSettings: pass
67+
class PalsMpiexecSettings: pass
68+
class RunSettings: pass
69+
class SrunSettings: pass
7170

7271
logger = get_logger(__name__)
7372

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# BSD 2-Clause License
2+
#
3+
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this
10+
# list of conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice,
13+
# this list of conditions and the following disclaimer in the documentation
14+
# and/or other materials provided with the distribution.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
from .command import Command
28+
from .commandList import CommandList
29+
from .launchCommands import LaunchCommands

smartsim/_core/commands/command.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# BSD 2-Clause License
2+
#
3+
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this
10+
# list of conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice,
13+
# this list of conditions and the following disclaimer in the documentation
14+
# and/or other materials provided with the distribution.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
import typing as t
28+
from collections.abc import MutableSequence
29+
30+
from ...settings.launchCommand import LauncherType
31+
32+
33+
class Command(MutableSequence[str]):
34+
"""Basic container for command information"""
35+
36+
def __init__(self, launcher: LauncherType, command: t.List[str]) -> None:
37+
"""Command constructor"""
38+
self._launcher = launcher
39+
self._command = command
40+
41+
@property
42+
def launcher(self) -> LauncherType:
43+
"""Get the launcher type.
44+
Return a reference to the LauncherType.
45+
"""
46+
return self._launcher
47+
48+
@property
49+
def command(self) -> t.List[str]:
50+
"""Get the command list.
51+
Return a reference to the command list.
52+
"""
53+
return self._command
54+
55+
def __getitem__(self, idx: int) -> str:
56+
"""Get the command at the specified index."""
57+
return self._command[idx]
58+
59+
def __setitem__(self, idx: int, value: str) -> None:
60+
"""Set the command at the specified index."""
61+
self._command[idx] = value
62+
63+
def __delitem__(self, idx: int) -> None:
64+
"""Delete the command at the specified index."""
65+
del self._command[idx]
66+
67+
def __len__(self) -> int:
68+
"""Get the length of the command list."""
69+
return len(self._command)
70+
71+
def insert(self, idx: int, value: str) -> None:
72+
"""Insert a command at the specified index."""
73+
self._command.insert(idx, value)
74+
75+
def __str__(self) -> str: # pragma: no cover
76+
string = f"\nLauncher: {self.launcher.value}\n"
77+
string += f"Command: {' '.join(str(cmd) for cmd in self.command)}"
78+
return string
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# BSD 2-Clause License
2+
#
3+
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this
10+
# list of conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice,
13+
# this list of conditions and the following disclaimer in the documentation
14+
# and/or other materials provided with the distribution.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
import typing as t
28+
from collections.abc import MutableSequence
29+
30+
from .command import Command
31+
32+
33+
class CommandList(MutableSequence[Command]):
34+
"""Container for a Sequence of Command objects"""
35+
36+
def __init__(self, commands: t.Union[Command, t.List[Command]]):
37+
"""CommandList constructor"""
38+
if isinstance(commands, Command):
39+
commands = [commands]
40+
self._commands: t.List[Command] = list(commands)
41+
42+
@property
43+
def commands(self) -> t.List[Command]:
44+
"""Get the Command list.
45+
Return a reference to the Command list.
46+
"""
47+
return self._commands
48+
49+
def __getitem__(self, idx: int) -> Command:
50+
"""Get the Command at the specified index."""
51+
return self._commands[idx]
52+
53+
def __setitem__(self, idx: int, value: Command) -> None:
54+
"""Set the Command at the specified index."""
55+
self._commands[idx] = value
56+
57+
def __delitem__(self, idx: int) -> None:
58+
"""Delete the Command at the specified index."""
59+
del self._commands[idx]
60+
61+
def __len__(self) -> int:
62+
"""Get the length of the Command list."""
63+
return len(self._commands)
64+
65+
def insert(self, idx: int, value: Command) -> None:
66+
"""Insert a Command at the specified index."""
67+
self._commands.insert(idx, value)
68+
69+
def __str__(self) -> str: # pragma: no cover
70+
string = "\n\nCommand List:\n\n"
71+
for counter, cmd in enumerate(self.commands):
72+
string += f"CommandList index {counter} value:"
73+
string += f"{cmd}\n\n"
74+
return string
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from .commandList import CommandList
2+
3+
4+
class LaunchCommands:
5+
"""Container for aggregating prelaunch commands (e.g. file
6+
system operations), launch commands, and postlaunch commands
7+
"""
8+
9+
def __init__(
10+
self,
11+
prelaunch_commands: CommandList,
12+
launch_commands: CommandList,
13+
postlaunch_commands: CommandList,
14+
) -> None:
15+
"""LaunchCommand constructor"""
16+
self._prelaunch_commands = prelaunch_commands
17+
self._launch_commands = launch_commands
18+
self._postlaunch_commands = postlaunch_commands
19+
20+
@property
21+
def prelaunch_command(self) -> CommandList:
22+
"""Get the prelaunch command list.
23+
Return a reference to the command list.
24+
"""
25+
return self._prelaunch_commands
26+
27+
@property
28+
def launch_command(self) -> CommandList:
29+
"""Get the launch command list.
30+
Return a reference to the command list.
31+
"""
32+
return self._launch_commands
33+
34+
@property
35+
def postlaunch_command(self) -> CommandList:
36+
"""Get the postlaunch command list.
37+
Return a reference to the command list.
38+
"""
39+
return self._postlaunch_commands
40+
41+
def __str__(self) -> str: # pragma: no cover
42+
string = "\n\nPrelaunch Command List:\n"
43+
for pre_cmd in self.prelaunch_command:
44+
string += f"{pre_cmd}\n"
45+
string += "\n\nLaunch Command List:\n"
46+
for launch_cmd in self.launch_command:
47+
string += f"{launch_cmd}\n"
48+
string += "\n\nPostlaunch Command List:\n"
49+
for post_cmd in self.postlaunch_command:
50+
string += f"{post_cmd}\n"
51+
return string

smartsim/_core/launcher/step/localStep.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
import typing as t
3030

3131
from ....entity import Application, FSNode
32-
from ....settings import Singularity
33-
from ....settings.base import RunSettings
32+
from ....settings import RunSettings, Singularity
3433
from .step import Step, proxyable_launch_cmd
3534

3635

smartsim/_core/launcher/step/lsfStep.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
from ....entity import Application, FSNode
3232
from ....error import AllocationError
3333
from ....log import get_logger
34-
from ....settings import BsubBatchSettings, JsrunSettings
35-
from ....settings.base import RunSettings
34+
from ....settings import BsubBatchSettings, JsrunSettings, RunSettings
3635
from .step import Step
3736

3837
logger = get_logger(__name__)

smartsim/_core/launcher/step/mpiStep.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
from ....entity import Application, FSNode
3333
from ....error import AllocationError, SmartSimError
3434
from ....log import get_logger
35-
from ....settings import MpiexecSettings, MpirunSettings, OrterunSettings
36-
from ....settings.base import RunSettings
35+
from ....settings import MpiexecSettings, MpirunSettings, OrterunSettings, RunSettings
3736
from .step import Step, proxyable_launch_cmd
3837

3938
logger = get_logger(__name__)

smartsim/_core/launcher/step/step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
from ....entity import Application, Ensemble, FSNode
4141
from ....log import get_logger
42-
from ....settings.base import RunSettings, SettingsBase
42+
from ....settings import RunSettings, SettingsBase
4343
from ...utils.helpers import encode_cmd, get_base_36_repr
4444
from ..colocated import write_colocated_launch_script
4545

smartsim/_core/utils/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def check_dev_log_level() -> bool:
8787
return lvl == "developer"
8888

8989

90-
def fmt_dict(value: t.Dict[str, t.Any]) -> str:
90+
def fmt_dict(value: t.Mapping[str, t.Any]) -> str:
9191
fmt_str = ""
9292
for k, v in value.items():
9393
fmt_str += "\t" + str(k) + " = " + str(v)

0 commit comments

Comments
 (0)