Skip to content

feat!: job arrays #174

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

feat!: job arrays #174

wants to merge 4 commits into from

Conversation

johanneskoester
Copy link
Contributor

@johanneskoester johanneskoester commented Nov 29, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new method for processing jobs in the Executor class, enhancing job management capabilities.
  • Chores
    • Added necessary imports to support the new functionality.

Copy link
Contributor

coderabbitai bot commented Nov 29, 2024

Walkthrough

The changes introduce a new method, run_jobs, in the Executor class within the snakemake_executor_plugin_slurm module. This method processes jobs grouped by their rule names using the groupby function. For single-job groups, it invokes run_job, while groups with multiple jobs have a placeholder for future enhancements. The import statement for groupby has been added, but existing methods and their functionality remain unchanged.

Changes

File Path Change Summary
snakemake_executor_plugin_slurm/init.py Added run_jobs method to Executor class for processing jobs; added import for groupby.

Sequence Diagram(s)

sequenceDiagram
    participant Executor
    participant JobExecutorInterface

    Executor->>JobExecutorInterface: run_jobs(jobs)
    alt Single Job
        Executor->>JobExecutorInterface: run_job(job)
    else Multiple Jobs
        Executor->>Executor: // TODO: Implement job array submission
    end
Loading

🐰 In the meadow where bunnies hop,
A new method's born, it won't stop!
Jobs grouped by name, they dance and play,
With run_jobs leading the way.
So here's to the code, fresh and bright,
A leap towards the future, oh what a sight! 🌼

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

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
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: 2

🧹 Outside diff range and nitpick comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

111-124: Enhance error handling and logging

The new method should follow the same error handling and logging patterns as the rest of the codebase. Consider adding:

  1. Error handling for empty job lists
  2. Logging for job grouping operations
  3. Consistent error propagation

Here's a suggested implementation:

def run_jobs(self, jobs: List[JobExecutorInterface]):
+    if not jobs:
+        return
+
+    self.logger.debug(f"Grouping {len(jobs)} jobs by rule name")
     try:
         for rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
             same_rule_jobs = list(group)
+            self.logger.debug(
+                f"Processing {len(same_rule_jobs)} jobs for rule '{rule_name}'"
+            )
             if len(same_rule_jobs) == 1:
                 self.run_job(same_rule_jobs[0])
             else:
                 # Temporary implementation: submit jobs individually
                 for job in same_rule_jobs:
                     self.run_job(job)
+    except Exception as e:
+        raise WorkflowError(f"Failed to process job group: {str(e)}")
🧰 Tools
🪛 Ruff (0.8.0)

114-114: Using the generator returned from itertools.groupby() more than once will do nothing on the second usage

(B031)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 531ebc6 and 3abb561.

📒 Files selected for processing (1)
  • snakemake_executor_plugin_slurm/__init__.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.0)
snakemake_executor_plugin_slurm/__init__.py

114-114: Using the generator returned from itertools.groupby() more than once will do nothing on the second usage

(B031)

🔇 Additional comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

8-8: LGTM!

The groupby import is correctly placed with other standard library imports and is required for the new job array functionality.

Comment on lines 115 to 124
else:
# TODO submit as array
# share code with run_job

# TODO in the future: give a hint to the scheduler to select preferably
# many jobs from the same rule if possible, in order to have
# more efficient array jobs. This should be somehow tunable, because
# it might contradict other efficiency goals.
...

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implement placeholder for array jobs

The current implementation uses an ellipsis (...) as a placeholder, which will raise a NotImplementedError. Until the array job submission is implemented, we should handle these jobs individually.

Apply this improvement to handle multi-job groups temporarily:

         else:
             # TODO submit as array
             # share code with run_job
-            ...
+            # Temporary implementation: submit jobs individually until array support is added
+            for job in same_rule_jobs:
+                self.run_job(job)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else:
# TODO submit as array
# share code with run_job
# TODO in the future: give a hint to the scheduler to select preferably
# many jobs from the same rule if possible, in order to have
# more efficient array jobs. This should be somehow tunable, because
# it might contradict other efficiency goals.
...
else:
# TODO submit as array
# share code with run_job
# TODO in the future: give a hint to the scheduler to select preferably
# many jobs from the same rule if possible, in order to have
# more efficient array jobs. This should be somehow tunable, because
# it might contradict other efficiency goals.
# Temporary implementation: submit jobs individually until array support is added
for job in same_rule_jobs:
self.run_job(job)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@johanneskoester
Copy link
Contributor Author

johanneskoester commented Dec 20, 2024

Plan: support aggregation of jobs in the Snakemake scheduler before they are send to the executor. This can be done by supporting a new standard resource min_jobs that tells the scheduler how many jobs shall be considered at least of a given rule. Of course, this resource will be automatically limited to the theoretical maximum number of jobs from that rule. The latter has to consider that a rule may occur in different topological levels of the workflow, which should be treated independently.

This way we avoid the case that jobs drop into the executor in a too fine-grained way.
Admins can even set this resource to the minimum size they want to have for array jobs on their cluster.

@cmeesters cmeesters changed the title feat: job arrays feat!: job arrays Jan 25, 2025
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

♻️ Duplicate comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

177-185: ⚠️ Potential issue

Implement temporary handling for multi-job groups.

The current implementation uses an ellipsis (...) as a placeholder, which will raise a NotImplementedError. Until the array job submission is implemented, we should handle these jobs individually.

