Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions smartsim/launchable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from .basejob import BaseJob
from .job import Job
from .launchable import Launchable
from .mpmdjob import MPMDJob
from .mpmdpair import MPMDPair
41 changes: 41 additions & 0 deletions smartsim/launchable/basejob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


from abc import ABC, abstractmethod

from smartsim.launchable.launchable import Launchable


class BaseJob(ABC, Launchable):
"""The highest level abstract base class for a single job that can be launched"""

@abstractmethod
def get_launch_steps(self) -> None: # TODO: -> LaunchSteps:
"""Return the launch steps corresponding to the
internal data.
"""
...
80 changes: 80 additions & 0 deletions smartsim/launchable/job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from abc import abstractmethod
from copy import deepcopy

from smartsim.entity.entity import SmartSimEntity
from smartsim.launchable.basejob import BaseJob
from smartsim.settings import RunSettings


class Job(BaseJob):
"""A Job holds a reference to a SmartSimEntity and associated
LaunchSettings prior to launch. It is responsible for turning
the stored entity and launch settings into commands that can be
executed by a launcher.

Jobs will hold a deep copy of launch settings.
"""

def __init__(
self,
entity: SmartSimEntity,
launch_settings: RunSettings, # TODO: rename to LaunchSettings
) -> None:
super().__init__()
self._entity = deepcopy(entity)
self._launch_settings = deepcopy(launch_settings)
# TODO: self.warehouse_runner = JobWarehouseRunner

@property
def entity(self) -> SmartSimEntity:
return deepcopy(self._entity)

@entity.setter
def entity(self, value):
self._entity = deepcopy(value)

@property
def launch_settings(self) -> RunSettings:
return deepcopy(self._launch_settings)

@launch_settings.setter
def launch_settings(self, value):
self._launch_settings = deepcopy(value)

def get_launch_steps(self) -> None: # -> LaunchCommands:
"""Return the launch steps corresponding to the
internal data.
"""
pass
# TODO: return JobWarehouseRunner.run(self)

def __str__(self) -> str: # pragma: no cover
string = f"SmartSim Entity: {self.entity}\n"
string += f"Launch Settings: {self.launch_settings}"
return string
38 changes: 38 additions & 0 deletions smartsim/launchable/launchable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


class SmartSimObject:
"""Base Class for SmartSim Objects"""

...


class Launchable(SmartSimObject):
"""Base Class for anything than can be passed
into Experiment.start()"""

...
110 changes: 110 additions & 0 deletions smartsim/launchable/mpmdjob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import typing as t
from copy import deepcopy

from smartsim.entity.entity import SmartSimEntity
from smartsim.error.errors import SSUnsupportedError
from smartsim.launchable.basejob import BaseJob
from smartsim.launchable.mpmdpair import MPMDPair
from smartsim.settings.base import RunSettings


def _check_launcher(mpmd_pairs: t.List[MPMDPair]) -> None:
"""Enforce all pairs have the same launcher"""
flag = 0
ret = None
for mpmd_pair in mpmd_pairs:
if flag == 1:
if ret == mpmd_pair.launch_settings.run_command:
flag = 0
else:
raise SSUnsupportedError("MPMD pairs must all share the same launcher.")
ret = mpmd_pair.launch_settings.run_command
flag = 1


def _check_entity(mpmd_pairs: t.List[MPMDPair]) -> None:
"""Enforce all pairs have the same entity types"""
flag = 0
ret = None
for mpmd_pair in mpmd_pairs:
if flag == 1:
if type(ret) == type(mpmd_pair.entity):
flag = 0
else:
raise SSUnsupportedError(
"MPMD pairs must all share the same entity type."
)
ret = mpmd_pair.entity
flag = 1


class MPMDJob(BaseJob):
"""An MPMDJob holds references to SmartSimEntity and
LaunchSettings pairs. It is responsible for turning
The stored pairs into an MPMD command(s)
"""

def __init__(self, mpmd_pairs: t.List[MPMDPair] = None) -> None:
super().__init__()
self._mpmd_pairs = deepcopy(mpmd_pairs) if mpmd_pairs else []
_check_launcher(self._mpmd_pairs)
_check_entity(self._mpmd_pairs)
# TODO: self.warehouse_runner = MPMDJobWarehouseRunner

@property
def mpmd_pairs(self) -> t.List[MPMDPair]:
return deepcopy(self._mpmd_pairs)

@mpmd_pairs.setter
def mpmd_pair(self, value):
self._mpmd_pair = deepcopy(value)

def add_mpmd_pair(
self, entity: SmartSimEntity, launch_settings: RunSettings
) -> None:
"""
Add a mpmd pair to the mpmd job
"""
self._mpmd_pairs.append(MPMDPair(entity, launch_settings))
_check_launcher(self.mpmd_pairs)
_check_entity(self.mpmd_pairs)

def get_launch_steps(self) -> None: # TODO: -> LaunchSteps:
"""Return the launch steps corresponding to the
internal data.
"""
pass
# TODO: return MPMDJobWarehouseRunner.run(self)

def __str__(self) -> str: # pragma: no cover
"""returns A user-readable string of a MPMD Job"""
for mpmd_pair in self.mpmd_pairs:
string = "\n== MPMD Pair == \n{}\n{}\n"
return string.format(mpmd_pair.entity, mpmd_pair.launch_settings)
return string
38 changes: 38 additions & 0 deletions smartsim/launchable/mpmdpair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from smartsim.entity.entity import SmartSimEntity
from smartsim.settings.base import RunSettings


class MPMDPair:
"""Class to store MPMD Pairs"""

def __init__(
self, entity: SmartSimEntity, launch_settings: RunSettings
): # TODO: rename to LaunchSettings
self.entity = entity
self.launch_settings = launch_settings
Loading