Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Apr 26, 2025

Summary by CodeRabbit

  • Refactor

    • Unified executor classes under a new interface, providing a consistent abstraction layer for all executor types.
    • Standardized initialization patterns for all executor classes, improving maintainability and design consistency.
  • Documentation

    • Updated developer documentation to clarify the mapping between executor interfaces and internal task schedulers.
  • Tests

    • Updated tests to reflect changes in internal structure, ensuring correct access to nested attributes within executor instances.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 26, 2025

Walkthrough

This update introduces a new ExecutorInterface abstraction that wraps an internal executor and standardizes the interface for various executor types. Several executor classes (SingleNodeExecutor, SlurmClusterExecutor, SlurmJobExecutor, FluxClusterExecutor, and FluxJobExecutor) are refactored to inherit from ExecutorInterface, replacing previous factory patterns with unified initialization logic. Internal state access in both test code and documentation is updated to reference the _task_scheduler attribute, reflecting the new internal structure. No changes are made to the core scheduling logic, but the interface and initialization patterns are now more consistent and maintainable.

Changes

File(s) Change Summary
executorlib/base/executor.py Added ExecutorInterface class as a wrapper around internal executors; updated ExecutorBase.submit to enforce positional-only fn argument.
executorlib/interfaces/flux.py
executorlib/interfaces/single.py
executorlib/interfaces/slurm.py
Refactored executor classes to inherit from ExecutorInterface, removed factory-style __new__ methods, and standardized initialization by passing composed executors to the superclass.
notebooks/4-developer.ipynb Updated documentation to clarify that executor interfaces map to task schedulers via the _task_scheduler attribute.
tests/test_fluxjobexecutor_plot.py
tests/test_singlenodeexecutor_plot_dependency.py
tests/test_singlenodeexecutor_resize.py
Updated test code to access internal state through the _task_scheduler attribute, reflecting changes in executor class structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExecutorInterface
    participant ExecutorBase

    User->>ExecutorInterface: initialize(executor)
    ExecutorInterface->>ExecutorBase: delegate methods/properties

    User->>ExecutorInterface: submit(fn, ...)
    ExecutorInterface->>ExecutorBase: submit(fn, ...)

    User->>ExecutorInterface: shutdown()
    ExecutorInterface->>ExecutorBase: shutdown()
Loading

Poem

In the warren where code bunnies dwell,
A new Interface hops in, wrapping so well.
Executors now line up in a tidy row,
Each with a scheduler tucked below.
Tests peek inside with gentle care,
Through _task_scheduler—they’re always aware!
Hop, hop, hooray for this refactor day! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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.

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.

@codecov
Copy link

codecov bot commented Apr 26, 2025

Codecov Report

Attention: Patch coverage is 89.36170% with 5 lines in your changes missing coverage. Please review.

