Skip to content

fix: Improved handling of missing output files in group job postprocessing, accounting for temporary files.#1765

Merged
johanneskoester merged 5 commits intosnakemake:mainfrom
pvandyken:group-temp
Dec 21, 2024
Merged

fix: Improved handling of missing output files in group job postprocessing, accounting for temporary files.#1765
johanneskoester merged 5 commits intosnakemake:mainfrom
pvandyken:group-temp

Conversation

@pvandyken
Copy link
Copy Markdown
Contributor

@pvandyken pvandyken commented Jul 11, 2022

When I run group jobs on a cluster, I'll often write temporary files to the node-specific local scratch folder. I'll label them temp(...) and the sub-snakemake instance will dutifully delete the files when no longer needed. Even without that deletion, the files would disappear with the node local scratch as soon as the group job finishes.

The problem occurs when the parent snakemake instance re-assumes control. It checks for all the outputs from the group job, finds the temp files missing, and exits with an error. But these temp files are no longer needed anywhere in the workflow, and indeed, Snakemake's immediate next step if it were to find the temp files would be to delete them.

This PR filters the group job outputs before the existence checks, removing any that are:

  • Not needed anywhere else in the workflow
  • Not target files

In particular, only files that would otherwise be immediately removed are excluded from the existence check (at least, that's the idea).

The idea is to remove a small frustration without causing any breaking or generally noticeable changes. I've no test yet, but I'll write one if the concept here is approved.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • 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).

Summary by CodeRabbit

  • New Features

    • Enhanced output checking mechanism to selectively ignore specific output files.
    • Improved handling of missing output files in job postprocessing, accounting for temporary files.
  • Bug Fixes

    • Refined logic for determining if files are needed by pending jobs, improving accuracy in output management.

@pvandyken pvandyken changed the title Stop checking for unneeded temp files from groups fix: Stop checking for unneeded temp files from groups Jul 11, 2022
@pvandyken pvandyken marked this pull request as draft July 11, 2022 21:46
@DrYak
Copy link
Copy Markdown
Contributor

DrYak commented Jul 17, 2022

This looks nice because it also solves a feature I would have liked to have: #1474

It solves the whole "files that only live for the duration of the group running on the node" part of the problem.

@pvandyken
Copy link
Copy Markdown
Contributor Author

One clarification: sub-snakemake instances on the cluster actually do not automatically delete the temp files (they get called with --notemp). This behaviour is fine, it just means this PR more specifically deals with temp files automatically deleted by the cluster off of local scratch. I don't think this will have any effect on temp files not saved on local scratch (i.e. they should be deleted as normal after the group job finishes), but I'll do some more specific investigations on this at some point.

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DrYak
Copy link
Copy Markdown
Contributor

DrYak commented Jul 31, 2022

@pvandyken : Yes, I meant that we could start also storing our on node-local scratch, completely aleviating all problems of file that don't even live beyond group job.

We're currently testing this on our production server. (:notes: Living on the edge! :guitar: :man_singer:)

@pvandyken
Copy link
Copy Markdown
Contributor Author

@DrYak Ah, no worries, I was clarifying myself because I made a mistake in the initial post. I wanted to correct it for the record.

@pvandyken pvandyken force-pushed the group-temp branch 3 times, most recently from c0353dd to 05d92e0 Compare October 21, 2022 00:18
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Files produced by jobs in the middle of a group job that are neither
endpoints nor needed by any other jobs in the dag are no longer subject
to an existance check
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@johanneskoester johanneskoester marked this pull request as ready for review December 21, 2024 19:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 21, 2024

Warning

Rate limit exceeded

@johanneskoester has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 34 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e92e856 and 83ff23e.

📒 Files selected for processing (2)
  • snakemake/dag.py (2 hunks)
  • snakemake/jobs.py (2 hunks)
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to two Snakemake core files: snakemake/dag.py and snakemake/jobs.py. The changes enhance the handling of output files, particularly for temporary and missing files. In dag.py, a new conditional block allows selective ignoring of specific output files when ignore_missing_output is a list. In jobs.py, the postprocess method of the GroupJob class now includes logic to determine which temporary output files can be safely ignored based on their necessity to pending jobs.

Changes

File Change Summary
snakemake/dag.py Modified check_and_touch_output method to filter expanded_output when ignore_missing_output is a list, allowing selective ignoring of specific output files. Updated method signature to include wait_for_local and check_output_mtime parameters.
snakemake/jobs.py Updated postprocess method in GroupJob class to:
  • Change ignore_missing_output type from boolean to a list of _IOFile objects.
  • Introduce needed inner function to check file requirements.
  • Adjust control flow to incorporate new logic for handling missing output files. |

Sequence Diagram

