@@ -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