Skip to content

Commit

Permalink
updates to adapt to ensemble
Browse files Browse the repository at this point in the history
  • Loading branch information
amandarichardsonn committed Jul 17, 2024
1 parent bfb90d4 commit 08b487f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
35 changes: 22 additions & 13 deletions smartsim/_core/generation/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,29 @@ def __init__(self, gen_path: str, run_ID: str, job: Job) -> None:
"""
self.job = job
# TODO revisit this check
if isinstance(job, (Job, JobGroup)):
if job._ensemble_name is None:
job_type = f"{job.__class__.__name__.lower()}s"
entity_type = f"{job.entity.__class__.__name__.lower()}-{create_short_id_str()}"
self.path = os.path.join(
gen_path,
run_ID,
job_type,
f"{job.name}-{create_short_id_str()}",
entity_type,
"run",
)
entity_type = f"{job.entity.__class__.__name__.lower()}-{create_short_id_str()}"
self.path = os.path.join(
gen_path,
run_ID,
job_type,
f"{job.name}-{create_short_id_str()}",
entity_type,
"run",
)
else:
job_type = "ensembles"
entity_type = f"{job.entity.__class__.__name__.lower()}-{create_short_id_str()}"
self.path = os.path.join(
gen_path,
run_ID,
job_type,
job._ensemble_name,
f"{job.name}",
entity_type,
"run",
)

@property
def log_level(self) -> int:
Expand Down Expand Up @@ -130,9 +142,6 @@ def generate_experiment(self) -> str:
"""
pathlib.Path(self.path).mkdir(exist_ok=True, parents=True)
# logger.log(
# level=self.log_level, msg="Working in experiment "
# )

# The log_file only keeps track of the last generation
# this is to avoid gigantic files in case the user repeats
Expand Down
2 changes: 1 addition & 1 deletion smartsim/entity/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ def as_jobs(self, settings: LaunchSettings) -> tuple[Job, ...]:
apps = self._create_applications()
if not apps:
raise ValueError("There are no members as part of this ensemble")
return tuple(Job(app, settings) for app in apps)
return tuple(Job(app, settings, f"job_{i}", ensemble_name=self.name) for i, app in enumerate(apps, 1))
5 changes: 5 additions & 0 deletions smartsim/launchable/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from smartsim._core.commands.launchCommands import LaunchCommands
from smartsim.launchable.basejob import BaseJob
from smartsim.settings import LaunchSettings
from smartsim._core.utils.helpers import create_short_id_str

if t.TYPE_CHECKING:
from smartsim.entity.entity import SmartSimEntity
Expand All @@ -51,11 +52,15 @@ def __init__(
entity: SmartSimEntity,
launch_settings: LaunchSettings,
name: str = "job",
**kwargs: t.Any,
):
super().__init__()
self._entity = deepcopy(entity)
self._launch_settings = deepcopy(launch_settings)
self._name = deepcopy(name)
self._ensemble_name = kwargs.get('ensemble_name', None)
if self._ensemble_name is not None:
self._ensemble_name += f"-{create_short_id_str()}"
# TODO: self.warehouse_runner = JobWarehouseRunner

# TODO do we want the user to be allowed to reset the Job name? Therefore, add setter
Expand Down
13 changes: 12 additions & 1 deletion tests/test_generator/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from smartsim import Experiment
from smartsim._core.generation.generator import Generator
from smartsim.entity.model import Application
from smartsim.entity import Application, Ensemble
from smartsim.launchable import Job, JobGroup
from smartsim.settings.builders.launch import SlurmArgBuilder
from smartsim.settings.dispatch import Dispatcher
Expand Down Expand Up @@ -97,3 +97,14 @@ def test_full_exp_generate_job_directory(test_dir, job_instance):
)
job_execution_path = no_op_exp._generate(job_instance)
assert osp.isdir(job_execution_path)

def test_generate_ensemble_directory(test_dir, wlmutils):
ensemble = Ensemble("ensemble-name", "echo", replicas=2)
launch_settings = LaunchSettings(wlmutils.get_test_launcher())
job_list = ensemble.as_jobs(launch_settings)
for job in job_list:
run_ID = "temp_run"
gen = Generator(gen_path=test_dir, run_ID=run_ID, job=job)
print(gen.path)


0 comments on commit 08b487f

Please sign in to comment.