icaros-usc / pyribs

A bare-bones Python library for quality diversity optimization.
https://pyribs.org
MIT License
205 stars 31 forks source link

[BUG] Lunar Lander tutorial pool.starmap() does not accept custom functions in interactive interpreter #346

Closed yutaizhou closed 10 months ago

yutaizhou commented 10 months ago

Description

The lunar lander tutorial's pool() function runs into error with using non-built-in function, simulate(), in __main__, when ran on VsCode's jupyter notebook.

AttributeError: Can't get attribute 'simulate' on <module '__main__' (built-in)>

The cause is as mentioned here. I was able to get around this issue by moving simulate() into its own file, pool_functions, then importing before passing into pool

import pool_functions

for itr in trange(1, total_itrs + 1, file=sys.stdout, desc='Iterations'):
...
 # Evaluate the models and record the objectives and measures.
    with multiprocessing.Pool(workers) as pool:
        results = pool.starmap(pool_functions.simulate, [(model, env_seed) for model in sols])

Not sure if this should be merged into master, as I have so far only ran into the issue and been able to test it on my MacBook.