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 @@ -166,6 +166,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 @@ -154,7 +154,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
50 changes: 50 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 pathlib import Path
Expand Down Expand Up @@ -564,3 +567,50 @@ def push_unique(self, fn: _TSignalHandlerFn) -> bool:
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"``)
"""

def _stringify_id(_id: int) -> str:
"""Return the cPU id as a string if an int, otherwise raise a ValueError"""
juliaputko marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(_id, int):
if _id < 0:
raise ValueError("CPU id must be a nonnegative number")
return str(_id)

raise TypeError(f"Argument is of type '{type(_id)}' not 'int'")
juliaputko marked this conversation as resolved.
Show resolved Hide resolved

try:
pin_ids = tuple(pin_ids) if pin_ids is not None else None
except TypeError:
raise TypeError(
"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(
"CPU pinning is not supported on MacOSX. Ignoring pinning "
"specification.",
RuntimeWarning,
)
return None

# 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}))
2 changes: 1 addition & 1 deletion smartsim/entity/dbnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
fs_identifier: str = "",
) -> None:
"""Initialize a feature store node within an feature store."""
super().__init__(name, run_settings)
super().__init__(name)

Check warning on line 67 in smartsim/entity/dbnode.py

View check run for this annotation

Codecov / codecov/patch

smartsim/entity/dbnode.py#L67

Added line #L67 was not covered by tests
juliaputko marked this conversation as resolved.
Show resolved Hide resolved
self.exe = [exe] if run_settings.container else [expand_exe_path(exe)]
self.exe_args = exe_args or []
self.ports = ports
Expand Down
8 changes: 1 addition & 7 deletions smartsim/entity/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,9 @@ def _create_applications(self) -> tuple[Application, ...]:
Application(
name=f"{self.name}-{i}",
exe=self.exe,
run_settings=_mock.Mock(),
# ^^^^^^^^^^^^^^^^^^^^^^^
# FIXME: remove this constructor arg! It should not exist!!
exe_args=self.exe_args,
files=self.files,
params=permutation.params,
params_as_args=permutation.exe_args, # type: ignore[arg-type]
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# FIXME: this is the wrong type on Application!
file_parameters=permutation.params,
)
for i, permutation in enumerate(permutations_)
)
Expand Down
6 changes: 2 additions & 4 deletions smartsim/entity/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,15 @@ def _on_disable(self) -> None:


class SmartSimEntity:
def __init__(self, name: str, run_settings: "RunSettings") -> None:
def __init__(self, name: str) -> None:
"""Initialize a SmartSim entity.

Each entity must have a name, path, and
run_settings. All entities within SmartSim
Each entity must have a name and path. All entities within SmartSim
share these attributes.

:param name: Name of the entity
"""
self.name = name
self.run_settings = run_settings

@property
def type(self) -> str:
Expand Down
Loading