Skip to content

Commit 7000bc5

Browse files
authored
Merge pull request #260 from python-adaptive/mpi-doc-fix
use __name__ == "__main__" for the MPIPoolExecutor
2 parents f2571c1 + d2985fe commit 7000bc5

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

azure-pipelines.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ jobs:
1212
matrix:
1313
UbuntuPy36:
1414
python.version: '3.6'
15-
vmImage: 'ubuntu-16.04'
15+
vmImage: 'ubuntu-latest'
1616
tox_env: 'py36'
1717
UbuntuPy37:
1818
python.version: '3.7'
19-
vmImage: 'ubuntu-16.04'
19+
vmImage: 'ubuntu-latest'
2020
tox_env: 'py37'
2121
UbuntuPy38:
2222
python.version: '3.8'
23-
vmImage: 'ubuntu-16.04'
23+
vmImage: 'ubuntu-latest'
2424
tox_env: 'py38'
2525

2626
macOSPy36:
2727
python.version: '3.6'
28-
vmImage: 'macOS-10.13'
28+
vmImage: 'macOS-latest'
2929
tox_env: 'py36'
3030
macOSPy37:
3131
python.version: '3.7'
32-
vmImage: 'macOS-10.13'
32+
vmImage: 'macOS-latest'
3333
tox_env: 'py37'
3434
macOSPy38:
3535
python.version: '3.8'
36-
vmImage: 'macOS-10.13'
36+
vmImage: 'macOS-latest'
3737
tox_env: 'py38'
3838

3939
WindowsServerPy36:

docs/source/tutorial/tutorial.parallelism.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,31 @@ For example, you create the following file called ``run_learner.py``:
6565
6666
from mpi4py.futures import MPIPoolExecutor
6767
68-
learner = adaptive.Learner1D(f, bounds=(-1, 1))
68+
# use the idiom below, see the warning at
69+
# https://mpi4py.readthedocs.io/en/stable/mpi4py.futures.html#mpipoolexecutor
70+
if __name__ == "__main__":
71+
72+
learner = adaptive.Learner1D(f, bounds=(-1, 1))
6973
70-
# load the data
71-
learner.load(fname)
74+
# load the data
75+
learner.load(fname)
7276
73-
# run until `goal` is reached with an `MPIPoolExecutor`
74-
runner = adaptive.Runner(
75-
learner,
76-
executor=MPIPoolExecutor(),
77-
shutdown_executor=True,
78-
goal=lambda l: l.loss() < 0.01,
79-
)
77+
# run until `goal` is reached with an `MPIPoolExecutor`
78+
runner = adaptive.Runner(
79+
learner,
80+
executor=MPIPoolExecutor(),
81+
shutdown_executor=True,
82+
goal=lambda l: l.loss() < 0.01,
83+
)
8084
81-
# periodically save the data (in case the job dies)
82-
runner.start_periodic_saving(dict(fname=fname), interval=600)
85+
# periodically save the data (in case the job dies)
86+
runner.start_periodic_saving(dict(fname=fname), interval=600)
8387
84-
# block until runner goal reached
85-
runner.ioloop.run_until_complete(runner.task)
88+
# block until runner goal reached
89+
runner.ioloop.run_until_complete(runner.task)
8690
87-
# save one final time before exiting
88-
learner.save(fname)
91+
# save one final time before exiting
92+
learner.save(fname)
8993
9094
9195
On your laptop/desktop you can run this script like:

0 commit comments

Comments
 (0)