Skip to content

use __name__ == "__main__" for the MPIPoolExecutor #260

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 4 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ jobs:
matrix:
UbuntuPy36:
python.version: '3.6'
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-latest'
tox_env: 'py36'
UbuntuPy37:
python.version: '3.7'
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-latest'
tox_env: 'py37'
UbuntuPy38:
python.version: '3.8'
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-latest'
tox_env: 'py38'

macOSPy36:
python.version: '3.6'
vmImage: 'macOS-10.13'
vmImage: 'macOS-latest'
tox_env: 'py36'
macOSPy37:
python.version: '3.7'
vmImage: 'macOS-10.13'
vmImage: 'macOS-latest'
tox_env: 'py37'
macOSPy38:
python.version: '3.8'
vmImage: 'macOS-10.13'
vmImage: 'macOS-latest'
tox_env: 'py38'

WindowsServerPy36:
Expand Down
36 changes: 20 additions & 16 deletions docs/source/tutorial/tutorial.parallelism.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,31 @@ For example, you create the following file called ``run_learner.py``:

from mpi4py.futures import MPIPoolExecutor

learner = adaptive.Learner1D(f, bounds=(-1, 1))
# use the idiom below, see the warning at
# https://mpi4py.readthedocs.io/en/stable/mpi4py.futures.html#mpipoolexecutor
if __name__ == "__main__":

learner = adaptive.Learner1D(f, bounds=(-1, 1))

# load the data
learner.load(fname)
# load the data
learner.load(fname)

# run until `goal` is reached with an `MPIPoolExecutor`
runner = adaptive.Runner(
learner,
executor=MPIPoolExecutor(),
shutdown_executor=True,
goal=lambda l: l.loss() < 0.01,
)
# run until `goal` is reached with an `MPIPoolExecutor`
runner = adaptive.Runner(
learner,
executor=MPIPoolExecutor(),
shutdown_executor=True,
goal=lambda l: l.loss() < 0.01,
)

# periodically save the data (in case the job dies)
runner.start_periodic_saving(dict(fname=fname), interval=600)
# periodically save the data (in case the job dies)
runner.start_periodic_saving(dict(fname=fname), interval=600)

# block until runner goal reached
runner.ioloop.run_until_complete(runner.task)
# block until runner goal reached
runner.ioloop.run_until_complete(runner.task)

# save one final time before exiting
learner.save(fname)
# save one final time before exiting
learner.save(fname)


On your laptop/desktop you can run this script like:
Expand Down