icaros-usc / pyribs

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

Move threadpoolctl from optimizer to CMA-ES #241

Closed btjanaka closed 2 years ago

btjanaka commented 2 years ago

Description

Previously, we placed threadpoolctl in the optimizer in order to force OpenBLAS to run with only one thread in CMA-ES. However, this meant that all emitters would be affected by OpenBLAS, including ones defined by users. This commit moves threadpoolctl out of the optimizer and into CMA-ES, so that we only limit OpenBLAS in our code.

In #51, we mentioned that moving threadpoolctl to CMA-ES failed due to the overhead of creating the context manager. The new decorator from threadpoolctl seems to resolve this.

Here are some approximate times from running the sphere example (python examples/sphere.py cma_me_imp --dim 20 and python examples/sphere.py cma_me_imp --dim 100) with the different ways of calling threadpoolctl. Note that when threadpoolctl is disabled, the multithreading in OpenBLAS causes race conditions which slow down the execution (see #51).

Method 20-dim sphere 100-dim sphere
Only in CMA-ES (this PR) 55s 94s
In Optimizer (previous) 55s 98s
No threadpoolctl 60s 458s

TODO

Questions

Status