Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 63
add support for loky#263
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
add support for loky #263
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
498f56b
add support for loky
basnijholt 2ad5582
add loky.get_reusable_executor to the doc-string of the Runners
basnijholt f404f16
add loky docs
basnijholt df1b2fd
add Loky to (optional) dependencies
d23fa79
add test for Loky executor
2b70b7f
use a lambda in the loky test
basnijholt 33e7cae
make Loky the default executor when available
89e8649
reword loky docs part
basnijholt 0e99bdf
add loky to the intersphinx_mapping
basnijholt 8d97deb
do not import ipyparallel on Python 3.8
basnijholt 7448f01
shutdown loky executor after usage
basnijholt db051be
always shutdown.wait(True)
basnijholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -12,9 +12,13 @@ | ||
| from adaptive.notebook_integration import in_ipynb, live_info, live_plot | ||
| try: | ||
| import ipyparallel | ||
| if sys.version_info < (3, 8): | ||
| # XXX: remove when ipyparallel 6.2.5 is released | ||
| import ipyparallel | ||
| with_ipyparallel = True | ||
| with_ipyparallel = True | ||
| else: | ||
| with_ipyparallel = False | ||
| except ModuleNotFoundError: | ||
| with_ipyparallel = False | ||
| @@ -32,6 +36,13 @@ | ||
| except ModuleNotFoundError: | ||
| with_mpi4py = False | ||
| try: | ||
| import loky | ||
| with_loky = True | ||
| except ModuleNotFoundError: | ||
| with_loky = False | ||
| with suppress(ModuleNotFoundError): | ||
| import uvloop | ||
| @@ -232,10 +243,13 @@ def _remove_unfinished(self): | ||
| def _cleanup(self): | ||
| if self.shutdown_executor: | ||
| # XXX: temporary set wait=True for Python 3.7 | ||
| # XXX: temporary set wait=True because of a bug with Python ≥3.7 | ||
| # and loky in any Python version. | ||
| # see https://github.com/python-adaptive/adaptive/issues/156 | ||
| # and https://github.com/python-adaptive/adaptive/pull/164 | ||
| self.executor.shutdown(wait=True if sys.version_info >= (3, 7) else False) | ||
| # and https://bugs.python.org/issue36281 | ||
| # and https://github.com/joblib/loky/issues/241 | ||
| self.executor.shutdown(wait=True) | ||
| self.end_time = time.time() | ||
| @property | ||
| @@ -269,7 +283,8 @@ class BlockingRunner(BaseRunner): | ||
| the learner as its sole argument, and return True when we should | ||
| stop requesting more points. | ||
| executor : `concurrent.futures.Executor`, `distributed.Client`,\ | ||
| `mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional | ||
| `mpi4py.futures.MPIPoolExecutor`, `ipyparallel.Client` or\ | ||
| `loky.get_reusable_executor`, optional | ||
| The executor in which to evaluate the function to be learned. | ||
| If not provided, a new `~concurrent.futures.ProcessPoolExecutor`. | ||
| ntasks : int, optional | ||
| @@ -386,7 +401,8 @@ class AsyncRunner(BaseRunner): | ||
| stop requesting more points. If not provided, the runner will run | ||
| forever, or until ``self.task.cancel()`` is called. | ||
| executor : `concurrent.futures.Executor`, `distributed.Client`,\ | ||
| `mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional | ||
| `mpi4py.futures.MPIPoolExecutor`, `ipyparallel.Client` or\ | ||
| `loky.get_reusable_executor`, optional | ||
jbweston marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| The executor in which to evaluate the function to be learned. | ||
| If not provided, a new `~concurrent.futures.ProcessPoolExecutor`. | ||
| ntasks : int, optional | ||
| @@ -740,9 +756,16 @@ def shutdown(self, wait=True): | ||
| pass | ||
| def _default_executor(): | ||
| if with_loky: | ||
| return loky.get_reusable_executor() | ||
jbweston marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| else: | ||
| return concurrent.ProcessPoolExecutor() | ||
| def _ensure_executor(executor): | ||
| if executor is None: | ||
| executor = concurrent.ProcessPoolExecutor() | ||
| executor = _default_executor() | ||
| if isinstance(executor, concurrent.Executor): | ||
| return executor | ||
| @@ -765,6 +788,8 @@ def _get_ncores(ex): | ||
| ex, (concurrent.ProcessPoolExecutor, concurrent.ThreadPoolExecutor) | ||
| ): | ||
| return ex._max_workers # not public API! | ||
| elif with_loky and isinstance(ex, loky.reusable_executor._ReusablePoolExecutor): | ||
| return ex._max_workers # not public API! | ||
| elif isinstance(ex, SequentialExecutor): | ||
| return 1 | ||
| elif with_distributed and isinstance(ex, distributed.cfexecutor.ClientExecutor): | ||
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
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
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.