-
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
Cache: Use explicit arguments for serialize_funct_h5() #448
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2e78087
Cache: Use explicit arguments for serialize_funct_h5()
jan-janssen a5ffc6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 075c39c
Add resource dict
jan-janssen 2f5273c
Merge remote-tracking branch 'origin/serialize_funct_h5' into seriali…
jan-janssen ca0a804
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 25523b5
fix docstring
jan-janssen 4dd0b1b
Update submit function
jan-janssen 58f907d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2c64c16
Merge remote-tracking branch 'origin/main' into serialize_funct_h5
jan-janssen af994a2
Fix tests
jan-janssen 8784b22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6c5853a
Remove ExecutorSteps
jan-janssen 815ed41
Merge remote-tracking branch 'origin/main' into serialize_funct_h5
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 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 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 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 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 |
---|---|---|
|
@@ -8,7 +8,10 @@ | |
|
||
from executorlib.base.executor import ExecutorBase, cancel_items_in_queue | ||
from executorlib.standalone.command import get_command_path | ||
from executorlib.standalone.inputcheck import check_resource_dict | ||
from executorlib.standalone.inputcheck import ( | ||
check_resource_dict, | ||
check_resource_dict_is_empty, | ||
) | ||
from executorlib.standalone.interactive.communication import ( | ||
SocketInterface, | ||
interface_bootup, | ||
|
@@ -19,6 +22,37 @@ | |
|
||
|
||
class ExecutorBroker(ExecutorBase): | ||
def submit(self, fn: callable, *args, resource_dict: dict = {}, **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. | ||
""" | ||
check_resource_dict_is_empty(resource_dict=resource_dict) | ||
check_resource_dict(function=fn) | ||
f = Future() | ||
self._future_queue.put({"fn": fn, "args": args, "kwargs": kwargs, "future": f}) | ||
return f | ||
|
||
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False): | ||
"""Clean-up the resources associated with the Executor. | ||
|
||
|
@@ -57,46 +91,6 @@ def _set_process(self, process: List[RaisingThread]): | |
process.start() | ||
|
||
|
||
class ExecutorSteps(ExecutorBase): | ||
def submit(self, fn: callable, *args, resource_dict: dict = {}, **kwargs): | ||
""" | ||
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: | ||
A Future representing the given call. | ||
""" | ||
check_resource_dict(function=fn) | ||
f = Future() | ||
self._future_queue.put( | ||
{ | ||
"fn": fn, | ||
"args": args, | ||
"kwargs": kwargs, | ||
"future": f, | ||
"resource_dict": resource_dict, | ||
} | ||
) | ||
return f | ||
|
||
|
||
class InteractiveExecutor(ExecutorBroker): | ||
""" | ||
The executorlib.interactive.executor.InteractiveExecutor leverages the exeutorlib interfaces to distribute python | ||
|
@@ -151,7 +145,7 @@ def __init__( | |
) | ||
|
||
|
||
class InteractiveStepExecutor(ExecutorSteps): | ||
class InteractiveStepExecutor(ExecutorBase): | ||
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. Fix incorrect class name in docstring example The example in the docstring uses Update the example in the docstring: ->>> with PyFluxStepExecutor(max_cores=2) as p:
+>>> with InteractiveStepExecutor(max_cores=2) as p:
|
||
""" | ||
The executorlib.interactive.executor.InteractiveStepExecutor leverages the executorlib interfaces to distribute python | ||
tasks. In contrast to the mpi4py.futures.MPIPoolExecutor the executorlib.interactive.executor.InteractiveStepExecutor | ||
|
@@ -596,7 +590,10 @@ def _execute_task_with_cache( | |
|
||
future = task_dict["future"] | ||
task_key, data_dict = serialize_funct_h5( | ||
task_dict["fn"], *task_dict["args"], **task_dict["kwargs"] | ||
fn=task_dict["fn"], | ||
fn_args=task_dict["args"], | ||
fn_kwargs=task_dict["kwargs"], | ||
resource_dict=task_dict["resource_dict"], | ||
) | ||
os.makedirs(cache_directory, exist_ok=True) | ||
file_name = os.path.join(cache_directory, task_key + ".h5out") | ||
|
This file contains 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 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 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.
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.
Replace mutable default argument
Using a mutable default argument (empty dict) can lead to unexpected behavior when the default value is shared between function calls.
Apply this fix:
And add this check at the beginning of the method:
🧰 Tools
🪛 Ruff