-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor Task scheduler #637
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
59e4be8
refactor internal interfaces
jan-janssen 6ae7b7e
split task scheduler and executor
jan-janssen adbdb60
major refactoring
jan-janssen d7bdad7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 22eed9d
fix backends
jan-janssen b003cd6
Merge remote-tracking branch 'origin/task_scheduler' into task_scheduler
jan-janssen ddbb6d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0f054e3
fix imports
jan-janssen 636b5ba
Merge remote-tracking branch 'origin/task_scheduler' into task_scheduler
jan-janssen b8f73a8
fix hidden imports
jan-janssen 5e411b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3ba0dcd
Update documentation
jan-janssen b441dca
Merge remote-tracking branch 'origin/task_scheduler' into task_scheduler
jan-janssen e1a8a8c
revert file to cache
jan-janssen 124f925
rename cache file
jan-janssen b2962e2
another fix
jan-janssen 35c0532
last fixes
jan-janssen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import sys | ||
|
|
||
| from executorlib.cache.backend import backend_execute_task_in_file | ||
| from executorlib.task_scheduler.file.backend import backend_execute_task_in_file | ||
|
|
||
| if __name__ == "__main__": | ||
| backend_execute_task_in_file(file_name=sys.argv[1]) |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import queue | ||
| from concurrent.futures import ( | ||
| Executor as FutureExecutor, | ||
| ) | ||
| from concurrent.futures import ( | ||
| Future, | ||
| ) | ||
| from typing import Callable, Optional | ||
|
|
||
| from executorlib.task_scheduler.base import TaskSchedulerBase | ||
|
|
||
|
|
||
| class ExecutorBase(FutureExecutor): | ||
| """ | ||
| Interface class for the executor. | ||
|
|
||
| Args: | ||
| executor (TaskSchedulerBase): internal executor | ||
| """ | ||
|
|
||
| def __init__(self, executor: TaskSchedulerBase): | ||
| self._task_scheduler = executor | ||
|
|
||
| @property | ||
| def max_workers(self) -> Optional[int]: | ||
| return self._task_scheduler.max_workers | ||
|
|
||
| @max_workers.setter | ||
| def max_workers(self, max_workers: int): | ||
| self._task_scheduler.max_workers = max_workers | ||
|
|
||
| @property | ||
| def info(self) -> Optional[dict]: | ||
| """ | ||
| Get the information about the executor. | ||
|
|
||
| Returns: | ||
| Optional[dict]: Information about the executor. | ||
| """ | ||
| return self._task_scheduler.info | ||
|
|
||
| @property | ||
| def future_queue(self) -> Optional[queue.Queue]: | ||
| """ | ||
| Get the future queue. | ||
|
|
||
| Returns: | ||
| queue.Queue: The future queue. | ||
| """ | ||
| return self._task_scheduler.future_queue | ||
|
|
||
| def submit( # type: ignore | ||
| self, | ||
| fn: Callable, | ||
| /, | ||
| *args, | ||
| resource_dict: Optional[dict] = None, | ||
| **kwargs, | ||
| ) -> Future: | ||
| """ | ||
| Submits a callable to be executed with the given arguments. | ||
|
|
||
| Schedules the callable to be executed as fn(*args, **kwargs) and returns | ||
| a Future instance representing the execution of the callable. | ||
|
|
||
| Args: | ||
| fn (callable): function to submit for execution | ||
| args: arguments for the submitted function | ||
| kwargs: keyword arguments for the submitted function | ||
| resource_dict (dict): resource dictionary, which defines the resources used for the execution of the | ||
| function. Example resource dictionary: { | ||
| cores: 1, | ||
| threads_per_core: 1, | ||
| gpus_per_worker: 0, | ||
| oversubscribe: False, | ||
| cwd: None, | ||
| executor: None, | ||
| hostname_localhost: False, | ||
| } | ||
|
|
||
| Returns: | ||
| Future: A Future representing the given call. | ||
| """ | ||
| return self._task_scheduler.submit( | ||
| *([fn] + list(args)), resource_dict=resource_dict, **kwargs | ||
| ) | ||
|
|
||
| def shutdown(self, wait: bool = True, *, cancel_futures: bool = False): | ||
| """ | ||
| Clean-up the resources associated with the Executor. | ||
|
|
||
| It is safe to call this method several times. Otherwise, no other | ||
| methods can be called after this one. | ||
|
|
||
| Args: | ||
| wait (bool): If True then shutdown will not return until all running | ||
| futures have finished executing and the resources used by the | ||
| parallel_executors have been reclaimed. | ||
| cancel_futures (bool): If True then shutdown will cancel all pending | ||
| futures. Futures that are completed or running will not be | ||
| cancelled. | ||
| """ | ||
| self._task_scheduler.shutdown(wait=wait, cancel_futures=cancel_futures) | ||
|
|
||
| def __len__(self) -> int: | ||
| """ | ||
| Get the length of the executor. | ||
|
|
||
| Returns: | ||
| int: The length of the executor. | ||
| """ | ||
| return len(self._task_scheduler) | ||
|
|
||
| def __exit__(self, *args, **kwargs) -> None: | ||
| """ | ||
| Exit method called when exiting the context manager. | ||
| """ | ||
| self._task_scheduler.__exit__(*args, **kwargs) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing
__enter__breaks context-manager usageExecutorBaseimplements__exit__but not__enter__.Any subclass used with a
with-statement (see the doctstrings for the Slurm executors) will fail.Add a trivial pass-through implementation:
📝 Committable suggestion