Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead attributes in application #673

Merged
merged 13 commits into from
Aug 29, 2024
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ module = [
"smartsim._core.utils.telemetry.*",
"smartsim.database.*",
"smartsim.settings.sgeSettings",
"smartsim._core.control.controller_utils",
"smartsim.entity.dbnode",
]
ignore_missing_imports = true
ignore_errors = true
2 changes: 1 addition & 1 deletion smartsim/_core/generation/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _build_operations(cls, job: Job, job_path: pathlib.Path) -> None:
app = t.cast(Application, job.entity)
cls._copy_files(app.files, job_path)
cls._symlink_files(app.files, job_path)
cls._write_tagged_files(app.files, app.params, job_path)
cls._write_tagged_files(app.files, app.file_parameters, job_path)

@staticmethod
def _copy_files(files: t.Union[EntityFiles, None], dest: pathlib.Path) -> None:
Expand Down
60 changes: 60 additions & 0 deletions smartsim/_core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@

import base64
import collections.abc
import itertools
import os
import signal
import subprocess
import sys
import typing as t
import uuid
import warnings
from datetime import datetime
from functools import lru_cache
from shutil import which
Expand Down Expand Up @@ -284,6 +287,20 @@
return process.stdout.decode("utf-8"), process.returncode


def _stringify_id(_id: int) -> str:
"""Return the CPU id as a string if an int, otherwise raise a ValueError

:params _id: the CPU id as an int
:returns: the CPU as a string
"""
if isinstance(_id, int):
if _id < 0:
raise ValueError("CPU id must be a nonnegative number")
return str(_id)

Check warning on line 299 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L296-L299

Added lines #L296 - L299 were not covered by tests

raise TypeError(f"Argument is of type '{type(_id)}' not 'int'")

Check warning on line 301 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L301

Added line #L301 was not covered by tests


class CrayExPlatformResult:
locate_msg = "Unable to locate `{0}`."

Expand Down Expand Up @@ -515,3 +532,46 @@
if did_push := fn not in self:
self.push(fn)
return did_push

def _create_pinning_string(
pin_ids: t.Optional[t.Iterable[t.Union[int, t.Iterable[int]]]], cpus: int
) -> t.Optional[str]:
"""Create a comma-separated string of CPU ids. By default, ``None``
juliaputko marked this conversation as resolved.
Show resolved Hide resolved
returns 0,1,...,cpus-1; an empty iterable will disable pinning
altogether, and an iterable constructs a comma separated string of
integers (e.g. ``[0, 2, 5]`` -> ``"0,2,5"``)

:params pin_ids: CPU ids
:params cpu: number of CPUs
:raises TypeError: if pin id is not an iterable of ints
:returns: a comma separated string of CPU ids
"""

try:
pin_ids = tuple(pin_ids) if pin_ids is not None else None
except TypeError:
raise TypeError(

Check warning on line 553 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L550-L553

Added lines #L550 - L553 were not covered by tests
"Expected a cpu pinning specification of type iterable of ints or "
f"iterables of ints. Instead got type `{type(pin_ids)}`"
) from None

# Deal with MacOSX limitations first. The "None" (default) disables pinning
# and is equivalent to []. The only invalid option is a non-empty pinning
if sys.platform == "darwin":
if pin_ids:
warnings.warn(

Check warning on line 562 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L560-L562

Added lines #L560 - L562 were not covered by tests
"CPU pinning is not supported on MacOSX. Ignoring pinning "
"specification.",
RuntimeWarning,
)
return None

Check warning on line 567 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L567

Added line #L567 was not covered by tests

# Flatten the iterable into a list and check to make sure that the resulting
# elements are all ints
if pin_ids is None:
return ",".join(_stringify_id(i) for i in range(cpus))
if not pin_ids:
return None
pin_ids = ((x,) if isinstance(x, int) else x for x in pin_ids)
to_fmt = itertools.chain.from_iterable(pin_ids)
return ",".join(sorted({_stringify_id(x) for x in to_fmt}))

Check warning on line 577 in smartsim/_core/utils/helpers.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/utils/helpers.py#L571-L577

Added lines #L571 - L577 were not covered by tests
2 changes: 1 addition & 1 deletion smartsim/entity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
# 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 .application import Application
from .dbnode import FSNode
from .dbobject import *
from .ensemble import Ensemble
from .entity import SmartSimEntity, TelemetryConfiguration
from .entityList import EntityList, EntitySequence
from .files import TaggedFilesHierarchy
from .model import Application
Loading
Loading