-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Remove the __main__ restriction from examples #1053
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
8 commits
Select commit
Hold shift + click to select a range
31df41f
Allow to pass the context to each block
franchuterivera b932cfd
Re-enable examples without main
franchuterivera 1afaf9d
Intensification supports just 1 worker
franchuterivera 8572cef
spawn if provided dask client
franchuterivera d97cce7
Mock dask client
franchuterivera 99098aa
Flake fix
franchuterivera 375c12d
distributed wait redundant
franchuterivera 2193c53
Error out on unsupported calls
franchuterivera 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 |
|---|---|---|
|
|
@@ -75,3 +75,6 @@ coverage.xml | |
| *,cover | ||
| .hypothesis/ | ||
| prof/ | ||
|
|
||
| # Mypy | ||
| .mypy_cache/ | ||
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
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,86 @@ | ||
| import typing | ||
| from pathlib import Path | ||
|
|
||
| import dask.distributed | ||
|
|
||
|
|
||
| class DummyFuture(dask.distributed.Future): | ||
| """ | ||
| A class that mimics a distributed Future, the outcome of | ||
| performing submit on a distributed client. | ||
| """ | ||
| def __init__(self, result: typing.Any) -> None: | ||
| self._result = result # type: typing.Any | ||
|
|
||
| def result(self, timeout: typing.Optional[int] = None) -> typing.Any: | ||
| return self._result | ||
|
|
||
| def cancel(self) -> None: | ||
| pass | ||
|
|
||
| def done(self) -> bool: | ||
| return True | ||
|
|
||
| def __repr__(self) -> str: | ||
| return "DummyFuture: {}".format(self._result) | ||
|
|
||
| def __del__(self) -> None: | ||
| pass | ||
|
|
||
|
|
||
| class SingleThreadedClient(dask.distributed.Client): | ||
| """ | ||
| A class to Mock the Distributed Client class, in case | ||
| Auto-Sklearn is meant to run in the current Thread. | ||
| """ | ||
| def __init__(self) -> None: | ||
|
|
||
| # Raise a not implemented error if using a method from Client | ||
| implemented_methods = ['submit', 'close', 'shutdown', 'write_scheduler_file', | ||
| '_get_scheduler_info', 'nthreads'] | ||
| method_list = [func for func in dir(dask.distributed.Client) if callable( | ||
| getattr(dask.distributed.Client, func)) and not func.startswith('__')] | ||
| for method in method_list: | ||
| if method in implemented_methods: | ||
| continue | ||
| setattr(self, method, self._unsupported_method) | ||
| pass | ||
|
|
||
| def _unsupported_method(self) -> None: | ||
| raise NotImplementedError() | ||
|
|
||
| def submit( | ||
| self, | ||
| func: typing.Callable, | ||
| *args: typing.List, | ||
| priority: int = 0, | ||
| **kwargs: typing.Dict, | ||
| ) -> typing.Any: | ||
| return DummyFuture(func(*args, **kwargs)) | ||
|
|
||
| def close(self) -> None: | ||
| pass | ||
|
|
||
| def shutdown(self) -> None: | ||
| pass | ||
|
|
||
| def write_scheduler_file(self, scheduler_file: str) -> None: | ||
| Path(scheduler_file).touch() | ||
| return | ||
|
|
||
| def _get_scheduler_info(self) -> typing.Dict: | ||
| return { | ||
| 'workers': ['127.0.0.1'], | ||
| 'type': 'Scheduler', | ||
| } | ||
|
|
||
| def nthreads(self) -> typing.Dict: | ||
| return { | ||
| '127.0.0.1': 1, | ||
| } | ||
|
|
||
| def __repr__(self) -> str: | ||
| return 'SingleThreadedClient()' | ||
|
|
||
| def __del__(self) -> None: | ||
| pass | ||
|
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. Can we check automatically check which other methods are implemented by dask using inspection and automatically add these to the single-threaded client and raise a NotImplementedError so that we don't run into any issues in the future? |
||
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.
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.