Skip to content

Commit 0a4388b

Browse files
committed
MPI: move hints/reqs + DockerRequirement checking into Process._init_job()
1 parent 7bce73a commit 0a4388b

File tree

3 files changed

+61
-42
lines changed

3 files changed

+61
-42
lines changed

Diff for: cwltool/command_line_tool.py

-22
Original file line numberDiff line numberDiff line change
@@ -431,28 +431,6 @@ def make_job_runner(self, runtimeContext: RuntimeContext) -> type[JobBase]:
431431
return SingularityCommandLineJob
432432
elif runtimeContext.user_space_docker_cmd:
433433
return UDockerCommandLineJob
434-
if mpiReq is not None:
435-
if mpiRequired:
436-
if dockerRequired:
437-
raise UnsupportedRequirement(
438-
"No support for Docker and MPIRequirement both being required"
439-
)
440-
else:
441-
_logger.warning(
442-
"MPI has been required while Docker is hinted, discarding Docker hint(s)"
443-
)
444-
self.hints = [h for h in self.hints if h["class"] != "DockerRequirement"]
445-
return CommandLineJob
446-
else:
447-
if dockerRequired:
448-
_logger.warning(
449-
"Docker has been required while MPI is hinted, discarding MPI hint(s)"
450-
)
451-
self.hints = [h for h in self.hints if h["class"] != MPIRequirementName]
452-
else:
453-
raise UnsupportedRequirement(
454-
"Both Docker and MPI have been hinted - don't know what to do"
455-
)
456434
if runtimeContext.podman:
457435
return PodmanCommandLineJob
458436
return DockerCommandLineJob

Diff for: cwltool/process.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,43 @@ def inc(d: list[int]) -> None:
810810
tmpdir = ""
811811
stagedir = ""
812812

813-
docker_req, _ = self.get_requirement("DockerRequirement")
813+
docker_req, docker_required = self.get_requirement("DockerRequirement")
814814
default_docker = None
815+
mpi_req, mpi_required = self.get_requirement(MPIRequirementName)
815816

816817
if docker_req is None and runtime_context.default_container:
817818
default_docker = runtime_context.default_container
818819

820+
if (
821+
docker_req is not None
822+
and runtime_context.use_container
823+
and not runtime_context.singularity
824+
and not runtime_context.user_space_docker_cmd
825+
and mpi_req is not None
826+
):
827+
if mpi_required:
828+
if docker_required:
829+
raise UnsupportedRequirement(
830+
"No support for Docker and MPIRequirement both being required"
831+
)
832+
else:
833+
_logger.warning(
834+
"MPI has been required while Docker is hinted, discarding Docker hint(s)"
835+
)
836+
self.hints = [h for h in self.hints if h["class"] != "DockerRequirement"]
837+
docker_req = None
838+
docker_required = False
839+
else:
840+
if docker_required:
841+
_logger.warning(
842+
"Docker has been required while MPI is hinted, discarding MPI hint(s)"
843+
)
844+
self.hints = [h for h in self.hints if h["class"] != MPIRequirementName]
845+
else:
846+
raise UnsupportedRequirement(
847+
"Both Docker and MPI have been hinted - don't know what to do"
848+
)
849+
819850
if (docker_req or default_docker) and runtime_context.use_container:
820851
if docker_req is not None:
821852
# Check if docker output directory is absolute

Diff for: tests/test_mpi.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
import pytest
1313
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1414
from schema_salad.avro.schema import Names
15+
from schema_salad.ref_resolver import file_uri
1516
from schema_salad.utils import yaml_no_ts
1617

1718
import cwltool.load_tool
1819
import cwltool.singularity
1920
import cwltool.udocker
20-
from cwltool.command_line_tool import CommandLineTool
21-
from cwltool.context import LoadingContext, RuntimeContext
21+
from cwltool.context import RuntimeContext
2222
from cwltool.main import main
2323
from cwltool.mpi import MpiConfig, MPIRequirementName
24+
from cwltool.process import Process
2425

2526
from .util import get_data, working_directory
2627

@@ -292,15 +293,22 @@ def schema_ext11() -> Generator[Names, None, None]:
292293

293294
mpiReq = CommentedMap({"class": MPIRequirementName, "processes": 1})
294295
containerReq = CommentedMap({"class": "DockerRequirement"})
295-
basetool = CommentedMap({"cwlVersion": "v1.1", "inputs": CommentedSeq(), "outputs": CommentedSeq()})
296+
basetool = CommentedMap(
297+
{
298+
"cwlVersion": "v1.1",
299+
"class": "CommandLineTool",
300+
"inputs": CommentedSeq(),
301+
"outputs": CommentedSeq(),
302+
}
303+
)
296304

