Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always recalculate job resources before job is scheduled as input might have changed or not have been present initially #1552

Merged
merged 3 commits into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions snakemake/jobs.py
Expand Up @@ -152,6 +152,7 @@ class Job(AbstractJob):
"_group",
"targetfile",
"incomplete_input_expand",
"_params_and_resources_resetted",
]

def __init__(
Expand Down Expand Up @@ -203,6 +204,7 @@ def __init__(
self.shadow_dir = None
self._inputsize = None
self.is_updated = False
self._params_and_resources_resetted = False

self._attempt = self.dag.workflow.attempt

Expand Down Expand Up @@ -340,8 +342,10 @@ def resources(self):
return self._resources

def reset_params_and_resources(self):
self._resources = None
self._params = None
if not self._params_and_resources_resetted:
self._resources = None
self._params = None
self._params_and_resources_resetted = True

@property
def conda_env_spec(self):
Expand Down
11 changes: 6 additions & 5 deletions snakemake/scheduler.py
Expand Up @@ -471,6 +471,12 @@ def schedule(self):
if self.dryrun:
run = needrun
else:
# Reset params and resources because they might still contain TBDs
# or old values from before files have been regenerated.
# Now, they can be recalculated as all input is present and up to date.
for job in needrun:
job.reset_params_and_resources()

logger.debug(
"Resources before job selection: {}".format(self.resources)
)
Expand All @@ -497,11 +503,6 @@ def schedule(self):
# remove from ready_jobs
self.dag.register_running(run)

# reset params and resources because they might contain TBDs
if not self.dryrun:
for job in run:
job.reset_params_and_resources()

# actually run jobs
local_runjobs = [job for job in run if job.is_local]
runjobs = [job for job in run if not job.is_local]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_github_issue1550/Snakefile
@@ -0,0 +1,13 @@
# Snakefile
rule all:
input:
"a.out",


rule a:
output:
"a.out",
resources:
mem_mb=2000, # Note that resources are specified here, but not in all.
shell:
"touch {output}"
Empty file.
12 changes: 12 additions & 0 deletions tests/tests.py
Expand Up @@ -1591,6 +1591,18 @@ def test_github_issue1542():
run(dpath("test_github_issue1542"), dryrun=True)


def test_github_issue1550():
from snakemake.resources import DefaultResources

run(
dpath("test_github_issue1550"),
resources={"mem_mb": 4000},
default_resources=DefaultResources(
["mem_mb=max(2*input.size, 1000)", "disk_mb=max(2*input.size, 1000)"]
),
)


def test_github_issue1498():
run(dpath("test_github_issue1498"))

Expand Down