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

Renaming Model to Application #579

Merged
merged 14 commits into from
May 30, 2024
24 changes: 12 additions & 12 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from smartsim._core.config.config import Config
from smartsim._core.utils.telemetry.telemetry import JobEntity
from smartsim.database import Orchestrator
from smartsim.entity import Model
from smartsim.entity import Application
from smartsim.error import SSConfigError, SSInternalError
from smartsim.log import get_logger
from smartsim.settings import (
Expand Down Expand Up @@ -654,10 +654,10 @@ def setup_test_colo(
application_file: str,
db_args: t.Dict[str, t.Any],
colo_settings: t.Optional[RunSettings] = None,
colo_model_name: str = "colocated_model",
colo_application_name: str = "colocated_application",
port: t.Optional[int] = None,
on_wlm: bool = False,
) -> Model:
) -> Application:
"""Setup database needed for the colo pinning tests"""

# get test setup
Expand All @@ -672,31 +672,31 @@ def setup_test_colo(
colo_settings.set_tasks(1)
colo_settings.set_nodes(1)

colo_model = exp.create_model(colo_model_name, colo_settings)
colo_application = exp.create_application(colo_application_name, colo_settings)

if db_type in ["tcp", "deprecated"]:
db_args["port"] = port if port is not None else _find_free_port(test_ports)
db_args["ifname"] = "lo"
if db_type == "uds" and colo_model_name is not None:
if db_type == "uds" and colo_application_name is not None:
tmp_dir = tempfile.gettempdir()
socket_suffix = str(uuid.uuid4())[:7]
socket_name = f"{colo_model_name}_{socket_suffix}.socket"
socket_name = f"{colo_application_name}_{socket_suffix}.socket"
db_args["unix_socket"] = os.path.join(tmp_dir, socket_name)

colocate_fun: t.Dict[str, t.Callable[..., None]] = {
"tcp": colo_model.colocate_db_tcp,
"deprecated": colo_model.colocate_db,
"uds": colo_model.colocate_db_uds,
"tcp": colo_application.colocate_db_tcp,
"deprecated": colo_application.colocate_db,
"uds": colo_application.colocate_db_uds,
}
with warnings.catch_warnings():
if db_type == "deprecated":
message = "`colocate_db` has been deprecated"
warnings.filterwarnings("ignore", message=message)
colocate_fun[db_type](**db_args)
# assert model will launch with colocated db
assert colo_model.colocated
# assert application will launch with colocated db
assert colo_application.colocated
# Check to make sure that limit_db_cpus made it into the colo settings
return colo_model
return colo_application


@pytest.fixture(scope="function")
Expand Down
48 changes: 24 additions & 24 deletions smartsim/_core/control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
shutdown_db_node,
)
from ...database import Orchestrator
from ...entity import Ensemble, EntitySequence, Model, SmartSimEntity
from ...entity import Ensemble, EntitySequence, Application, SmartSimEntity
from ...error import (
LauncherError,
SmartSimError,
Expand Down Expand Up @@ -224,7 +224,7 @@ def stop_entity(
if job.status not in TERMINAL_STATUSES:
logger.info(
" ".join(
("Stopping model", entity.name, "with job name", str(job.name))
("Stopping application", entity.name, "with job name", str(job.name))
)
)
status = self._launcher.stop(job.name)
Expand Down Expand Up @@ -445,7 +445,7 @@ def _launch(
)

# symlink substeps to maintain directory structure
for substep, substep_entity in zip(substeps, elist.models):
for substep, substep_entity in zip(substeps, elist.applications):
symlink_substeps.append((substep, substep_entity))

steps.append((batch_step, elist))
Expand All @@ -459,24 +459,24 @@ def _launch(
elist, [(step.name, step) for step, _ in job_steps]
)
steps.extend(job_steps)
# models themselves cannot be batch steps. If batch settings are
# applications themselves cannot be batch steps. If batch settings are
# attached, wrap them in an anonymous batch job step
for model in manifest.models:
model_telem_dir = manifest_builder.run_telemetry_subdirectory / "model"
if model.batch_settings:
anon_entity_list = _AnonymousBatchJob(model)
for application in manifest.applications:
application_telem_dir = manifest_builder.run_telemetry_subdirectory / "application"
if application.batch_settings:
anon_entity_list = _AnonymousBatchJob(application)
batch_step, substeps = self._create_batch_job_step(
anon_entity_list, model_telem_dir
anon_entity_list, application_telem_dir
)
manifest_builder.add_model(model, (batch_step.name, batch_step))
manifest_builder.add_application(application, (batch_step.name, batch_step))

symlink_substeps.append((substeps[0], model))
steps.append((batch_step, model))
symlink_substeps.append((substeps[0], application))
steps.append((batch_step, application))
else:
# create job step for a model with run settings
job_step = self._create_job_step(model, model_telem_dir)
manifest_builder.add_model(model, (job_step.name, job_step))
steps.append((job_step, model))
# create job step for aapplication with run settings
job_step = self._create_job_step(application, application_telem_dir)
manifest_builder.add_application(application, (job_step.name, job_step))
steps.append((job_step, application))

# launch and symlink steps
for step, entity in steps:
Expand Down Expand Up @@ -670,7 +670,7 @@ def _create_job_step(
:return: the job step
"""
# get SSDB, SSIN, SSOUT and add to entity run settings
if isinstance(entity, Model):
if isinstance(entity, Application):
self._prep_entity_client_env(entity)

# creating job step through the created launcher
Expand All @@ -682,7 +682,7 @@ def _create_job_step(
# return the job step that was created using the launcher since the launcher is defined in the exp
return step

def _prep_entity_client_env(self, entity: Model) -> None:
def _prep_entity_client_env(self, entity: Application) -> None:
"""Retrieve all connections registered to this entity

:param entity: The entity to retrieve connections from
Expand All @@ -708,7 +708,7 @@ def _prep_entity_client_env(self, entity: Model) -> None:
if entity.query_key_prefixing():
client_env["SSKEYOUT"] = entity.name

# Set address to local if it's a colocated model
# Set address to local if it's a colocated application
if entity.colocated and entity.run_settings.colocated_db_settings is not None:
db_name_colo = entity.run_settings.colocated_db_settings["db_identifier"]
assert isinstance(db_name_colo, str)
Expand Down Expand Up @@ -899,19 +899,19 @@ def _set_dbobjects(self, manifest: Manifest) -> None:
options = ConfigOptions.create_from_environment(name)
client = Client(options, logger_name="SmartSim")

for model in manifest.models:
if not model.colocated:
for db_model in model.db_models:
for application in manifest.applications:
if not application.colocated:
for db_model in application.db_models:
set_ml_model(db_model, client)
for db_script in model.db_scripts:
for db_script in application.db_scripts:
set_script(db_script, client)

for ensemble in manifest.ensembles:
for db_model in ensemble.db_models:
set_ml_model(db_model, client)
for db_script in ensemble.db_scripts:
set_script(db_script, client)
for entity in ensemble.models:
for entity in ensemble.applications:
if not entity.colocated:
# Set models which could belong only
# to the entities and not to the ensemble
Expand Down
18 changes: 9 additions & 9 deletions smartsim/_core/control/controller_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
import typing as t

from ..._core.launcher.step import Step
from ...entity import EntityList, Model
from ...entity import EntityList, Application
from ...error import SmartSimError
from ..launcher.launcher import Launcher

if t.TYPE_CHECKING:
from ..utils.serialize import TStepLaunchMetaData


class _AnonymousBatchJob(EntityList[Model]):
class _AnonymousBatchJob(EntityList[Application]):
@staticmethod
def _validate(model: Model) -> None:
if model.batch_settings is None:
def _validate(application: Application) -> None:
if application.batch_settings is None:
msg = "Unable to create _AnonymousBatchJob without batch_settings"
raise SmartSimError(msg)

def __init__(self, model: Model) -> None:
self._validate(model)
super().__init__(model.name, model.path)
self.entities = [model]
self.batch_settings = model.batch_settings
def __init__(self, application: Application) -> None:
self._validate(application)
super().__init__(application.name, application.path)
self.entities = [application]
self.batch_settings = application.batch_settings

def _initialize_entities(self, **kwargs: t.Any) -> None: ...

Expand Down
60 changes: 30 additions & 30 deletions smartsim/_core/control/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
from dataclasses import dataclass, field

from ...database import Orchestrator
from ...entity import DBNode, Ensemble, EntitySequence, Model, SmartSimEntity
from ...entity import DBNode, Ensemble, EntitySequence, Application, SmartSimEntity
from ...error import SmartSimError
from ..config import CONFIG
from ..utils import helpers as _helpers
from ..utils import serialize as _serialize

_T = t.TypeVar("_T")
_U = t.TypeVar("_U")
_AtomicLaunchableT = t.TypeVar("_AtomicLaunchableT", Model, DBNode)
_AtomicLaunchableT = t.TypeVar("_AtomicLaunchableT", Application, DBNode)

if t.TYPE_CHECKING:
import os
Expand All @@ -50,7 +50,7 @@ class Manifest:
`SmartSimEntity`-derived objects or `EntitySequence`-derived objects) can
be accessed by using the corresponding accessor.

Instances of ``Model``, ``Ensemble`` and ``Orchestrator``
Instances of ``Application``, ``Ensemble`` and ``Orchestrator``
can all be passed as arguments
"""

Expand All @@ -73,15 +73,15 @@ def dbs(self) -> t.List[Orchestrator]:
return dbs

@property
def models(self) -> t.List[Model]:
"""Return Model instances in Manifest
def applications(self) -> t.List[Application]:
"""Return Application instances in Manifest

:return: model instances
:return: application instances
"""
_models: t.List[Model] = [
item for item in self._deployables if isinstance(item, Model)
_applications: t.List[Application] = [
item for item in self._deployables if isinstance(item, Application)
]
return _models
return _applications

@property
def ensembles(self) -> t.List[Ensemble]:
Expand Down Expand Up @@ -143,7 +143,7 @@ def _check_entity_lists_nonempty(self) -> None:
def __str__(self) -> str:
output = ""
e_header = "=== Ensembles ===\n"
m_header = "=== Models ===\n"
m_header = "=== Applications ===\n"
db_header = "=== Database ===\n"
if self.ensembles:
output += e_header
Expand All @@ -157,15 +157,15 @@ def __str__(self) -> str:
output += f"{str(ensemble.batch_settings)}\n"
output += "\n"

if self.models:
if self.applications:
output += m_header
for model in self.models:
output += f"{model.name}\n"
if model.batch_settings:
output += f"{model.batch_settings}\n"
output += f"{model.run_settings}\n"
if model.params:
output += f"Parameters: \n{_helpers.fmt_dict(model.params)}\n"
for application in self.applications:
output += f"{application.name}\n"
if application.batch_settings:
output += f"{application.batch_settings}\n"
output += f"{application.run_settings}\n"
if application.params:
output += f"Parameters: \n{_helpers.fmt_dict(application.params)}\n"
output += "\n"

for adb in self.dbs:
Expand All @@ -183,8 +183,8 @@ def __str__(self) -> str:
@property
def has_db_objects(self) -> bool:
"""Check if any entity has DBObjects to set"""
ents: t.Iterable[t.Union[Model, Ensemble]] = itertools.chain(
self.models,
ents: t.Iterable[t.Union[Application, Ensemble]] = itertools.chain(
self.applications,
self.ensembles,
(member for ens in self.ensembles for member in ens.entities),
)
Expand Down Expand Up @@ -220,8 +220,8 @@ class LaunchedManifest(t.Generic[_T]):
"""

metadata: _LaunchedManifestMetadata
models: t.Tuple[t.Tuple[Model, _T], ...]
ensembles: t.Tuple[t.Tuple[Ensemble, t.Tuple[t.Tuple[Model, _T], ...]], ...]
applications: t.Tuple[t.Tuple[Application, _T], ...]
ensembles: t.Tuple[t.Tuple[Ensemble, t.Tuple[t.Tuple[Application, _T], ...]], ...]
databases: t.Tuple[t.Tuple[Orchestrator, t.Tuple[t.Tuple[DBNode, _T], ...]], ...]

def map(self, func: t.Callable[[_T], _U]) -> "LaunchedManifest[_U]":
Expand All @@ -233,10 +233,10 @@ def _map_entity_data(

return LaunchedManifest(
metadata=self.metadata,
models=_map_entity_data(func, self.models),
applications=_map_entity_data(func, self.applications),
ensembles=tuple(
(ens, _map_entity_data(func, model_data))
for ens, model_data in self.ensembles
(ens, _map_entity_data(func, application_data))
for ens, application_data in self.ensembles
),
databases=tuple(
(db_, _map_entity_data(func, node_data))
Expand All @@ -257,8 +257,8 @@ class LaunchedManifestBuilder(t.Generic[_T]):
launcher_name: str
run_id: str = field(default_factory=_helpers.create_short_id_str)

_models: t.List[t.Tuple[Model, _T]] = field(default_factory=list, init=False)
_ensembles: t.List[t.Tuple[Ensemble, t.Tuple[t.Tuple[Model, _T], ...]]] = field(
_applications: t.List[t.Tuple[Application, _T]] = field(default_factory=list, init=False)
_ensembles: t.List[t.Tuple[Ensemble, t.Tuple[t.Tuple[Application, _T], ...]]] = field(
default_factory=list, init=False
)
_databases: t.List[t.Tuple[Orchestrator, t.Tuple[t.Tuple[DBNode, _T], ...]]] = (
Expand All @@ -273,8 +273,8 @@ def exp_telemetry_subdirectory(self) -> pathlib.Path:
def run_telemetry_subdirectory(self) -> pathlib.Path:
return _format_run_telemetry_path(self.exp_path, self.exp_name, self.run_id)

def add_model(self, model: Model, data: _T) -> None:
self._models.append((model, data))
def add_application(self, application: Application, data: _T) -> None:
self._applications.append((application, data))

def add_ensemble(self, ens: Ensemble, data: t.Sequence[_T]) -> None:
self._ensembles.append((ens, self._entities_to_data(ens.entities, data)))
Expand Down Expand Up @@ -303,7 +303,7 @@ def finalize(self) -> LaunchedManifest[_T]:
self.exp_path,
self.launcher_name,
),
models=tuple(self._models),
applications=tuple(self._applications),
ensembles=tuple(self._ensembles),
databases=tuple(self._databases),
)
Expand Down
2 changes: 1 addition & 1 deletion smartsim/_core/entrypoints/indirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(

:param cmd: a base64 encoded cmd to execute
:param entity_type: `SmartSimEntity` entity class. Valid values
include: orchestrator, dbnode, ensemble, model
include: orchestrator, dbnode, ensemble, application
:param cwd: working directory to execute the cmd from
:param status_dir: path to the output directory for status updates
"""
Expand Down
Loading
Loading