Skip to content

Commit 318bd7c

Browse files
committed
[OAR] correct check_format and lint CI tests
1 parent e9afae1 commit 318bd7c

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

submitit/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from .local.debug import DebugJob as DebugJob
1616
from .local.local import LocalExecutor as LocalExecutor
1717
from .local.local import LocalJob as LocalJob
18-
from .slurm.slurm import SlurmExecutor as SlurmExecutor
19-
from .slurm.slurm import SlurmJob as SlurmJob
2018
from .oar.oar import OarExecutor as OarExecutor
2119
from .oar.oar import OarJob as OarJob
20+
from .slurm.slurm import SlurmExecutor as SlurmExecutor
21+
from .slurm.slurm import SlurmJob as SlurmJob
2222

2323
__version__ = "1.4.6"

submitit/auto/test_auto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import pytest
1111

1212
from ..local import debug
13-
from ..slurm import test_slurm
1413
from ..oar import test_oar
14+
from ..slurm import test_slurm
1515
from . import auto
1616

1717

@@ -39,6 +39,7 @@ def test_slurm_executor(tmp_path: Path, monkeypatch) -> None:
3939
with pytest.raises(NameError, match=r"debug_blublu.*\n.*local_num_threads"):
4040
executor.update_parameters(debug_blublu=2.0, local_num_threads=4)
4141

42+
4243
def test_oar_executor(tmp_path: Path, monkeypatch) -> None:
4344
monkeypatch.setattr(debug.DebugExecutor, "_valid_parameters", lambda: {"blabla"})
4445
with test_oar.mocked_oar():

submitit/core/plugins.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@ def _get_plugins() -> Tuple[List[Type["Executor"]], List["JobEnvironment"]]:
2424
import pkg_resources
2525

2626
from ..local import debug, local
27-
from ..slurm import slurm
2827
from ..oar import oar
28+
from ..slurm import slurm
2929

3030
# TODO: use sys.modules.keys() and importlib.resources to find the files
3131
# We load both kind of entry points at the same time because we have to go through all module files anyway.
32-
executors: List[Type["Executor"]] = [slurm.SlurmExecutor, local.LocalExecutor, debug.DebugExecutor, oar.OarExecutor]
33-
job_envs = [slurm.SlurmJobEnvironment(), local.LocalJobEnvironment(), debug.DebugJobEnvironment(), oar.OarJobEnvironment()]
32+
executors: List[Type["Executor"]] = [
33+
slurm.SlurmExecutor,
34+
local.LocalExecutor,
35+
debug.DebugExecutor,
36+
oar.OarExecutor,
37+
]
38+
job_envs = [
39+
slurm.SlurmJobEnvironment(),
40+
local.LocalJobEnvironment(),
41+
debug.DebugJobEnvironment(),
42+
oar.OarJobEnvironment(),
43+
]
3444
for entry_point in pkg_resources.iter_entry_points("submitit"):
3545
if entry_point.name not in ("executor", "job_environment"):
3646
logger.warning(f"Found unknown entry point in package {entry_point.module_name}: {entry_point}")

submitit/oar/oar.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OarInfoWatcher(core.InfoWatcher):
3838
}
3939

