Skip to content
Merged
Changes from 1 commit
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
34 changes: 18 additions & 16 deletions docs/source/tutorial/tutorial.parallelism.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,29 @@ For example, you create the following file called ``run_learner.py``:

from mpi4py.futures import MPIPoolExecutor

learner = adaptive.Learner1D(f, bounds=(-1, 1))
if __name__ == "__main__": # ← use this, see warning @ https://bit.ly/2HAk0GG
Comment thread
basnijholt marked this conversation as resolved.
Outdated

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