Skip to content

Commit b64af80

Browse files
authored
Job and MPMD Job Implementation (#603)
[ committed by @juliaputko ] [ reviewed by @amandarichardsonn ]
1 parent 883824b commit b64af80

File tree

7 files changed

+555
-0
lines changed

7 files changed

+555
-0
lines changed

smartsim/launchable/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 .basejob import BaseJob
28+
from .job import Job
29+
from .launchable import Launchable
30+
from .mpmdjob import MPMDJob
31+
from .mpmdpair import MPMDPair

smartsim/launchable/basejob.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
28+
from abc import ABC, abstractmethod
29+
30+
from smartsim.launchable.launchable import Launchable
31+
32+
33+
class BaseJob(ABC, Launchable):
34+
"""The highest level abstract base class for a single job that can be launched"""
35+
36+
@abstractmethod
37+
def get_launch_steps(self) -> None: # TODO: -> LaunchSteps:
38+
"""Return the launch steps corresponding to the
39+
internal data.
40+
"""
41+
...

smartsim/launchable/job.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 abc import abstractmethod
28+
from copy import deepcopy
29+
30+
from smartsim.entity.entity import SmartSimEntity
31+
from smartsim.launchable.basejob import BaseJob
32+
from smartsim.settings import RunSettings
33+
34+
35+
class Job(BaseJob):
36+
"""A Job holds a reference to a SmartSimEntity and associated
37+
LaunchSettings prior to launch. It is responsible for turning
38+
the stored entity and launch settings into commands that can be
39+
executed by a launcher.
40+
41+
Jobs will hold a deep copy of launch settings.
42+
"""
43+
44+
def __init__(
45+
self,
46+
entity: SmartSimEntity,
47+
launch_settings: RunSettings, # TODO: rename to LaunchSettings
48+
) -> None:
49+
super().__init__()
50+
self._entity = deepcopy(entity)
51+
self._launch_settings = deepcopy(launch_settings)
52+
# TODO: self.warehouse_runner = JobWarehouseRunner
53+
54+
@property
55+
def entity(self) -> SmartSimEntity:
56+
return deepcopy(self._entity)
57+
58+
@entity.setter
59+
def entity(self, value):
60+
self._entity = deepcopy(value)
61+
62+
@property
63+
def launch_settings(self) -> RunSettings:
64+
return deepcopy(self._launch_settings)
65+
66+
@launch_settings.setter
67+
def launch_settings(self, value):
68+
self._launch_settings = deepcopy(value)
69+
70+
def get_launch_steps(self) -> None: # -> LaunchCommands:
71+
"""Return the launch steps corresponding to the
72+
internal data.
73+
"""
74+
pass
75+
# TODO: return JobWarehouseRunner.run(self)
76+
77+
def __str__(self) -> str: # pragma: no cover
78+
string = f"SmartSim Entity: {self.entity}\n"
79+
string += f"Launch Settings: {self.launch_settings}"
80+
return string

smartsim/launchable/launchable.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
28+
class SmartSimObject:
29+
"""Base Class for SmartSim Objects"""
30+
31+
...
32+
33+
34+
class Launchable(SmartSimObject):
35+
"""Base Class for anything than can be passed
36+
into Experiment.start()"""
37+
38+
...

smartsim/launchable/mpmdjob.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 copy import deepcopy
29+
30+
from smartsim.entity.entity import SmartSimEntity
31+
from smartsim.error.errors import SSUnsupportedError
32+
from smartsim.launchable.basejob import BaseJob
33+
from smartsim.launchable.mpmdpair import MPMDPair
34+
from smartsim.settings.base import RunSettings
35+
36+
37+
def _check_launcher(mpmd_pairs: t.List[MPMDPair]) -> None:
38+
"""Enforce all pairs have the same launcher"""
39+
flag = 0
40+
ret = None
41+
for mpmd_pair in mpmd_pairs:
42+
if flag == 1:
43+
if ret == mpmd_pair.launch_settings.run_command:
44+
flag = 0
45+
else:
46+
raise SSUnsupportedError("MPMD pairs must all share the same launcher.")
47+
ret = mpmd_pair.launch_settings.run_command
48+
flag = 1
49+
50+
51+
def _check_entity(mpmd_pairs: t.List[MPMDPair]) -> None:
52+
"""Enforce all pairs have the same entity types"""
53+
flag = 0
54+
ret = None
55+
for mpmd_pair in mpmd_pairs:
56+
if flag == 1:
57+
if type(ret) == type(mpmd_pair.entity):
58+
flag = 0
59+
else:
60+
raise SSUnsupportedError(
61+
"MPMD pairs must all share the same entity type."
62+
)
63+
ret = mpmd_pair.entity
64+
flag = 1
65+
66+
67+
class MPMDJob(BaseJob):
68+
"""An MPMDJob holds references to SmartSimEntity and
69+
LaunchSettings pairs. It is responsible for turning
70+
The stored pairs into an MPMD command(s)
71+
"""
72+
73+
def __init__(self, mpmd_pairs: t.List[MPMDPair] = None) -> None:
74+
super().__init__()
75+
self._mpmd_pairs = deepcopy(mpmd_pairs) if mpmd_pairs else []
76+
_check_launcher(self._mpmd_pairs)
77+
_check_entity(self._mpmd_pairs)
78+
# TODO: self.warehouse_runner = MPMDJobWarehouseRunner
79+
80+
@property
81+
def mpmd_pairs(self) -> t.List[MPMDPair]:
82+
return deepcopy(self._mpmd_pairs)
83+
84+
@mpmd_pairs.setter
85+
def mpmd_pair(self, value):
86+
self._mpmd_pair = deepcopy(value)
87+
88+
def add_mpmd_pair(
89+
self, entity: SmartSimEntity, launch_settings: RunSettings
90+
) -> None:
91+
"""
92+
Add a mpmd pair to the mpmd job
93+
"""
94+
self._mpmd_pairs.append(MPMDPair(entity, launch_settings))
95+
_check_launcher(self.mpmd_pairs)
96+
_check_entity(self.mpmd_pairs)
97+
98+
def get_launch_steps(self) -> None: # TODO: -> LaunchSteps:
99+
"""Return the launch steps corresponding to the
100+
internal data.
101+
"""
102+
pass
103+
# TODO: return MPMDJobWarehouseRunner.run(self)
104+
105+
def __str__(self) -> str: # pragma: no cover
106+
"""returns A user-readable string of a MPMD Job"""
107+
for mpmd_pair in self.mpmd_pairs:
108+
string = "\n== MPMD Pair == \n{}\n{}\n"
109+
return string.format(mpmd_pair.entity, mpmd_pair.launch_settings)
110+
return string

smartsim/launchable/mpmdpair.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 smartsim.entity.entity import SmartSimEntity
28+
from smartsim.settings.base import RunSettings
29+
30+
31+
class MPMDPair:
32+
"""Class to store MPMD Pairs"""
33+
34+
def __init__(
35+
self, entity: SmartSimEntity, launch_settings: RunSettings
36+
): # TODO: rename to LaunchSettings
37+
self.entity = entity
38+
self.launch_settings = launch_settings

0 commit comments

Comments
 (0)