Skip to content

Commit

Permalink
fix: propagate attempt count from group to subjobs (snakemake#2052)
Browse files Browse the repository at this point in the history
Attempts was getting updated on the group job, but not getting updated
on the group job's member jobs. This prevented the member job resources
calculations from being updated, preventing the correct functioning of
resource lambdas in the group job context.

This propagates the update to the members and adds a test

Resolves snakemake#2045

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).
  • Loading branch information
pvandyken authored Jan 10, 2023
1 parent a328f3e commit da3f1c0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snakemake/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2525,8 +2525,8 @@ def toposorted(self, jobs=None, inherit_pipe_dependencies=False):

for group in pipe_groups.values():
sorted_layer.extend(
chain(
*toposort(
chain.from_iterable(
toposort(
{
job: {
dep
Expand Down
2 changes: 2 additions & 0 deletions snakemake/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,8 @@ def attempt(self):
def attempt(self, attempt):
# reset resources
self._resources = None
for job in self.jobs:
job.attempt = attempt
self._attempt = attempt

@property
Expand Down
17 changes: 17 additions & 0 deletions tests/test_group_jobs_attempts/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rule a:
output: "a"
resources: mem_mb = lambda w, attempt: attempt*1000
group: "mygroup"
shell: '''
if [ {resources.mem_mb} == 2000 ]; then
touch {output}
fi
'''

# rule b:
# input: rules.a.output
# output: "b_{number}"
# group: "mygroup"
# shell: '''
# touch -m {output}
# '''
Empty file.
6 changes: 6 additions & 0 deletions tests/test_group_jobs_attempts/qsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
echo `date` >> qsub.log
tail -n1 $1 >> qsub.log
# simulate printing of job id by a random number
echo $RANDOM
sh $1
5 changes: 5 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ def test_group_jobs():
run(dpath("test_group_jobs"), cluster="./qsub")


@skip_on_windows
def test_group_jobs_attempts():
run(dpath("test_group_jobs_attempts"), cluster="./qsub", restart_times=2)


def assert_resources(resources: dict, **expected_resources):
assert {res: resources[res] for res in expected_resources} == expected_resources

Expand Down

0 comments on commit da3f1c0

Please sign in to comment.