icaros-usc / pyribs

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

Add PyCMAEvolutionStrategy for using pycma in ES emitters #434

Closed btjanaka closed 6 months ago

btjanaka commented 6 months ago

Description

Currently, we only provide our custom implementation of CMA-ES for use with emitters like EvolutionStrategyEmitter. This PR instead makes it possible to use the pycma implementation of CMA-ES, which provides many more features.

In emitters, pycma can now be used by passing es="pycma_es" as an argument.

pycma can be installed separately with pip install cma; this PR also provides an extra for installing it with pip install ribs[pycma]. I have also added cma under the all extra; I believe it is a good idea to have the pycma extra and have cma under the all extra because pycma is fairly stable, so depending on it should be fine.

TODO

Example Outputs

(These are fairly consistent across runs)

cma_me_imp (set the es parameter to cma_es or pycma_es inside sphere.py):

Our CMA-ES:

Create Scheduler for cma_me_imp with learning rate 1.0 and add mode batch, using solution dim 20, archive dims (500, 500), and 15 emitters.
Iteration 250 | Archive Coverage: 18.436% QD Score: 4422557.102
Iteration 500 | Archive Coverage: 29.236% QD Score: 6886947.626
Iteration 750 | Archive Coverage: 40.558% QD Score: 9295140.818
Iteration 1000 | Archive Coverage: 55.431% QD Score: 12105614.271
Iteration 1250 | Archive Coverage: 65.508% QD Score: 13774296.004
Iteration 1500 | Archive Coverage: 72.332% QD Score: 14767106.638
Iteration 1750 | Archive Coverage: 78.571% QD Score: 15628185.304
Iteration 2000 | Archive Coverage: 81.630% QD Score: 16075205.193
Iteration 2250 | Archive Coverage: 84.147% QD Score: 16391622.812
Iteration 2500 | Archive Coverage: 86.269% QD Score: 16764425.062
Iteration 2750 | Archive Coverage: 88.213% QD Score: 17039262.660
Iteration 3000 | Archive Coverage: 90.166% QD Score: 17342512.202
Iteration 3250 | Archive Coverage: 91.337% QD Score: 17505068.566
Iteration 3500 | Archive Coverage: 92.187% QD Score: 17611056.311
Iteration 3750 | Archive Coverage: 92.411% QD Score: 17638383.915
Iteration 4000 | Archive Coverage: 92.882% QD Score: 17685042.031
Iteration 4250 | Archive Coverage: 93.278% QD Score: 17764361.816
Iteration 4500 | Archive Coverage: 93.398% QD Score: 17792564.912
100%|███████████████████████████████████████████████████████| 4500/4500 [00:37<00:00, 121.04it/s]
Algorithm Time (Excludes Logging and Setup): 27.589414358139038s

With pycma CMA-ES:

Create Scheduler for cma_me_imp with learning rate 1.0 and add mode batch, using solution dim 20, archive dims (500, 500), and 15 emitters.
Iteration 250 | Archive Coverage: 18.369% QD Score: 4421017.381
Iteration 500 | Archive Coverage: 32.998% QD Score: 7718952.239
Iteration 750 | Archive Coverage: 47.248% QD Score: 10660291.659
Iteration 1000 | Archive Coverage: 61.361% QD Score: 13229427.018
Iteration 1250 | Archive Coverage: 71.946% QD Score: 14927574.916
Iteration 1500 | Archive Coverage: 79.135% QD Score: 16002255.296
Iteration 1750 | Archive Coverage: 84.764% QD Score: 16758346.119
Iteration 2000 | Archive Coverage: 89.135% QD Score: 17293875.851
Iteration 2250 | Archive Coverage: 92.056% QD Score: 17641038.587
Iteration 2500 | Archive Coverage: 93.736% QD Score: 17824591.298
Iteration 2750 | Archive Coverage: 94.524% QD Score: 17921700.563
Iteration 3000 | Archive Coverage: 95.107% QD Score: 18003408.425
Iteration 3250 | Archive Coverage: 95.278% QD Score: 18038041.474
Iteration 3500 | Archive Coverage: 95.574% QD Score: 18067125.317
Iteration 3750 | Archive Coverage: 95.867% QD Score: 18089722.810
Iteration 4000 | Archive Coverage: 95.971% QD Score: 18115817.866
Iteration 4250 | Archive Coverage: 96.054% QD Score: 18132526.811
Iteration 4500 | Archive Coverage: 96.167% QD Score: 18151481.017
100%|████████████████████████████████████████████████████████| 4500/4500 [01:31<00:00, 49.06it/s]
Algorithm Time (Excludes Logging and Setup): 81.55640316009521s

Status