-
Notifications
You must be signed in to change notification settings - Fork 45
Bug fix in EvaluationManager #748
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
Open
weslleyspereira
wants to merge
1
commit into
llnl:develop
Choose a base branch
from
weslleyspereira:fix-bug-eval-manager
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| Weslley S Pereira <[email protected]> | ||
| """ | ||
|
|
||
| import threading | ||
| import logging | ||
| import copy | ||
| import os | ||
|
|
@@ -71,6 +72,7 @@ def __init__( | |
| cpu_executor=None, | ||
| mpi_executor=None) -> None: | ||
| self._queue = deque([]) | ||
| self._queue_lock = threading.Lock() | ||
| self.logger = logging.getLogger(self.__class__.__name__) | ||
|
|
||
| self.executors = { | ||
|
|
@@ -100,24 +102,23 @@ def sync(self) -> None: | |
| future_objs = [queue_obj[1] for queue_obj in self._queue] | ||
| wait(future_objs) | ||
|
|
||
| def submit_tasks(self, fn, X, execute_at="cpu", *args, **kwargs) -> None: | ||
| def submit_tasks(self, fn, X, execute_at="cpu", **kwargs) -> None: | ||
| """Submits tasks to the specified executor. | ||
|
|
||
| :param fn: The function to be executed. | ||
| :param X: The sequence of input data for the function. | ||
| :param execute_at: The executor to use for task submission. It can be | ||
| "cpu" for intra-node parallelism or "mpi" for inter-node | ||
| parallelism. | ||
| :param args: Additional positional arguments to be passed to the | ||
| function. | ||
| :param kwargs: Additional keyword arguments to be passed to the | ||
| function. | ||
| """ | ||
| key = execute_at.lower() | ||
| for x in X: | ||
| future_obj = self.executors[key].submit(fn, x, *args, **kwargs) | ||
| self._queue.append([copy.deepcopy(x), future_obj]) | ||
| self.logger.info(f"Submitted f({x})") | ||
| with self._queue_lock: | ||
| for x in X: | ||
| future_obj = self.executors[key].submit(fn, x, **kwargs) | ||
| self._queue.append([copy.deepcopy(x), future_obj]) | ||
| self.logger.info(f"Submitted f({x})") | ||
|
|
||
| def retrieve_results(self) -> tuple[list, list]: | ||
| """Retrieves the results of completed tasks. | ||
|
|
@@ -127,33 +128,31 @@ def retrieve_results(self) -> tuple[list, list]: | |
| """ | ||
| X = deque([]) | ||
| F = deque([]) | ||
| Idxs = deque([]) | ||
| new_queue = deque([]) | ||
| for i, item in enumerate(self._queue): | ||
| x = item[0] | ||
| future = item[1] | ||
| if future.done(): | ||
| # Try to get result | ||
| try: | ||
| fx = future.result() | ||
| Idxs.append(i) | ||
| except CancelledError: | ||
| self.logger.warning(f"The execution of x={x} was cancelled.") | ||
| continue | ||
|
|
||
| # Add result to the output | ||
| X.append(x) | ||
| F.append(fx) | ||
| self.logger.info(f"Completed: f({x}) = {fx}") | ||
| else: | ||
| # Keep the future in the queue | ||
| new_queue.append(item) | ||
|
|
||
| # Remove completed tasks from the queue | ||
| self._queue = new_queue | ||
|
|
||
| X = [X[Idxs[i]] for i in range(len(Idxs))] | ||
| F = [F[Idxs[i]] for i in range(len(Idxs))] | ||
|
|
||
| with self._queue_lock: | ||
| new_queue = deque([]) | ||
| for item in self._queue: | ||
| x = item[0] | ||
| future = item[1] | ||
| if future.done(): | ||
| # Try to get result | ||
| try: | ||
| fx = future.result() | ||
| except CancelledError: | ||
| self.logger.warning(f"The execution of x={x} was cancelled.") | ||
| continue | ||
|
|
||
| # Add result to the output | ||
| X.append(x) | ||
| F.append(fx) | ||
| self.logger.info(f"Completed: f({x}) = {fx}") | ||
| else: | ||
| # Keep the future in the queue | ||
| new_queue.append(item) | ||
|
|
||
| # Remove completed tasks from the queue | ||
| self._queue = new_queue | ||
|
|
||
| return list(X), list(F) | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.