Skip to content

feat: in job stability #137

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

Merged
merged 6 commits into from
Aug 23, 2024
Merged

feat: in job stability #137

merged 6 commits into from
Aug 23, 2024

Conversation

cmeesters
Copy link
Member

@cmeesters cmeesters commented Aug 16, 2024

might increase stability of in-job submissions, might fix #113

Summary by CodeRabbit

  • New Features

    • Introduced a utility function to manage SLURM environment variables, enhancing job submission reliability.
    • Updated warning handling to clean up SLURM environments when specific conditions are met.
  • Bug Fixes

    • Improved resource management by ensuring lingering SLURM job contexts are addressed.

Copy link
Contributor

coderabbitai bot commented Aug 16, 2024

Warning

Rate limit exceeded

@cmeesters has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 43 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

Files that changed from the base of the PR and between 5a12e61 and 6f0482c.

Walkthrough

The updates include the addition of a utility function, delete_slurm_environment, to manage SLURM-related environment variables, enhancing resource management. The warn_on_jobcontext method in the ExecutorSettings class has been modified to call this utility function when a warning about running Snakemake in a SLURM context is logged. This aims to ensure a cleaner execution environment for jobs.

Changes

Files Change Summary
snakemake_executor_plugin_slurm/__init__.py
snakemake_executor_plugin_slurm/utils.py
Added the delete_slurm_environment function to unset SLURM-related environment variables and modified warn_on_jobcontext to call this function when logging a warning.

Assessment against linked issues

Objective Addressed Explanation
Properly handle SLURM job context warnings (#113)
Ensure environment cleanliness for SLURM jobs (#113)
Improve Snakemake compatibility when run under SLURM (#113) The changes address warnings but may not fully resolve compatibility issues.

Poem

In the meadow where bunnies hop,
SLURM jobs run without a stop.
With a cleanup dance, we twirl and cheer,
No lingering vars, we have no fear!
Snakemake's path is now so bright,
Hopping along, everything feels right! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@cmeesters cmeesters marked this pull request as ready for review August 22, 2024 09:16
Copy link
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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6dad273 and fd3995a.

Files selected for processing (2)
  • snakemake_executor_plugin_slurm/init.py (2 hunks)
  • snakemake_executor_plugin_slurm/utils.py (1 hunks)
Additional comments not posted (1)
snakemake_executor_plugin_slurm/__init__.py (1)

29-30: LGTM! Verify the impact of delete_slurm_environment.

The import and usage of delete_slurm_environment in warn_on_jobcontext are approved. This change aims to prevent conflicts by cleaning up SLURM-related environment variables.

Ensure that this change does not inadvertently affect other parts of the system that rely on SLURM environment variables.

Run the following script to verify the impact of delete_slurm_environment:

Also applies to: 89-94

Verification successful

Verification Successful: No Impact Found from delete_slurm_environment

The searches for SLURM-related environment variables returned no results, indicating that there are no critical dependencies on these variables in the codebase. The delete_slurm_environment function does not inadvertently affect other parts of the system.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of `delete_slurm_environment` on the codebase.

# Test: Search for the usage of SLURM-related environment variables. Expect: No critical dependencies on these variables.
rg --type python -A 5 $'os.environ.get("SLURM_")'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify the impact of `delete_slurm_environment` on the codebase.

# Test: Search for the usage of SLURM-related environment variables. Expect: No critical dependencies on these variables.
rg -A 5 'os.environ.get("SLURM_")'

Length of output: 36


Script:

#!/bin/bash
# Description: Verify the impact of `delete_slurm_environment` on the codebase by checking for other patterns.

# Test: Search for any direct access to SLURM-related environment variables.
rg -A 5 'os.environ\["SLURM_"'

Length of output: 32

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd3995a and 5a12e61.

Files selected for processing (1)
  • snakemake_executor_plugin_slurm/utils.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • snakemake_executor_plugin_slurm/utils.py

@cmeesters cmeesters requested a review from fgvieira August 22, 2024 09:44
@cmeesters
Copy link
Member Author

@fgvieira would you have time to review this PR? Alas, we cannot test this within the CI (due to lack of resources). Seems to work fine for me and others.

@fgvieira
Copy link
Contributor

Why is it not recommended to run snakemake as a SLURM job? That is how I've been running it.

@cmeesters
Copy link
Member Author

Thing is: The executor exports the environment. This has to be done, because otherwise the base environment might not be present. Within a SLURM job the SLURM_* got exported, too. This caused SLURM in some cases to complain about mem and mem_per_cpu mismatches.

I am not sure the current PR will fix all issues. I am even not sure, that 100 % stability can be achieved at all - apparently HPC admins made akward configuration a hobby ... But removing the scheduler env variables certainly is a step forward.

@fgvieira
Copy link
Contributor

So the idea would be to remove all SLURM_* env variables from the (new) launched job. Not the parent snakemake job, right?

@cmeesters
Copy link
Member Author

In fact, you cannot remove environment variables from a parent shell. Hence, python can only remove within the current environment on a node, not its jobscript. Within the Snakemake process on that node, you would not see the SLURM_* variables any more. Also, a daughter process of the same Python process would not be able to see them. A newly lauchned job (on the same node or a different one) would get a fresh population of SLURM_* env variables by SLURM itself.

If you use (host based) logins to that node, you too do not see these environment variables (because: new shell). Howver, if your run

$ srun -A <account> -p <partition> --pty -t 10 bash -i
<node>:<path>$ python3
>>> import os
>>> print(os.environ["SLURM_JOB_ID"])
376803
>>> del os.environ["SLURM_JOB_ID"]
>>> print(os.environ["SLURM_JOB_ID"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen os>", line 714, in __getitem__
KeyError: 'SLURM_JOB_ID'
>>> 
<node>:<path>$ echo $SLURM_JOB_ID
376803

you will see, that you are able to tinker with env vars within your process, not in the parent shell.

@fgvieira fgvieira merged commit c27f5f8 into main Aug 23, 2024
4 checks passed
@fgvieira fgvieira deleted the feat/in_job_stability branch August 23, 2024 06:47
cmeesters pushed a commit that referenced this pull request Aug 23, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.10.0](v0.9.0...v0.10.0)
(2024-08-23)


### Features

* in job stability
([#137](#137))
([c27f5f8](c27f5f8))


### Bug Fixes

* add --parsable to sbatch call for a more robust output parsing
([#125](#125))
([5e41d05](5e41d05))
* issue
[#109](#109)
- preemption is no longer considered a failed status
([#132](#132))
([6dad273](6dad273))

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

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

## Summary by CodeRabbit

- **New Features**
- Introduced the `--parsable` option to the `sbatch` command for
improved output parsing.
	
- **Bug Fixes**
- Revised job preemption handling to prevent it from being marked as a
failed status, enhancing job stability.
	
- **Chores**
- Updated the version number of the Snakemake Executor Plugin for Slurm
to 0.10.0 in preparation for the release.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Sep 30, 2024
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.

Running snakemake in a SLURM job context
2 participants