sequenceDiagram
    participant GroupJob
    participant DAG
    participant Job
    
    GroupJob->>Job: Check temporary output files
    Job-->>GroupJob: File requirements
    GroupJob->>GroupJob: Determine unnecessary files
    GroupJob->>DAG: Pass ignore_missing_output list
    DAG->>DAG: Filter output files
    DAG-->>Job: Processed output files
Loading

The sequence diagram illustrates the new workflow for handling output files, showing how the GroupJob determines unnecessary files and passes this information to the DAG for processing.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
snakemake/jobs.py (1)

1464-1474: LGTM! Consider extracting the condition for better readability.

The needed function correctly determines if a file is required by pending jobs or is a target file. The implementation is accurate and solves the issue.

Consider extracting the complex condition into a more readable form:

-                if (
-                    not self.dag.finished(j)
-                    and self.dag.needrun(j)
-                    and j not in self.jobs
-                )
+                def is_pending_job(j):
+                    return (not self.dag.finished(j) 
+                            and self.dag.needrun(j)
+                            and j not in self.jobs)
+                
+                if is_pending_job(j)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 884498b and f73b3cf.

📒 Files selected for processing (2)
  • snakemake/dag.py (1 hunks)
  • snakemake/jobs.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
snakemake/jobs.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake/dag.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (2)
snakemake/jobs.py (1)

1475-1478: LGTM! The implementation correctly filters unneeded temp files.

The list comprehension effectively filters temporary output files that are not needed by any pending jobs, solving the issue of unnecessary temp file checks.

snakemake/dag.py (1)

582-587: LGTM! The implementation correctly handles the list of files to ignore.

The changes properly handle the case when ignore_missing_output is a list by:

  1. Filtering out the ignored files from expanded_output
  2. Resetting ignore_missing_output to maintain compatibility with the rest of the method

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
snakemake/jobs.py (1)

Line range hint 1537-1575: Please add test coverage for the new functionality.

The implementation looks solid and addresses the issue well. However, as mentioned in the PR description, test coverage is needed. Consider adding tests that verify:

  1. Temporary files not needed outside the group are properly ignored
  2. Temporary files still needed by other jobs are not ignored
  3. Edge cases with mixed temporary and non-temporary files

Would you like help creating these test cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f73b3cf and e92e856.

📒 Files selected for processing (2)
  • snakemake/dag.py (1 hunks)
  • snakemake/jobs.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
snakemake/jobs.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake/dag.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (5)
snakemake/dag.py (1)

693-698: LGTM: Proper handling of ignored output files

The implementation correctly:

  1. Filters out files that should be ignored from expanded_output
  2. Resets ignore_missing_output to empty list to maintain backward compatibility
snakemake/jobs.py (4)

1537-1546: LGTM! Well-implemented file necessity check.

The needed function correctly determines if a file is required by:

  1. Checking if it's a target file
  2. Checking if it's not temporary
  3. Checking if it's needed by pending jobs outside the group

1548-1552: LGTM! Correctly identifies unnecessary temporary files.

The implementation properly filters temporary output files that are not needed outside of the group job, which directly addresses the issue with cluster execution.


1570-1575: LGTM! Proper handling of postprocess parameters.

The implementation correctly:

  1. Passes the filtered list of files to ignore
  2. Disables output mtime checks to prevent interference with intermediate file updates
  3. Maintains proper error handling

1146-1146: LGTM! Note the breaking change in parameter type.

The parameter type change from bool to List[_IOFile] is well-aligned with the PR objectives. This allows for more granular control over which missing output files to ignore.

Let's verify if there are any external callers that might be affected:

✅ Verification successful

Parameter type change is safe to proceed

The search results show that all existing calls to postprocess() either:

  1. Don't pass the ignore_missing_output parameter at all (using default value)
  2. Pass it through from another function call (in jobs.py)

This indicates the type change from bool to List[_IOFile] is safe as there are no direct callers that would be affected by this breaking change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to postprocess with ignore_missing_output parameter
rg "postprocess.*ignore_missing_output\s*=" --type py

Length of output: 55


Script:

#!/bin/bash
# Let's try a broader search for postprocess method calls
rg "\.postprocess\(" --type py -A 3

# Also search for the method definition to understand its usage
ast-grep --pattern 'def postprocess($$$) { $$$ }'

Length of output: 2592

@sonarqubecloud
Copy link
Copy Markdown

@johanneskoester johanneskoester changed the title fix: Stop checking for unneeded temp files from groups fix: Improved handling of missing output files in group job postprocessing, accounting for temporary files. Dec 21, 2024
@johanneskoester johanneskoester merged commit bac06ba into snakemake:main Dec 21, 2024
@pvandyken
Copy link
Copy Markdown
Contributor Author

@johanneskoester thanks for merging!

@pvandyken pvandyken deleted the group-temp branch December 21, 2024 20:29
johanneskoester pushed a commit that referenced this pull request Dec 23, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.26.0](v8.25.5...v8.26.0)
(2024-12-23)