Project coverage is 96.65%. Comparing base (5a33b55) to head (6a708e8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
executorlib/interfaces/slurm.py 55.55% 4 Missing ⚠️
executorlib/base/executor.py 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #636      +/-   ##
==========================================
+ Coverage   96.30%   96.65%   +0.35%     
==========================================
  Files          28       28              
  Lines        1271     1287      +16     
==========================================
+ Hits         1224     1244      +20     
+ Misses         47       43       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

♻️ Duplicate comments (11)
tests/test_singlenodeexecutor_plot_dependency.py (6)

123-129: Same concern as above – the test relies on private attributes.


140-146: Same concern as above – the test relies on private attributes.


168-174: Same concern as above – the test relies on private attributes.


213-219: Same concern as above – the test relies on private attributes.


239-245: Same concern as above – the test relies on private attributes.


282-288: Same concern as above – the test relies on private attributes.

executorlib/interfaces/flux.py (1)

365-385: Copy-before-mutate for resource_dict applies here as well.

executorlib/interfaces/slurm.py (4)

152-169: Copy-before-mutate for resource_dict applies here as well.


171-186: Same disable_dependencies / validation asymmetry noted for FluxClusterExecutor.


329-345: Copy-before-mutate for resource_dict applies here as well.


347-359: Validation asymmetry as in SingleNodeExecutor.

🧹 Nitpick comments (2)
executorlib/interfaces/single.py (1)

167-179: Validation asymmetry – plot/refresh checks bypassed

When disable_dependencies=False the code path does not evaluate check_plot_dependency_graph nor check_refresh_rate.
Although DependencyExecutor may validate internally, callers expect identical validation behaviour regardless of the flag.
Consider moving the two checks above the if not disable_dependencies: guard (or duplicating them in both branches) to keep behaviour consistent.

executorlib/interfaces/flux.py (1)

191-197: Redundant per-class validation logic

check_plot_dependency_graph / check_refresh_rate are repeated across interface classes.
Extracting this into a tiny helper (e.g. _validate_plot_config) would reduce duplication and the risk of inconsistent behaviour.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a33b55 and 6a708e8.

📒 Files selected for processing (8)
  • executorlib/base/executor.py (2 hunks)
  • executorlib/interfaces/flux.py (5 hunks)
  • executorlib/interfaces/single.py (4 hunks)
  • executorlib/interfaces/slurm.py (5 hunks)
  • notebooks/4-developer.ipynb (1 hunks)
  • tests/test_fluxjobexecutor_plot.py (4 hunks)
  • tests/test_singlenodeexecutor_plot_dependency.py (7 hunks)
  • tests/test_singlenodeexecutor_resize.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/test_fluxjobexecutor_plot.py (1)
executorlib/standalone/plot.py (1)
  • generate_nodes_and_edges (8-81)
tests/test_singlenodeexecutor_plot_dependency.py (1)
executorlib/standalone/plot.py (1)
  • generate_nodes_and_edges (8-81)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_old
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: notebooks_integration
  • GitHub Check: unittest_win
  • GitHub Check: notebooks
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
🔇 Additional comments (10)
executorlib/base/executor.py (2)

75-75: Good improvement to the API design.

Making the fn parameter positional-only with the / marker enforces that users must pass the function as a positional argument, preventing potential confusion in argument passing.


184-289: Well-designed interface abstraction.

The ExecutorInterface class provides a clean implementation of the adapter pattern, forwarding methods and properties to the internal _task_scheduler instance. This refactoring improves separation of concerns and maintainability.

A few observations:

  1. The implementation correctly forwards all essential methods and properties
  2. The submit() method properly handles the positional-only nature of the fn parameter
  3. The class includes proper context manager support

This is a good architectural improvement that standardizes how executor interfaces interact with their implementation details.

tests/test_singlenodeexecutor_resize.py (2)

22-22: Test updated to match new architecture.

The test has been correctly updated to access the _process attribute through the new _task_scheduler indirection layer, consistent with the interface refactoring.


38-38: Test updated to match new architecture.

The test has been correctly updated to access the _process attribute through the new _task_scheduler indirection layer, consistent with the interface refactoring.

notebooks/4-developer.ipynb (1)

83-83: Clear documentation update reflecting the new architecture.

The documentation now correctly explains that the five executor interfaces internally map to task schedulers accessed via the _task_scheduler attribute. This clarification aligns with the architectural changes and helps developers understand the internal structure.

tests/test_fluxjobexecutor_plot.py (4)

56-57: Tests updated consistently with the new architecture.

The tests have been correctly updated to access the internal dictionaries (_future_hash_dict and _task_hash_dict) through the _task_scheduler attribute, maintaining consistency with the refactored interface design.

Also applies to: 59-62


101-102: Tests updated consistently with the new architecture.

The tests have been correctly updated to access the internal dictionaries (_future_hash_dict and _task_hash_dict) through the _task_scheduler attribute, maintaining consistency with the refactored interface design.

Also applies to: 104-107


127-128: Tests updated consistently with the new architecture.

The tests have been correctly updated to access the internal dictionaries (_future_hash_dict and _task_hash_dict) through the _task_scheduler attribute, maintaining consistency with the refactored interface design.

Also applies to: 130-133


170-171: Tests updated consistently with the new architecture.

The tests have been correctly updated to access the internal dictionaries (_future_hash_dict and _task_hash_dict) through the _task_scheduler attribute, maintaining consistency with the refactored interface design.

Also applies to: 173-176

executorlib/interfaces/flux.py (1)

346-364: disable_dependencies parameter is forwarded but not validated

When plot_dependency_graph=False the code builds a file_executor and passes disable_dependencies through, but no local validation (check_plot_dependency_graph, check_refresh_rate) occurs. If disable_dependencies is True, these validations are skipped entirely. Align behaviour with FluxJobExecutor / SlurmJobExecutor.

Comment on lines +62 to 68
self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
nodes, edges = generate_nodes_and_edges(
task_hash_dict=exe._task_hash_dict,
task_hash_dict=exe._task_scheduler._task_hash_dict,
future_hash_inverse_dict={
v: k for k, v in exe._future_hash_dict.items()
v: k for k, v in exe._task_scheduler._future_hash_dict.items()
},
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

🧩 Analysis chain

Avoid coupling tests to private executor internals

The tests now access exe._task_scheduler._future_hash_dict & exe._task_scheduler._task_hash_dict.
Because everything prefixed with “_” is considered private, any internal refactor (like the one in this PR) will break the tests again.
Consider exposing a thin, read-only property on ExecutorInterface (e.g. future_hash_dict / task_hash_dict) and let the tests consume that public API instead.

- self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
- self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
+ self.assertEqual(len(exe.future_hash_dict), 2)
+ self.assertEqual(len(exe.task_hash_dict), 2)

If creating the properties is feasible, it will de-fragilize the tests without changing their intent.


🏁 Script executed:

#!/bin/bash
# Locate the ExecutorInterface definition
rg -n "class ExecutorInterface" -A5 .

# Locate the SingleNodeExecutor definition to see how it exposes scheduler internals
rg -n "class SingleNodeExecutor" -A5 .

# Check for any existing public accessors of future_hash_dict or task_hash_dict
rg -n "future_hash_dict" -n .
rg -n "task_hash_dict" -n .

Length of output: 8077


🏁 Script executed:

#!/bin/bash
# Display ExecutorInterface class code
sed -n '160,260p' executorlib/base/executor.py

Length of output: 3112


🏁 Script executed:

#!/bin/bash
# Display the beginning of executorlib/interactive/dependency.py to inspect scheduler class and attributes
sed -n '1,200p' executorlib/interactive/dependency.py

Length of output: 6749


)


🏁 Script executed:

#!/bin/bash
# Display the beginning of SingleNodeExecutor implementation
sed -n '1,200p' executorlib/interfaces/single.py

Length of output: 12582


Add public accessors for task and future hash dictionaries

The tests in tests/test_singlenodeexecutor_plot_dependency.py (and similarly in test_fluxjobexecutor_plot) currently reach into the private scheduler internals:

- self.assertEqual(len(exe._task_scheduler._future_hash_dict), 2)
- self.assertEqual(len(exe._task_scheduler._task_hash_dict), 2)
+ self.assertEqual(len(exe.future_hash_dict), 2)
+ self.assertEqual(len(exe.task_hash_dict), 2)

Because any refactor of _task_scheduler will break these assertions, please expose read-only properties on ExecutorInterface. For example, in executorlib/base/executor.py within the ExecutorInterface class, add:

    @property
    def future_hash_dict(self) -> dict:
        """Read-only access to the scheduler’s future hash mapping."""
        return self._task_scheduler._future_hash_dict

    @property
    def task_hash_dict(self) -> dict:
        """Read-only access to the scheduler’s task hash mapping."""
        return self._task_scheduler._task_hash_dict

This preserves test intent without coupling to private attributes.

Comment on lines +149 to +166
super().__init__(
executor=DependencyExecutor(
executor=create_single_node_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)
else:
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

Mutating caller-provided resource_dict can cause surprising side-effects

resource_dict.update(...) happens before the call to DependencyExecutor, which means if the caller passes in a dict that is reused elsewhere its content is silently modified.

Safeguard by copying the dict first:

- if resource_dict is None:
-     resource_dict = {}
- resource_dict.update(
-     {k: v for k, v in default_resource_dict.items() if k not in resource_dict}
- )
+ if resource_dict is None:
+     resource_dict = {}
+ else:
+     # copy to avoid side-effects outside this scope
+     resource_dict = resource_dict.copy()
+ resource_dict.update(
+     {k: v for k, v in default_resource_dict.items() if k not in resource_dict}
+ )

Apply the same pattern wherever resource_dict is consumed (it recurs in many interface classes).

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +169 to +189
super().__init__(
executor=DependencyExecutor(
executor=create_flux_executor(
max_workers=max_workers,
cache_directory=cache_directory,
max_cores=max_cores,
resource_dict=resource_dict,
flux_executor=flux_executor,
flux_executor_pmi_mode=flux_executor_pmi_mode,
flux_executor_nesting=flux_executor_nesting,
flux_log_files=flux_log_files,
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
)
)
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

Copy resource_dict to maintain functional purity

Same mutability concern as raised for SingleNodeExecutor. Copy the user-supplied mapping before modification to protect callers from hidden side-effects.

@jan-janssen jan-janssen merged commit f3c99a1 into main Apr 26, 2025
51 of 53 checks passed
@jan-janssen jan-janssen deleted the executorinterface branch April 26, 2025 07:04
@coderabbitai coderabbitai bot mentioned this pull request May 27, 2025
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