Skip to content

Commit

Permalink
Merge branch 'main' into podman-volume-777
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricebrito authored Sep 10, 2021
2 parents 229ac35 + ffb7513 commit 5e27d91
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cwltool/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(
names: Names,
requirements: List[CWLObjectType],
hints: List[CWLObjectType],
resources: Dict[str, Union[int, float, str]],
resources: Dict[str, Union[int, float]],
mutation_manager: Optional[MutationManager],
formatgraph: Optional[Graph],
make_fs_access: Type[StdFsAccess],
Expand Down
4 changes: 2 additions & 2 deletions cwltool/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class RuntimeContext(ContextBase):
def __init__(self, kwargs: Optional[Dict[str, Any]] = None) -> None:
"""Initialize the RuntimeContext from the kwargs."""
select_resources_callable = Callable[ # pylint: disable=unused-variable
[Dict[str, Union[int, float, str]], RuntimeContext],
Dict[str, Union[int, float, str]],
[Dict[str, Union[int, float]], RuntimeContext],
Dict[str, Union[int, float]],
]
self.user_space_docker_cmd = "" # type: Optional[str]
self.secret_store = None # type: Optional[SecretStore]
Expand Down
27 changes: 9 additions & 18 deletions cwltool/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,35 +283,26 @@ def __init__(self) -> None:
self.allocated_cores = float(0)

def select_resources(
self, request, runtime_context
): # pylint: disable=unused-argument
# type: (Dict[str, Union[int, float, str]], RuntimeContext) -> Dict[str, Union[int, float, str]]
self, request: Dict[str, Union[int, float]], runtime_context: RuntimeContext
) -> Dict[str, Union[int, float]]: # pylint: disable=unused-argument
"""Naïve check for available cpu cores and memory."""
result = {} # type: Dict[str, Union[int, float, str]]
result: Dict[str, Union[int, float]] = {}
maxrsc = {"cores": self.max_cores, "ram": self.max_ram}
for rsc in ("cores", "ram"):
rsc_min = request[rsc + "Min"]
if not isinstance(rsc_min, str) and rsc_min > maxrsc[rsc]:
if rsc_min > maxrsc[rsc]:
raise WorkflowException(
"Requested at least %d %s but only %d available"
% (rsc_min, rsc, maxrsc[rsc])
f"Requested at least {rsc_min} {rsc} but only "
f"{maxrsc[rsc]} available"
)
rsc_max = request[rsc + "Max"]
if not isinstance(rsc_max, str) and rsc_max < maxrsc[rsc]:
if rsc_max < maxrsc[rsc]:
result[rsc] = math.ceil(rsc_max)
else:
result[rsc] = maxrsc[rsc]

result["tmpdirSize"] = (
math.ceil(request["tmpdirMin"])
if not isinstance(request["tmpdirMin"], str)
else request["tmpdirMin"]
)
result["outdirSize"] = (
math.ceil(request["outdirMin"])
if not isinstance(request["outdirMin"], str)
else request["outdirMin"]
)
result["tmpdirSize"] = math.ceil(request["tmpdirMin"])
result["outdirSize"] = math.ceil(request["outdirMin"])

return result

Expand Down
2 changes: 1 addition & 1 deletion cwltool/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def do_eval(
requirements: List[CWLObjectType],
outdir: Optional[str],
tmpdir: Optional[str],
resources: Dict[str, Union[float, int, str]],
resources: Dict[str, Union[float, int]],
context: Optional[CWLOutputType] = None,
timeout: float = default_timeout,
force_docker_pull: bool = False,
Expand Down
19 changes: 7 additions & 12 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def inc(d): # type: (List[int]) -> None

def evalResources(
self, builder: Builder, runtimeContext: RuntimeContext
) -> Dict[str, Union[int, float, str]]:
) -> Dict[str, Union[int, float]]:
resourceReq, _ = self.get_requirement("ResourceRequirement")
if resourceReq is None:
resourceReq = {}
Expand Down Expand Up @@ -1010,19 +1010,14 @@ def evalResources(
request[a + "Min"] = mn
request[a + "Max"] = cast(Union[int, float], mx)

request_evaluated = cast(Dict[str, Union[int, float]], request)
if runtimeContext.select_resources is not None:
return runtimeContext.select_resources(request, runtimeContext)
return runtimeContext.select_resources(request_evaluated, runtimeContext)
return {
"cores": request["coresMin"],
"ram": math.ceil(request["ramMin"])
if not isinstance(request["ramMin"], str)
else request["ramMin"],
"tmpdirSize": math.ceil(request["tmpdirMin"])
if not isinstance(request["tmpdirMin"], str)
else request["tmpdirMin"],
"outdirSize": math.ceil(request["outdirMin"])
if not isinstance(request["outdirMin"], str)
else request["outdirMin"],
"cores": request_evaluated["coresMin"],
"ram": math.ceil(request_evaluated["ramMin"]),
"tmpdirSize": math.ceil(request_evaluated["tmpdirMin"]),
"outdirSize": math.ceil(request_evaluated["outdirMin"]),
}

def validate_hints(
Expand Down

0 comments on commit 5e27d91

Please sign in to comment.