4040
def _make_command(self) -> tp.Optional[tp.List[str]]:
41-
to_check = {x for x in self._registered - self._finished}
41+
to_check = set(self._registered - self._finished)
4242
if not to_check:
4343
return None
4444
command = ["oarstat", "-f", "-J"]
@@ -88,7 +88,7 @@ def __init__(self, folder: tp.Union[Path, str], job_id: str, tasks: tp.Sequence[
8888
if len(tasks) > 1:
8989
raise NotImplementedError
9090
super().__init__(folder, job_id, tasks)
91-
self._resubmitted_job = None
91+
self._resubmitted_job: tp.Optional[OarJob[core.R]] = None
9292

9393
def _interrupt(self, timeout: bool = False) -> None:
9494
"""Sends preemption or timeout signal to the job (for testing purpose)
@@ -174,8 +174,6 @@ def _get_resubmitted_job(self) -> tp.Optional["OarJob[core.R]"]:
174174
folder=self._paths.folder, job_id=resubmitted_job_id, tasks=[0]
175175
)
176176
return self._resubmitted_job
177-
else:
178-
return None
179177
except Exception as e:
180178
logger.get_logger().error(
181179
f"Getting error with _get_resubmitted_job() by command {command}:\n"
@@ -259,7 +257,7 @@ def _internal_update_parameters(self, **kwargs: tp.Any) -> None:
259257
Parameters
260258
----------
261259
See oar documentation for most parameters.
262-
Most useful parameters are: core, walltime, gpu, queue.
260+
Most useful parameters are: cores, walltime, gpu, queue.
263261
264262
Below are the parameters that differ from OAR documentation:
265263
@@ -326,7 +324,7 @@ def _internal_process_submissions(
326324
if any(isinstance(d.function, helpers.Checkpointable) for d in delayed_submissions) and any(
327325
not isinstance(d.function, helpers.Checkpointable) for d in delayed_submissions
328326
):
329-
raise Exception(
327+
raise ValueError(
330328
"OarExecutor does not support a job array that mixes checkpointable and non-checkpointable functions."
331329
"\nPlease make groups of similar function calls in the job array."
332330
)
@@ -434,7 +432,7 @@ def _make_oarsub_string(
434432
folder: tp.Union[str, Path],
435433
map_count: tp.Optional[int] = None, # used internally
436434
nodes: tp.Optional[int] = None,
437-
core: tp.Optional[int] = None,
435+
cores: tp.Optional[int] = None,
438436
gpu: tp.Optional[int] = None,
439437
walltime: tp.Optional[str] = None,
440438
timeout_min: tp.Optional[int] = None,
@@ -449,7 +447,7 @@ def _make_oarsub_string(
449447
Parameters
450448
----------
451449
See oar documentation for most parameters.
452-
Most useful parameters are: core, walltime, gpu, queue.
450+
Most useful parameters are: cores, walltime, gpu, queue.
453451
454452
Below are the parameters that differ from OAR documentation:
455453
@@ -474,13 +472,13 @@ def _make_oarsub_string(
474472
# OAR resource hierarchy: nodes > gpu > core
475473
resource_hierarchy = ""
476474
if nodes is not None:
477-
resource_hierarchy += "/nodes=%d" % nodes
475+
resource_hierarchy += f"/nodes={nodes}"
478476
if gpu is not None:
479-
resource_hierarchy += "/gpu=%d" % gpu
480-
if core is not None:
481-
resource_hierarchy += "/core=%d" % core
477+
resource_hierarchy += f"/gpu={gpu}"
478+
if cores is not None:
479+
resource_hierarchy += f"/core={cores}"
482480
if walltime is not None:
483-
walltime = "walltime=%s" % walltime
481+
walltime = f"walltime={walltime}"
484482
resource_request = ",".join(filter(None, (resource_hierarchy, walltime)))
485483
if resource_request:
486484
parameters["l"] = resource_request

submitit/oar/test_oar.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from . import oar
2222

2323

24-
# pylint: disable=no-self-use
2524
class MockedSubprocess:
2625
"""Helper for mocking subprocess calls"""
2726

@@ -46,6 +45,7 @@ def __call__(self, command: tp.Sequence[str], **kwargs: tp.Any) -> bytes:
4645
def oarstat(self, _: tp.Sequence[str]) -> str:
4746
return "\n".join(self.job_oarstat.values())
4847

48+
# pylint: disable=unused-argument
4949
def oarsub(self, args: tp.Sequence[str]) -> str:
5050
"""Create a "RUNNING" job."""
5151
job_id = str(self.job_count)
@@ -159,6 +159,7 @@ def test_oar_job_mocked(tmp_path: Path) -> None:
159159
assert "_USELESS_TEST_ENV_VAR_" not in os.environ, "Test context manager seems to be failing"
160160

161161

162+
# pylint: disable=too-many-locals
162163
@pytest.mark.parametrize("use_batch_api", (False, True)) # type: ignore
163164
def test_oar_job_array_mocked(use_batch_api: bool, tmp_path: Path) -> None:
164165
n = 5
@@ -271,6 +272,10 @@ def test_requeuing_checkpointable(tmp_path: Path, fast_forward_clock) -> None:
271272
submitted_pkl_13 = tmp_path / "13_submitted.pkl"
272273
assert not submitted_pkl_13.exists()
273274

275+
# The job 12 is terminated, but the resubmitted job 13 is still running
276+
# The job should not be done
277+
assert job.done(force_check=False) is False
278+
274279
# This time the job as timed out,
275280
# but we have max_num_timeout=1, so we should requeue.
276281
# We are a little bit under the requested timedout, but close enough
@@ -288,6 +293,8 @@ def test_requeuing_checkpointable(tmp_path: Path, fast_forward_clock) -> None:
288293
utils.UncompletedJobError, match="timed-out too many times."
289294
):
290295
sig.checkpoint_and_try_requeue(usr_sig)
296+
# This time the job should be done
297+
assert job.done(force_check=False) is True
291298

292299

293300
def test_requeuing_not_checkpointable(tmp_path: Path, fast_forward_clock) -> None:
@@ -376,7 +383,7 @@ def test_make_oarsub_string_gpu() -> None:
376383

377384

378385
def test_make_oarsub_string_core() -> None:
379-
string = oar._make_oarsub_string(command="blublu", folder="/tmp", core=2)
386+
string = oar._make_oarsub_string(command="blublu", folder="/tmp", cores=2)
380387
assert "-l /core=2" in string
381388

382389

@@ -385,13 +392,13 @@ def test_make_oarsub_string_gpu_and_nodes() -> None:
385392
assert "-l /nodes=1/gpu=2" in string
386393

387394

388-
def test_make_oarsub_string_core_and_nodes() -> None:
389-
string = oar._make_oarsub_string(command="blublu", folder="/tmp", core=2, nodes=1)
395+
def test_make_oarsub_string_cores_and_nodes() -> None:
396+
string = oar._make_oarsub_string(command="blublu", folder="/tmp", cores=2, nodes=1)
390397
assert "-l /nodes=1/core=2" in string
391398

392399

393-
def test_make_oarsub_string_core_gpu_and_nodes() -> None:
394-
string = oar._make_oarsub_string(command="blublu", folder="/tmp", gpu=2, nodes=1, core=4)
400+
def test_make_oarsub_string_cores_gpu_and_nodes() -> None:
401+
string = oar._make_oarsub_string(command="blublu", folder="/tmp", gpu=2, nodes=1, cores=4)
395402
assert "-l /nodes=1/gpu=2/core=4" in string
396403

397404

0 commit comments

Comments
 (0)