Skip to content

Commit

Permalink
* evolve: Eliminate use of 'toolbox' global variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
bje- committed Jan 3, 2025
1 parent 2d02c20 commit d8b1729
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions evolve
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def run_final(best):
json.dump(bundle, filehandle)


def run():
def run(toolbox):
"""Run the evolution."""
if args.verbose:
docstring = scenarios.supply_scenarios[args.supply_scenario].__doc__
Expand Down Expand Up @@ -331,15 +331,15 @@ if __name__ == '__main__':
strategy = cma.Strategy(centroid=[0] * numparams, sigma=args.sigma,
lambda_=args.lambda_)

toolbox = base.Toolbox()
toolbox.register("generate", strategy.generate, creator.Individual)
toolbox.register("update", strategy.update)
toolbox.register("evaluate", eval_func)
tbox = base.Toolbox()
tbox.register("generate", strategy.generate, creator.Individual)
tbox.register("update", strategy.update)
tbox.register("evaluate", eval_func)

set_start_method('spawn')
with Pool(args.ncpus if args.ncpus else None,
initializer=init_worker, initargs=(args,)) as pool:
toolbox.register("map", pool.map)
run()
tbox.register("map", pool.map)
run(tbox)
pool.close()
pool.join()

0 comments on commit d8b1729

Please sign in to comment.