-
Notifications
You must be signed in to change notification settings - Fork 3
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
Validate maximum number of workers for flux #527
Conversation
WalkthroughThe pull request introduces a new resource validation mechanism for the Flux allocation backend in the executor library. A new function Changes
Sequence DiagramsequenceDiagram
participant User
participant CreateExecutor
participant FluxValidation
participant SystemResources
User->>CreateExecutor: Request executor with max_workers
CreateExecutor->>FluxValidation: Validate max_workers
FluxValidation->>SystemResources: Check available cores
alt Cores sufficient
FluxValidation-->>CreateExecutor: Validation passed
CreateExecutor-->>User: Create Executor
else Insufficient cores
FluxValidation-->>CreateExecutor: Raise ValueError
CreateExecutor-->>User: Resource allocation error
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_executor_backend_flux.py (1)
117-125
: Consider adding more test cases for comprehensive validation.While the current test verifies the basic validation scenario, consider adding these test cases:
- Edge case where requested cores equal available cores (should pass)
- Case with minimal values (e.g., 1 core, 1 thread)
- Case with non-default thread counts
Example addition:
def test_validate_max_workers(self): with self.assertRaises(ValueError): Executor( max_workers=10, resource_dict={"cores": 10, "threads_per_core": 10}, flux_executor=self.executor, backend="flux_allocation", block_allocation=True, ) + # Should pass: Equal to available cores + Executor( + max_workers=1, + resource_dict={"cores": 1, "threads_per_core": 1}, + flux_executor=self.executor, + backend="flux_allocation", + block_allocation=True, + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
executorlib/interactive/executor.py
(2 hunks)executorlib/interactive/flux.py
(1 hunks)tests/test_executor_backend_flux.py
(1 hunks)
🔇 Additional comments (1)
executorlib/interactive/executor.py (1)
229-233
: Consider validating resources regardless of block_allocation.
The current implementation only validates resources when block_allocation=True
. This could potentially lead to resource overallocation when block_allocation=False
.
Let's verify if there are any existing resource checks for non-block allocation:
Consider:
- Moving the validation earlier in the function, before other resource-specific checks
- Implementing validation for non-block allocation cases
- Adding a comment explaining why validation is only needed for block allocation if that's intentional
def validate_max_workers(max_workers, cores, threads_per_core): | ||
handle = flux.Flux() | ||
cores_total = flux.resource.list.resource_list(handle).get().up.ncores | ||
cores_requested = max_workers * cores * threads_per_core | ||
if cores_total < cores_requested: | ||
raise ValueError( | ||
"The number of requested cores is larger than the available cores " | ||
+ str(cores_total) | ||
+ " < " | ||
+ str(cores_requested) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling and type safety.
The validation function could benefit from the following improvements:
- Use f-strings for better readability
- Add type hints
- Ensure proper resource cleanup
Consider this implementation:
-def validate_max_workers(max_workers, cores, threads_per_core):
+def validate_max_workers(max_workers: int, cores: int, threads_per_core: int) -> None:
handle = flux.Flux()
- cores_total = flux.resource.list.resource_list(handle).get().up.ncores
- cores_requested = max_workers * cores * threads_per_core
- if cores_total < cores_requested:
- raise ValueError(
- "The number of requested cores is larger than the available cores "
- + str(cores_total)
- + " < "
- + str(cores_requested)
- )
+ try:
+ cores_total = flux.resource.list.resource_list(handle).get().up.ncores
+ cores_requested = max_workers * cores * threads_per_core
+ if cores_total < cores_requested:
+ raise ValueError(
+ f"The number of requested cores is larger than the available cores: "
+ f"{cores_total} < {cores_requested}"
+ )
+ finally:
+ handle.close()
📝 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.
def validate_max_workers(max_workers, cores, threads_per_core): | |
handle = flux.Flux() | |
cores_total = flux.resource.list.resource_list(handle).get().up.ncores | |
cores_requested = max_workers * cores * threads_per_core | |
if cores_total < cores_requested: | |
raise ValueError( | |
"The number of requested cores is larger than the available cores " | |
+ str(cores_total) | |
+ " < " | |
+ str(cores_requested) | |
) | |
def validate_max_workers(max_workers: int, cores: int, threads_per_core: int) -> None: | |
handle = flux.Flux() | |
try: | |
cores_total = flux.resource.list.resource_list(handle).get().up.ncores | |
cores_requested = max_workers * cores * threads_per_core | |
if cores_total < cores_requested: | |
raise ValueError( | |
f"The number of requested cores is larger than the available cores: " | |
f"{cores_total} < {cores_requested}" | |
) | |
finally: | |
handle.close() |
Summary by CodeRabbit
New Features
Bug Fixes
Tests