### Features

* add helpers for deferred input/output etc. item access
([#2927](#2927))
([2cca9bc](2cca9bc))


### Bug Fixes

* convert parameters so they can be serialized
([#2925](#2925))
([9e653fb](9e653fb))
* correct formatting of R preamble
([#2425](#2425))
([5380cae](5380cae))
* fix modification checks for scripts and and notebooks containing
wildcards or params in their paths
([#2751](#2751))
([773568d](773568d))
* Improved handling of missing output files in group job postprocessing,
accounting for temporary files.
([#1765](#1765))
([bac06ba](bac06ba))
* mtime of script or notebook not triggering workflow without metadata
([#3148](#3148))
([e8a0b83](e8a0b83))
* Pass `host` attribute to `GitlabFile` instantiation within class
methods ([#3155](#3155))
([9ef52de](9ef52de))
* problem with spaces in path
([#3236](#3236))
([2d08c63](2d08c63))
* require current yte release which contains an important bug fix for
cases where numpy/pandas data is passed to templates
([#3227](#3227))
([c3339da](c3339da))
* rerun jobs if previously failed but rule was changed afterwards
(thanks to [@laf070810](https://github.com/laf070810) for bringing this
up) ([#3237](#3237))
([1dc0084](1dc0084))
* use relpath for configfiles added to the source archive (thanks to
[@sposadac](https://github.com/sposadac) for the initial solution)
([#3240](#3240))
([bff3844](bff3844))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
…ssing, accounting for temporary files. (snakemake#1765)

When I run group jobs on a cluster, I'll often write temporary files to
the node-specific local scratch folder. I'll label them `temp(...)` and
the sub-snakemake instance will dutifully delete the files when no
longer needed. Even without that deletion, the files would disappear
with the node local scratch as soon as the group job finishes.

The problem occurs when the parent snakemake instance re-assumes
control. It checks for all the outputs from the group job, finds the
temp files missing, and exits with an error. But these temp files are no
longer needed anywhere in the workflow, and indeed, Snakemake's
immediate next step if it were to find the temp files would be to delete
them.

This PR filters the group job outputs before the existence checks,
removing any that are:
- Not needed anywhere else in the workflow
- Not target files

In particular, only files that would otherwise be immediately removed
are excluded from the existence check (at least, that's the idea).

The idea is to remove a small frustration without causing any breaking
or generally noticeable changes. I've no test yet, but I'll write one if
the concept here is approved.


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

* [ ] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [ ] 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).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced output checking mechanism to selectively ignore specific
output files.
- Improved handling of missing output files in job postprocessing,
accounting for temporary files.

- **Bug Fixes**
- Refined logic for determining if files are needed by pending jobs,
improving accuracy in output management.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
Co-authored-by: Johannes Koester <johannes.koester@uni-due.de>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[8.26.0](snakemake/snakemake@v8.25.5...v8.26.0)
(2024-12-23)


### Features

* add helpers for deferred input/output etc. item access
([snakemake#2927](snakemake#2927))
([2cca9bc](snakemake@2cca9bc))


### Bug Fixes

* convert parameters so they can be serialized
([snakemake#2925](snakemake#2925))
([9e653fb](snakemake@9e653fb))
* correct formatting of R preamble
([snakemake#2425](snakemake#2425))
([5380cae](snakemake@5380cae))
* fix modification checks for scripts and and notebooks containing
wildcards or params in their paths
([snakemake#2751](snakemake#2751))
([773568d](snakemake@773568d))
* Improved handling of missing output files in group job postprocessing,
accounting for temporary files.
([snakemake#1765](snakemake#1765))
([bac06ba](snakemake@bac06ba))
* mtime of script or notebook not triggering workflow without metadata
([snakemake#3148](snakemake#3148))
([e8a0b83](snakemake@e8a0b83))
* Pass `host` attribute to `GitlabFile` instantiation within class
methods ([snakemake#3155](snakemake#3155))
([9ef52de](snakemake@9ef52de))
* problem with spaces in path
([snakemake#3236](snakemake#3236))
([2d08c63](snakemake@2d08c63))
* require current yte release which contains an important bug fix for
cases where numpy/pandas data is passed to templates
([snakemake#3227](snakemake#3227))
([c3339da](snakemake@c3339da))
* rerun jobs if previously failed but rule was changed afterwards
(thanks to [@laf070810](https://github.com/laf070810) for bringing this
up) ([snakemake#3237](snakemake#3237))
([1dc0084](snakemake@1dc0084))
* use relpath for configfiles added to the source archive (thanks to
[@sposadac](https://github.com/sposadac) for the initial solution)
([snakemake#3240](snakemake#3240))
([bff3844](snakemake@bff3844))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants