-
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
Set max_cores and max_workers to None #478
Changes from 3 commits
7aa0de2
f8f69f6
9739df8
3e824b0
10ffbf3
c6c6b2e
b5c0a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -131,12 +131,14 @@ def check_init_function(block_allocation: bool, init_function: Callable) -> None | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def check_max_workers_and_cores(max_workers: int, max_cores: int) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_workers != 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def check_max_workers_and_cores( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
max_workers: Optional[int], max_cores: Optional[int] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_workers is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"The number of workers cannot be controlled with the pysqa based backend." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_cores != 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_cores is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+135
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Review needs to be updated - test cases don't align with new optional parameters The verification revealed an inconsistency between the changes and the test cases:
This indicates that either:
🔗 Analysis chainLGTM! Type hints and validation logic updated correctly. The changes properly implement optional parameters while maintaining the original validation purpose. The error messages remain clear and appropriate. Let's verify the usage of this function across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for all calls to check_max_workers_and_cores to ensure they handle None correctly
ast-grep --pattern 'check_max_workers_and_cores($$$)'
Length of output: 479 Script: #!/bin/bash
# Let's check the test file to understand the test cases
cat tests/test_shared_input_check.py
# Also check the executor implementation to see how it handles these parameters
cat executorlib/cache/executor.py
Length of output: 8418 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"The number of cores cannot be controlled with the pysqa based backend." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -170,6 +172,9 @@ def validate_number_of_cores(max_cores: int, max_workers: int) -> int: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Validate the number of cores and return the appropriate value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_workers != 1 and max_cores == 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if max_workers is None and max_cores is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elif max_workers is not None and max_cores is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return max_workers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return max_cores | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return max_cores | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Function needs type safety improvements and better documentation. Several issues need to be addressed:
Here's the suggested fix: - def validate_number_of_cores(max_cores: int, max_workers: int) -> int:
+ def validate_number_of_cores(max_cores: Optional[int], max_workers: Optional[int]) -> int:
"""
Validate the number of cores and return the appropriate value.
+
+ Args:
+ max_cores: Optional maximum number of cores
+ max_workers: Optional maximum number of workers
+
+ Returns:
+ int: 1 if both parameters are None,
+ max_workers if max_cores is None,
+ max_cores otherwise
"""
if max_workers is None and max_cores is None:
return 1
elif max_workers is not None and max_cores is None:
return max_workers
- else:
+ elif max_cores is not None:
return max_cores
+ else:
+ raise ValueError("Invalid combination of max_cores and max_workers") 📝 Committable suggestion
Suggested change
|
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.
💡 Codebase verification
Type mismatch in validate_number_of_cores function signature
The function signature in
executorlib/standalone/inputcheck.py
doesn't match the optional types:While the implementation correctly handles None values, the type hints need to be updated to
Optional[int]
to match the caller's signature.executorlib/standalone/inputcheck.py
: Update parameter types toOptional[int]
🔗 Analysis chain
Verify validation handling for None values.
While making
max_workers
andmax_cores
optional aligns with the PR objectives, we should ensure thatvalidate_number_of_cores
properly handles None values for both parameters.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1023
Script:
Length of output: 750