feat: assume checkpoint safe temp files#3218
feat: assume checkpoint safe temp files#3218mhulsman wants to merge 7 commits intosnakemake:mainfrom
Conversation
Snakemake can only ensure that temp files will not be needed anymore after all checkpoint jobs have been executed (snakemake#609, snakemake#2732, fixed in snakemake#2737). However, waiting for all checkpoint jobs to be completed can lead to excessive storage use (snakemake#2982). In most cases temp file usage is either unaffected by checkpoint jobs, or can be explicitly managed by including the temp files as input to checkpoint jobs or their downstream dependencies. This will ensure they are kept on disk until they (might) be needed. To address cases where pipelines using checkpoints become infeasible due to high storage demands, this commit introduces a new command-line option. This option lets Snakemake know that it can safely remove temporary files not required by current jobs, even if checkpoint jobs are still pending.
📝 WalkthroughWalkthroughThis pull request introduces a new configuration for managing temporary files when using checkpoint rules. It adds clarifications in the documentation, a new command-line flag ( Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CP as CLI Parser (get_argument_parser)
participant API as args_to_api / Snakemake API
participant D as DAG (dag.py)
U->>CP: Run snakemake with --assume-checkpoint-safe-temp-files flag
CP->>API: Parse flag and pass it along
API->>D: Initialize DAG with dag_settings (assume_checkpoint_safe_temp_files flag)
D->>D: Use flag in finish() to decide on temporary file deletion
Suggested labels
Suggested reviewers
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used📓 Path-based instructions (1)`**/*.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 `s...
⏰ Context from checks skipped due to timeout of 90000ms (36)
🔇 Additional comments (2)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
snakemake/settings/types.py (1)
205-205: LGTM! Consider adding a docstring.The new boolean flag is well-placed within the
DAGSettingsclass and aligns with the PR's objective of optimizing temporary file handling in checkpoint jobs. However, adding a docstring would improve code maintainability.Consider adding a docstring to document the flag's purpose:
class DAGSettings(SettingsBase): targets: AnySet[str] = frozenset() target_jobs: AnySet[str] = frozenset() target_files_omit_workdir_adjustment: bool = False batch: Optional[Batch] = None forcetargets: bool = False forceall: bool = False forcerun: AnySet[str] = frozenset() until: AnySet[str] = frozenset() omit_from: AnySet[str] = frozenset() force_incomplete: bool = False allowed_rules: AnySet[str] = frozenset() rerun_triggers: AnySet[RerunTrigger] = RerunTrigger.all() max_inventory_wait_time: int = 20 - assume_checkpoint_safe_temp_files: bool = False + assume_checkpoint_safe_temp_files: bool = False + """When True, allows Snakemake to remove temporary files that are not required by current jobs, + even if there are pending checkpoint jobs. This can significantly reduce storage requirements + in workflows with checkpoint rules."""docs/snakefiles/rules.rst (1)
1659-1666: Documentation enhancement looks good, with a minor suggestion.The added documentation clearly explains the behavior of temporary files with checkpoint rules and introduces the new
--assume-checkpoint-safe-temp-filesoption. The warning about potential premature deletion is well-articulated.Consider adding a small code example to illustrate the proper way to include temporary files as inputs to checkpoint jobs or their dependencies. This would make the documentation more actionable for users.
Example addition:
# Example of properly including temp files in checkpoint dependencies rule create_temp: output: temp("temp_file.txt") shell: "..." checkpoint process_data: input: "temp_file.txt" # temp file properly included as input output: "checkpoint_output.txt" shell: "..."snakemake/dag.py (1)
1979-1982: Implement Conditional Temp File Deletion and Address TODOThe condition now allows temp files to be deleted when
assume_checkpoint_safe_temp_filesis True, which is correct. There's a TODO comment suggesting a more accurate method to determine dependencies on temp files in relation to checkpoints. I can assist with this enhancement.Would you like me to work on a solution or open a new GitHub issue to address this TODO?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
docs/snakefiles/rules.rst(1 hunks)snakemake/cli.py(3 hunks)snakemake/dag.py(4 hunks)snakemake/settings/types.py(1 hunks)tests/common.py(2 hunks)tests/tests.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
snakemake/cli.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.
snakemake/settings/types.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.
tests/common.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.
tests/tests.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 (14)
tests/common.py (2)
216-216: LGTM: Parameter addition follows existing patterns
The new parameter assume_checkpoint_safe_temp_files is well-placed and maintains backward compatibility with its default False value.
373-373: LGTM: Verify test coverage for the new parameter
The parameter is correctly passed to the DAG settings. However, let's verify that there are corresponding test cases that exercise this parameter.
tests/tests.py (2)
2290-2291: LGTM! Appropriate use of skip decorator.
The @skip_on_windows decorator is correctly used as this test is OS-agnostic and doesn't need to run on Windows.
2292-2297: LGTM! Test implementation validates error handling.
The test appropriately validates that the new assume_checkpoint_safe_temp_files flag handles error cases correctly by:
- Using an existing test case that exercises checkpoint functionality
- Enabling the new flag
- Expecting the test to fail via
shouldfail=True
snakemake/cli.py (3)
Line range hint 850-857: LGTM: Shadow prefix argument is well implemented
The --shadow-prefix argument is properly implemented with clear documentation explaining its purpose and default behavior.
861-872: LGTM: Checkpoint-safe temp files flag is well designed
The --assume-checkpoint-safe-temp-files flag is well implemented with thorough documentation that clearly explains:
- The default safer behavior of keeping temp files until checkpoints complete
- The conditions under which it's safe to use this flag
- The requirement to declare temp files as inputs if needed after checkpoints
2106-2106: LGTM: DAG settings integration is correct
The new flag is properly integrated into the DAG settings.
snakemake/dag.py (7)
115-116: Add Type Annotation for self.workflow
Adding the type annotation :_workflow.Workflow for self.workflow enhances code readability and maintainability.
118-118: Clarify self._dependencies with Comment
The added comment clearly describes the purpose of self._dependencies, improving code understanding.
121-121: Add Comment for self.depending Mapping
The comment provides a concise explanation of self.depending, aiding in code comprehension.
125-127: Initialize assume_checkpoint_safe_temp_files Attribute
Correctly initializing self.assume_checkpoint_safe_temp_files enhances temporary file management, especially in the context of checkpoint jobs.
196-197: Add Docstring for dependencies Property
The docstring effectively documents the dependencies property, clarifying its return value and purpose.
202-204: Provide Docstring for batch Property
Adding the docstring to the batch property improves documentation and explains its functionality clearly.
1002-1007: Document update Method with Docstring
The added docstring for the update method concisely describes its purpose and exceptions, enhancing code readability.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
docs/snakefiles/rules.rst (1)
1659-1666: Documentation enhancement looks good with a minor formatting suggestion.The added documentation clearly explains:
- The limitation that temporary files cannot be deleted until all checkpoint jobs complete
- The new
--assume-checkpoint-safe-temp-filesoption to override this behavior- Important safety considerations when using this option
Consider applying this formatting improvement to make the documentation more readable:
-When using checkpoint rules, Snakemake cannot determine whether temporary files are no longer needed until -all checkpoint jobs have been completed. This delay in removal may result in unexpectedly high storage usage. -This behavior can be disabled by using the option ``--assume-checkpoint-safe-temp-files``. -However, if any temporary files might still be needed after future checkpoints, you must ensure they are not -deleted prematurely. To do so, include them as input of the checkpoint job (or any jobs dependent on the -checkpoint job)." +When using checkpoint rules, Snakemake cannot determine whether temporary files are no longer needed until +all checkpoint jobs have been completed. This delay in removal may result in unexpectedly high storage usage. + +This behavior can be disabled by using the option ``--assume-checkpoint-safe-temp-files``. +However, if any temporary files might still be needed after future checkpoints, you must ensure they are not +deleted prematurely. To do so, include them as input of the checkpoint job (or any jobs dependent on the +checkpoint job).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
docs/snakefiles/rules.rst(1 hunks)snakemake/dag.py(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- snakemake/dag.py
|
@mhulsman and @johanneskoester I just merged the main into this PR. And as I just have the usecase for this, I will check out this PR next week and will try to apply it in a complex scenario. Thanks for this contribution! At quick glance, the review is not overwhelming. Can do, if you want me to, Johannes. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
docs/snakefiles/rules.rst (1)
1827-1833: Documentation Clarity and Formatting ImprovementThe new paragraph effectively explains that when using checkpoint rules, temporary files cannot be removed until all checkpoint jobs have completed—which might lead to excessive storage usage—and that this behavior can be disabled with the new
--assume-checkpoint-safe-temp-filesoption. However, there is a minor formatting issue: a stray closing double-quote at the end of the paragraph. Additionally, consider a slight rephrasing for enhanced clarity and consistency.Suggested diff for polishing the text:
-When using checkpoint rules, Snakemake cannot determine whether temporary files are no longer needed until -all checkpoint jobs have been completed. This delay in removal may result in unexpectedly high storage usage. -This behavior can be disabled by using the option ``--assume-checkpoint-safe-temp-files``. -However, if any temporary files might still be needed after future checkpoints, you must ensure they are not -deleted prematurely. To do so, include them as input of the checkpoint job (or any jobs dependent on the -checkpoint job)." +When using checkpoint rules, Snakemake cannot determine whether temporary files are no longer needed until all checkpoint jobs have been completed, which may delay their removal and result in unexpectedly high storage usage. This behavior can be disabled by using the ``--assume-checkpoint-safe-temp-files`` option. However, if any temporary files might still be required after future checkpoints, ensure they are not deleted prematurely by including them as input to the checkpoint job (or to any jobs that depend on the checkpoint).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docs/snakefiles/rules.rst(1 hunks)src/snakemake/cli.py(3 hunks)src/snakemake/dag.py(4 hunks)src/snakemake/settings/types.py(1 hunks)tests/common.py(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/common.py
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.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 `s...
**/*.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 theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
src/snakemake/settings/types.pysrc/snakemake/cli.pysrc/snakemake/dag.py
🧬 Code Definitions (1)
src/snakemake/dag.py (1)
src/snakemake/workflow.py (1)
Workflow(140-2396)
⏰ Context from checks skipped due to timeout of 90000ms (35)
- GitHub Check: tests (10, windows-latest, py312)
- GitHub Check: tests (10, ubuntu-latest, py312)
- GitHub Check: tests (10, ubuntu-latest, py311)
- GitHub Check: tests (9, windows-latest, py312)
- GitHub Check: tests (9, ubuntu-latest, py312)
- GitHub Check: tests (9, ubuntu-latest, py311)
- GitHub Check: tests (8, macos-latest, py312)
- GitHub Check: tests (8, windows-latest, py312)
- GitHub Check: tests (8, ubuntu-latest, py312)
- GitHub Check: tests (8, ubuntu-latest, py311)
- GitHub Check: tests (7, macos-latest, py312)
- GitHub Check: tests (7, windows-latest, py312)
- GitHub Check: tests (7, ubuntu-latest, py312)
- GitHub Check: tests (7, ubuntu-latest, py311)
- GitHub Check: tests (6, macos-latest, py312)
- GitHub Check: tests (6, windows-latest, py312)
- GitHub Check: tests (6, ubuntu-latest, py312)
- GitHub Check: tests (6, ubuntu-latest, py311)
- GitHub Check: tests (5, macos-latest, py312)
- GitHub Check: tests (5, windows-latest, py312)
- GitHub Check: tests (5, ubuntu-latest, py312)
- GitHub Check: tests (5, ubuntu-latest, py311)
- GitHub Check: tests (4, windows-latest, py312)
- GitHub Check: tests (4, ubuntu-latest, py312)
- GitHub Check: tests (4, ubuntu-latest, py311)
- GitHub Check: tests (3, windows-latest, py312)
- GitHub Check: tests (3, ubuntu-latest, py312)
- GitHub Check: tests (3, ubuntu-latest, py311)
- GitHub Check: tests (2, windows-latest, py312)
- GitHub Check: tests (2, ubuntu-latest, py312)
- GitHub Check: tests (2, ubuntu-latest, py311)
- GitHub Check: tests (1, macos-latest, py312)
- GitHub Check: tests (1, windows-latest, py312)
- GitHub Check: tests (1, ubuntu-latest, py312)
- GitHub Check: tests (1, ubuntu-latest, py311)
🔇 Additional comments (10)
src/snakemake/settings/types.py (1)
211-211: Well-implemented addition for temporary file management.The new boolean attribute
assume_checkpoint_safe_temp_filesis well-named and clearly relates to the PR's objective. The default value ofFalseis appropriate as it maintains backward compatibility, ensuring that users must explicitly opt-in to the new behavior.src/snakemake/cli.py (2)
855-867: Well-documented new command-line option.The new
--assume-checkpoint-safe-temp-filesoption is clearly described with appropriate warnings about potential risks when using this flag. The documentation effectively explains the tradeoff between storage efficiency and ensuring necessary files are available for downstream jobs after checkpoints.
2116-2116: Correct integration with DAG settings.The new command-line option is properly passed to the DAG settings, which will make it available to the appropriate components that manage temporary file cleanup.
src/snakemake/dag.py (7)
120-121: Type annotation added, improving code readability.The explicit type annotation for
self.workflowmakes the code more maintainable by clearly indicating the expected type.
123-127: Improved documentation with descriptive comments.Adding clear comments about the purpose of the dependency dictionaries enhances code readability and makes it easier for developers to understand the data structures.
130-132: Good implementation of new configuration flag.The new instance variable
self.assume_checkpoint_safe_temp_filesis properly initialized from the workflow's DAG settings, enabling the new feature to control temporary file deletion behavior in the presence of checkpoint jobs.
202-204: Enhanced property documentation with docstring.Adding a descriptive docstring to the
dependenciesproperty improves API documentation and makes the codebase more maintainable.
208-211: Added descriptive docstring to the batch property.The docstring clearly explains the purpose of the
batchproperty, making the API more self-documenting.
1072-1077: Improved method documentation with clarified docstring.The updated docstring for the
updatemethod better explains its functionality and the exception it raises, making the code more accessible to contributors.
1159-1163: Implemented the core feature change for checkpoint-safe temp files.The modified condition now allows temporary files to be deleted either when there are no checkpoint jobs remaining OR when the user has explicitly requested to assume checkpoint-safe temp files, implementing the feature described in the PR objectives.
The comments clearly explain that normally, temp files can't be safely deleted while checkpoint jobs exist, but the new flag allows overriding this behavior.
…ires this pull request: snakemake/snakemake#3218



Snakemake can only ensure that temp files will not be needed anymore
after all checkpoint jobs have been executed (#609, #2732, fixed in #2737).
However, waiting for all checkpoint jobs to be completed can lead to
excessive storage use (#2982).
In most cases temp file usage is either unaffected by checkpoint jobs, or
can be explicitly managed by including the temp files as input to
checkpoint jobs or their downstream dependencies. This will ensure they
are kept on disk until they (might) be needed.
To address cases where pipelines using checkpoints become infeasible due
to high storage demands, this commit introduces a new command-line
option
--assume-checkpoint-safe-temp-files.This option lets Snakemake know that it can safely remove temporary files
not required by current jobs, even if checkpoint jobs are still pending.
QC
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
Documentation
Tests