@@ -148,7 +148,8 @@ need to write a new allocation function.
148148 from gen import gen_random_sample
149149 from sim import sim_find_sine
150150
151- libE_specs = LibeSpecs(nworkers = 4 , comms = " local" )
151+ if __name__ == " __main__" : # Python-quirk required on macOS and windows
152+ libE_specs = LibeSpecs(nworkers = 4 , comms = " local" )
152153
153154 We configure the settings and specifications for our ``sim_f `` and ``gen_f ``
154155 functions in the :ref: `GenSpecs<datastruct-gen-specs> ` and
@@ -159,45 +160,43 @@ need to write a new allocation function.
159160
160161 .. code-block :: python
161162 :linenos:
162- :lineno- start: 9
163-
164- gen_specs = GenSpecs(
165- gen_f = gen_random_sample, # Our generator function
166- out = [(" x" , float , (1 ,))], # gen_f output (name, type, size)
167- user = {
168- " lower" : np.array([- 3 ]), # lower boundary for random sampling
169- " upper" : np.array([3 ]), # upper boundary for random sampling
170- " gen_batch_size" : 5 , # number of x's gen_f generates per call
171- },
172- )
173-
174- sim_specs = SimSpecs(
175- sim_f = sim_find_sine, # Our simulator function
176- inputs = [" x" ], # InputArray field names. "x" from gen_f output
177- out = [(" y" , float )], # sim_f output. "y" = sine("x")
178- )
163+ :lineno- start: 10
164+
165+ gen_specs = GenSpecs(
166+ gen_f = gen_random_sample, # Our generator function
167+ out = [(" x" , float , (1 ,))], # gen_f output (name, type, size)
168+ user = {
169+ " lower" : np.array([- 3 ]), # lower boundary for random sampling
170+ " upper" : np.array([3 ]), # upper boundary for random sampling
171+ " gen_batch_size" : 5 , # number of x's gen_f generates per call
172+ },
173+ )
174+
175+ sim_specs = SimSpecs(
176+ sim_f = sim_find_sine, # Our simulator function
177+ inputs = [" x" ], # InputArray field names. "x" from gen_f output
178+ out = [(" y" , float )], # sim_f output. "y" = sine("x")
179+ )
179180
180181 We then specify the circumstances where
181182 libEnsemble should stop execution in :ref: `ExitCriteria<datastruct-exit-criteria> `.
182183
183184 .. code-block :: python
184185 :linenos:
185- :lineno- start: 25
186+ :lineno- start: 26
186187
187- exit_criteria = ExitCriteria(sim_max = 80 ) # Stop libEnsemble after 80 simulations
188+ exit_criteria = ExitCriteria(sim_max = 80 ) # Stop libEnsemble after 80 simulations
188189
189190 Now we're ready to write our libEnsemble :doc: `libE<../programming_libE> `
190191 function call. :ref: `ensemble.H<funcguides-history> ` is the final version of
191192 the history array. ``ensemble.flag `` should be zero if no errors occur.
192193
193194 .. code-block :: python
194195 :linenos:
195- :lineno- start: 27
196+ :lineno- start: 28
196197
197- ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs)
198- ensemble.add_random_streams() # setup the random streams unique to each worker
199-
200- if __name__ == " __main__" : # Python-quirk required on macOS and windows
198+ ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs)
199+ ensemble.add_random_streams() # setup the random streams unique to each worker
201200 ensemble.run() # start the ensemble. Blocks until completion.
202201
203202 history = ensemble.H # start visualizing our results
@@ -246,6 +245,7 @@ need to write a new allocation function.
246245
247246 .. code-block :: python
248247 :linenos:
248+ :lineno- start: 37
249249
250250 import matplotlib.pyplot as plt
251251
@@ -278,37 +278,37 @@ need to write a new allocation function.
278278
279279 .. code-block :: python
280280 :linenos:
281- :emphasize- lines: 13 , 14 ,15 ,25 ,32 ,33
281+ :emphasize- lines: 14 ,15 ,16 , 26 ,32 ,33
282282
283283 import numpy as np
284284 from libensemble import Ensemble
285285 from libensemble.specs import LibeSpecs, SimSpecs, GenSpecs, ExitCriteria
286286 from gen import gen_random_sample
287287 from sim import sim_find_sine
288288
289- libE_specs = LibeSpecs(nworkers = 4 , comms = " local" )
290-
291- gen_specs = GenSpecs(
292- gen_f = gen_random_sample, # Our generator function
293- out = [(" x" , float , (1 ,))], # gen_f output (name, type, size)
294- user = {
295- " lower" : np.array([- 6 ]), # lower boundary for random sampling
296- " upper" : np.array([6 ]), # upper boundary for random sampling
297- " gen_batch_size" : 10 , # number of x's gen_f generates per call
298- },
299- )
300-
301- sim_specs = SimSpecs(
302- sim_f = sim_find_sine, # Our simulator function
303- inputs = [" x" ], # InputArray field names. "x" from gen_f output
304- out = [(" y" , float )], # sim_f output. "y" = sine("x")
305- )
306-
307- exit_criteria = ExitCriteria(gen_max = 160 )
308-
309- ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs)
310- ensemble.add_random_streams()
311289 if __name__ == " __main__" :
290+ libE_specs = LibeSpecs(nworkers = 4 , comms = " local" )
291+
292+ gen_specs = GenSpecs(
293+ gen_f = gen_random_sample, # Our generator function
294+ out = [(" x" , float , (1 ,))], # gen_f output (name, type, size)
295+ user = {
296+ " lower" : np.array([- 6 ]), # lower boundary for random sampling
297+ " upper" : np.array([6 ]), # upper boundary for random sampling
298+ " gen_batch_size" : 10 , # number of x's gen_f generates per call
299+ },
300+ )
301+
302+ sim_specs = SimSpecs(
303+ sim_f = sim_find_sine, # Our simulator function
304+ inputs = [" x" ], # InputArray field names. "x" from gen_f output
305+ out = [(" y" , float )], # sim_f output. "y" = sine("x")
306+ )
307+
308+ exit_criteria = ExitCriteria(gen_max = 160 )
309+
310+ ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs)
311+ ensemble.add_random_streams()
312312 ensemble.run()
313313
314314 if ensemble.flag != 0 :
@@ -341,9 +341,9 @@ need to write a new allocation function.
341341
342342 .. code-block :: python
343343 :linenos:
344- :lineno- start: 7
344+ :lineno- start: 8
345345
346- # libE_specs = LibeSpecs(nworkers=4, comms="local")
346+ # libE_specs = LibeSpecs(nworkers=4, comms="local")
347347
348348 We'll be parameterizing our MPI runtime with a ``parse_args=True `` argument to
349349 the ``Ensemble `` class instead of ``libE_specs ``. We'll also use an ``ensemble.is_manager ``
@@ -353,15 +353,12 @@ need to write a new allocation function.
353353
354354 .. code-block :: python
355355 :linenos:
356- :lineno- start: 27
357-
358- # replace libE_specs with parse_args=True. Detects MPI runtime
359- ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, parse_args = True )
356+ :lineno- start: 28
360357
361- ensemble.add_random_streams()
362-
363- if __name__ == " __main__" :
358+ # replace libE_specs with parse_args=True. Detects MPI runtime
359+ ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, parse_args = True )
364360
361+ ensemble.add_random_streams()
365362 ensemble.run() # start the ensemble. Blocks until completion.
366363
367364 if ensemble.is_manager: # only True on rank 0
0 commit comments