Skip to content
Open
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
3 changes: 2 additions & 1 deletion exca/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ def _method_override(self, *args: tp.Any, **kwargs: tp.Any) -> tp.Iterator[tp.An
items = next(iter(kwargs.values()))
# specific function for thread and process pool executors
if self.cluster in [None, "threadpool", "processpool"]:
return self._method_override_futures(items)
with self._work_env():
return self._method_override_futures(items)
uid_func = imethod.item_uid
# we need to keep order for output:
uid_items = [(uid_func(item), item) for item in items]
Expand Down
5 changes: 3 additions & 2 deletions exca/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def model_post_init(self, log__: tp.Any) -> None:
f"cluster={self.cluster} requires a folder to be provided, "
"only cluster=None works without folder"
)
if self.workdir is not None:
if self.workdir is not None and self.workdir.folder is None:
raise ValueError("Workdir requires a folder")
if self.tasks_per_node > 1 and not self.slurm_use_srun:
if self.cluster in ["slurm", "auto"]:
Expand Down Expand Up @@ -205,7 +205,8 @@ def _work_env(self) -> tp.Iterator[None]:
if not isinstance(self, base.BaseInfra):
raise RuntimeError("SubmititMixin should be set a BaseInfra mixin")
with contextlib.ExitStack() as estack:
estack.enter_context(submitit.helpers.clean_env())
if self.executor is not None:
estack.enter_context(submitit.helpers.clean_env())
if self.workdir is not None:
if self.workdir.folder is None:
if self.folder is None:
Expand Down
3 changes: 2 additions & 1 deletion exca/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def job(self) -> submitit.Job[tp.Any] | LocalJob:
# submit job if it does not exist
executor = self.executor()
if executor is None:
job = LocalJob(self._run_method)
with self._work_env():
job = LocalJob(self._run_method)
job._name = self._factory() # for better logging message
else:
executor.folder.mkdir(exist_ok=True, parents=True)
Expand Down
12 changes: 12 additions & 0 deletions exca/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@ def test_tricky_update(tmp_path: Path) -> None:
assert isinstance(wxp.infra.workdir, WorkDir)


def test_workdir_no_cache(tmp_path: Path) -> None:
# pb in confdict for subconfig
infra: tp.Any = {
"folder": None,
"workdir": {"folder": tmp_path, "copied": [Path(__file__).parent]},
}
xp = Base(infra=infra)
assert xp.func() == 24
folders = [x.name for x in tmp_path.iterdir()]
assert folders == ["exca"]


def test_missing_base_model() -> None:
with pytest.raises(RuntimeError):

Expand Down
Loading