From c4f37133a5b3d6a12663a948d7d3d76c5547632c Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 24 Jan 2025 14:31:47 -0800 Subject: [PATCH] BUG: Fix case where `SlurmExecutor.finalize()` is called but no work (#256) --- adaptive_scheduler/_executor.py | 11 ++++++++--- readthedocs.yml | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/adaptive_scheduler/_executor.py b/adaptive_scheduler/_executor.py index 9c1b9ee4..adecd605 100644 --- a/adaptive_scheduler/_executor.py +++ b/adaptive_scheduler/_executor.py @@ -36,8 +36,11 @@ def submit(self, fn: Callable[..., Any], /, *args: Any, **kwargs: Any) -> Future """Submit a task to the executor.""" @abc.abstractmethod - def finalize(self, *, start: bool = True) -> adaptive_scheduler.RunManager: - """Finalize the executor and return the RunManager.""" + def finalize(self, *, start: bool = True) -> adaptive_scheduler.RunManager | None: + """Finalize the executor and return the RunManager. + + Returns None if no learners were submitted. + """ def map( # type: ignore[override] self, @@ -408,11 +411,13 @@ def _to_learners(self) -> tuple[list[SequenceLearner], list[Path]]: fnames.append(self.folder / f"{name}-{i}-{uuid.uuid4().hex}.pickle") return learners, fnames - def finalize(self, *, start: bool = True) -> adaptive_scheduler.RunManager: + def finalize(self, *, start: bool = True) -> adaptive_scheduler.RunManager | None: if self._run_manager is not None: msg = "RunManager already initialized. Create a new SlurmExecutor instance." raise RuntimeError(msg) learners, fnames = self._to_learners() + if not learners: + return None assert self.folder is not None self._run_manager = adaptive_scheduler.slurm_run( learners=learners, diff --git a/readthedocs.yml b/readthedocs.yml index 23fab10c..07c7a10a 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -5,5 +5,8 @@ build: tools: python: "mambaforge-4.10" +sphinx: + configuration: docs/source/conf.py + conda: environment: docs/environment.yml