-
Notifications
You must be signed in to change notification settings - Fork 3
Set max_cores and max_workers to None #478
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
Changes from all 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import inspect | ||
| import multiprocessing | ||
| from concurrent.futures import Executor | ||
| from typing import Callable, List, Optional | ||
|
|
||
|
|
@@ -131,12 +132,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
Contributor
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." | ||
| ) | ||
|
|
@@ -166,10 +169,15 @@ def check_pysqa_config_directory(pysqa_config_directory: Optional[str]) -> None: | |
| ) | ||
|
|
||
|
|
||
| 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. | ||
| """ | ||
| if max_workers != 1 and max_cores == 1: | ||
| if max_workers is None and max_cores is None: | ||
| return multiprocessing.cpu_count() | ||
| elif max_workers is not None and max_cores is None: | ||
| return max_workers | ||
| return max_cores | ||
| else: | ||
| return max_cores | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| check_max_workers_and_cores, | ||
| check_hostname_localhost, | ||
| check_pysqa_config_directory, | ||
| validate_number_of_cores, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -80,9 +81,9 @@ def test_check_flux_executor_pmi_mode(self): | |
|
|
||
| def test_check_max_workers_and_cores(self): | ||
| with self.assertRaises(ValueError): | ||
| check_max_workers_and_cores(max_workers=2, max_cores=1) | ||
| check_max_workers_and_cores(max_workers=2, max_cores=None) | ||
| with self.assertRaises(ValueError): | ||
| check_max_workers_and_cores(max_workers=1, max_cores=2) | ||
| check_max_workers_and_cores(max_workers=None, max_cores=2) | ||
| with self.assertRaises(ValueError): | ||
| check_max_workers_and_cores(max_workers=2, max_cores=2) | ||
|
|
||
|
|
@@ -95,3 +96,14 @@ def test_check_hostname_localhost(self): | |
| def test_check_pysqa_config_directory(self): | ||
| with self.assertRaises(ValueError): | ||
| check_pysqa_config_directory(pysqa_config_directory="path/to/config") | ||
|
|
||
| def test_validate_number_of_cores(self): | ||
| self.assertIsInstance( | ||
| validate_number_of_cores(max_cores=None, max_workers=None), int | ||
| ) | ||
| self.assertIsInstance( | ||
| validate_number_of_cores(max_cores=1, max_workers=None), int | ||
| ) | ||
| self.assertIsInstance( | ||
| validate_number_of_cores(max_cores=None, max_workers=1), int | ||
| ) | ||
|
Comment on lines
+100
to
+109
Contributor
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. 🛠️ Refactor suggestion Enhance test coverage and documentation for validate_number_of_cores While the test verifies return types, consider these improvements:
Example enhancement: def test_validate_number_of_cores(self):
"""
Test validate_number_of_cores function handles various input combinations
and returns expected core counts.
"""
# Test return types and values
self.assertEqual(
validate_number_of_cores(max_cores=None, max_workers=None),
os.cpu_count(), # Expected default
)
self.assertEqual(
validate_number_of_cores(max_cores=2, max_workers=None),
2,
)
self.assertEqual(
validate_number_of_cores(max_cores=None, max_workers=2),
os.cpu_count() // 2, # Expected cores divided by workers
)
# Test error cases
with self.assertRaises(ValueError):
validate_number_of_cores(max_cores=-1, max_workers=None)
with self.assertRaises(ValueError):
validate_number_of_cores(max_cores=None, max_workers=-1) |
||
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.pydoesn'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_workersandmax_coresoptional aligns with the PR objectives, we should ensure thatvalidate_number_of_coresproperly 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