Apply this improvement to handle multi-job groups temporarily:

             else:
                 # TODO submit as array
                 # share code with run_job
-
-                # TODO in the future: give a hint to the scheduler to select preferably
-                # many jobs from the same rule if possible, in order to have
-                # more efficient array jobs. This should be somehow tunable, because
-                # it might contradict other efficiency goals.
-                ...
+                # Temporary implementation: submit jobs individually until array support is added
+                for job in same_rule_jobs:
+                    self.run_job(job)
🧹 Nitpick comments (2)
snakemake_executor_plugin_slurm/__init__.py (2)

172-172: Add docstring to document the method's purpose and parameters.

The method lacks documentation explaining its purpose and parameters.

Apply this improvement:

     def run_jobs(self, jobs: List[JobExecutorInterface]):
+        """Process and submit multiple jobs, potentially as job arrays.
+
+        Args:
+            jobs: List of jobs to be submitted for execution.
+        """

173-173: Fix unused loop variable.

The loop control variable rule_name is not used within the loop body.

Apply this improvement:

-        for rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
+        for _rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
🧰 Tools
🪛 Ruff (0.8.2)

173-173: Loop control variable rule_name not used within loop body

Rename unused rule_name to _rule_name

(B007)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3abb561 and f9cb5ad.

📒 Files selected for processing (1)
  • snakemake_executor_plugin_slurm/__init__.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
snakemake_executor_plugin_slurm/__init__.py

173-173: Loop control variable rule_name not used within loop body

Rename unused rule_name to _rule_name

(B007)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing
🔇 Additional comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

9-9: LGTM!

The groupby import is correctly placed with other standard library imports and is necessary for the new functionality.

@cmeesters cmeesters marked this pull request as draft March 7, 2025 18:59
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

♻️ Duplicate comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

179-185: ⚠️ Potential issue

Implement placeholder for array jobs

The current implementation uses an ellipsis (...) as a placeholder, which will raise a NotImplementedError. Until the array job submission is implemented, we should handle these jobs individually.

            else:
                # TODO submit as array
                # share code with run_job

                # TODO in the future: give a hint to the scheduler to select preferably
                # many jobs from the same rule if possible, in order to have
                # more efficient array jobs. This should be somehow tunable, because
                # it might contradict other efficiency goals.
-                ...
+                # Temporary implementation: submit jobs individually until array support is added
+                for job in same_rule_jobs:
+                    self.run_job(job)
🧹 Nitpick comments (1)
snakemake_executor_plugin_slurm/__init__.py (1)

173-173: Rename unused variable rule_name to _rule_name

The variable rule_name is defined in the loop statement but never used within the loop body. To follow Python conventions, prefix unused variables with an underscore.

-    def run_jobs(self, jobs: List[JobExecutorInterface]):
-        for rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
+    def run_jobs(self, jobs: List[JobExecutorInterface]):
+        for _rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
🧰 Tools
🪛 Ruff (0.8.2)

173-173: Loop control variable rule_name not used within loop body

Rename unused rule_name to _rule_name

(B007)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9cb5ad and 6e3742c.

📒 Files selected for processing (1)
  • snakemake_executor_plugin_slurm/__init__.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
snakemake_executor_plugin_slurm/__init__.py

173-173: Loop control variable rule_name not used within loop body

Rename unused rule_name to _rule_name

(B007)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing

Comment on lines +172 to 186
def run_jobs(self, jobs: List[JobExecutorInterface]):
for rule_name, group in groupby(jobs, key=lambda job: job.rule.name):
same_rule_jobs = list(group) # Materialize the generator
if len(same_rule_jobs) == 1:
self.run_job(same_rule_jobs[0])
else:
# TODO submit as array
# share code with run_job

# TODO in the future: give a hint to the scheduler to select preferably
# many jobs from the same rule if possible, in order to have
# more efficient array jobs. This should be somehow tunable, because
# it might contradict other efficiency goals.
...
def run_job(self, job: JobExecutorInterface):
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Verify implementation aligns with PR objectives

The PR mentions implementing a min_jobs resource for job aggregation, but this resource isn't referenced in the current implementation. Consider how this resource will be integrated with the job grouping logic.


🏁 Script executed:

#!/bin/bash
# Search for any references to min_jobs in the codebase
rg "min_jobs" --type python

Length of output: 58


I'll run a revised shell script using the proper file type flag to search for references to min_jobs in Python files. This will help verify whether the intended resource is referenced anywhere in the codebase.


🏁 Script executed:

#!/bin/bash
# Search for any references to 'min_jobs' in Python files using the correct file type flag.
rg "min_jobs" --type py

Length of output: 23


Action Required: Integrate the min_jobs resource with job aggregation logic

Our verification confirms that there are no references to the min_jobs resource anywhere in the Python codebase. Since the PR explicitly mentions implementing a min_jobs resource for job aggregation, the current job grouping logic in snakemake_executor_plugin_slurm/__init__.py (lines 172-186) does not reflect this change.

  • Location: snakemake_executor_plugin_slurm/__init__.py (within the run_jobs method)
  • Action: Please update the implementation to incorporate the min_jobs logic into the job aggregation process, or provide additional documentation explaining how this resource will be integrated in subsequent changes.
🧰 Tools
🪛 Ruff (0.8.2)

173-173: Loop control variable rule_name not used within loop body

Rename unused rule_name to _rule_name

(B007)

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.

2 participants