297305

298306
def mk_tool(
299307
schema: Names,
300308
opts: list[str],
301309
reqs: Optional[list[CommentedMap]] = None,
302310
hints: Optional[list[CommentedMap]] = None,
303-
) -> tuple[LoadingContext, RuntimeContext, CommentedMap]:
311+
) -> tuple[RuntimeContext, Process]:
304312
tool = basetool.copy()
305313

306314
if reqs is not None:
@@ -313,50 +321,52 @@ def mk_tool(
313321
rc = RuntimeContext(vars(args))
314322
lc = cwltool.main.setup_loadingContext(None, rc, args)
315323
lc.avsc_names = schema
316-
return lc, rc, tool
324+
tool["id"] = file_uri(os.path.abspath("./mktool.cwl"))
325+
lc.loader.idx[tool["id"]] = tool
326+
return rc, cwltool.load_tool.load_tool(tool, lc)
317327

318328

319329
def test_singularity(schema_ext11: Names) -> None:
320-
lc, rc, tool = mk_tool(schema_ext11, ["--singularity"], reqs=[mpiReq, containerReq])
321-
clt = CommandLineTool(tool, lc)
330+
rc, clt = mk_tool(schema_ext11, ["--singularity"], reqs=[mpiReq, containerReq])
331+
clt._init_job({}, rc)
322332
jr = clt.make_job_runner(rc)
323333
assert jr is cwltool.singularity.SingularityCommandLineJob
324334

325335

326336
def test_udocker(schema_ext11: Names) -> None:
327-
lc, rc, tool = mk_tool(schema_ext11, ["--udocker"], reqs=[mpiReq, containerReq])
328-
clt = CommandLineTool(tool, lc)
337+
rc, clt = mk_tool(schema_ext11, ["--udocker"], reqs=[mpiReq, containerReq])
338+
clt._init_job({}, rc)
329339
jr = clt.make_job_runner(rc)
330340
assert jr is cwltool.udocker.UDockerCommandLineJob
331341

332342

333343
def test_docker_hint(schema_ext11: Names) -> None:
334344
# Docker hint, MPI required
335-
lc, rc, tool = mk_tool(schema_ext11, [], hints=[containerReq], reqs=[mpiReq])
336-
clt = CommandLineTool(tool, lc)
345+
rc, clt = mk_tool(schema_ext11, [], hints=[containerReq], reqs=[mpiReq])
346+
clt._init_job({}, rc)
337347
jr = clt.make_job_runner(rc)
338348
assert jr is cwltool.job.CommandLineJob
339349

340350

341351
def test_docker_required(schema_ext11: Names) -> None:
342352
# Docker required, MPI hinted
343-
lc, rc, tool = mk_tool(schema_ext11, [], reqs=[containerReq], hints=[mpiReq])
344-
clt = CommandLineTool(tool, lc)
353+
rc, clt = mk_tool(schema_ext11, [], reqs=[containerReq], hints=[mpiReq])
354+
clt._init_job({}, rc)
345355
jr = clt.make_job_runner(rc)
346356
assert jr is cwltool.docker.DockerCommandLineJob
347357

348358

349359
def test_docker_mpi_both_required(schema_ext11: Names) -> None:
350360
# Both required - error
351-
lc, rc, tool = mk_tool(schema_ext11, [], reqs=[mpiReq, containerReq])
352-
clt = CommandLineTool(tool, lc)
361+
rc, clt = mk_tool(schema_ext11, [], reqs=[mpiReq, containerReq])
353362
with pytest.raises(cwltool.errors.UnsupportedRequirement):
354-
clt.make_job_runner(rc)
363+
clt._init_job({}, rc)
364+
clt.make_job_runner(rc)
355365

356366

357367
def test_docker_mpi_both_hinted(schema_ext11: Names) -> None:
358368
# Both hinted - error
359-
lc, rc, tool = mk_tool(schema_ext11, [], hints=[mpiReq, containerReq])
360-
clt = CommandLineTool(tool, lc)
369+
rc, clt = mk_tool(schema_ext11, [], hints=[mpiReq, containerReq])
361370
with pytest.raises(cwltool.errors.UnsupportedRequirement):
362-
clt.make_job_runner(rc)
371+
clt._init_job({}, rc)
372+
clt.make_job_runner(rc)

0 commit comments

Comments
 (0)