Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyCMAEvolutionStrategy for using pycma in ES emitters #434

Merged
merged 20 commits into from
Dec 9, 2023
Merged

Conversation

btjanaka
Copy link
Member

@btjanaka btjanaka commented Dec 8, 2023

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

  • Add extra for installing pycma
  • Register pycma in ribs.emitters.opt
  • Implement PyCMAEvolutionStrategy
  • Benchmark PyCMA-ME on sphere -> tends to do slightly better but much slower
  • Write tests

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

  • I have read the guidelines in
    CONTRIBUTING.md
  • I have formatted my code using yapf
  • I have tested my code by running pytest
  • I have linted my code with pylint
  • I have added a one-line description of my change to the changelog in
    HISTORY.md
  • This PR is ready to go

btjanaka added a commit that referenced this pull request Dec 9, 2023
## Description

<!-- Provide a brief description of the PR's purpose here. -->

This PR adds the `ranking_values` argument to the tell() method in
evolution strategies. This paves the way for #434, since pycma needs the
ranking values to be passed into tell().

Note that I considered removing ranking_values from `check_stop` and
instead forcing the ES to store its own ranking values like pycma does,
but I do not think this is a necessary change.

This change is backwards-incompatible, but similar to #436, I do not
think it will affect most users.

## TODO

<!-- Notable points that this PR has either accomplished or will
accomplish. -->

- [x] Update EvolutionStrategyBase and corresponding ESs
- [x] Update emitter calls
- [x] Remove redundant method docstrings

## Questions

<!-- Any concerns or points of confusion? -->

## Status

- [x] I have read the guidelines in

[CONTRIBUTING.md](https://github.com/icaros-usc/pyribs/blob/master/CONTRIBUTING.md)
- [x] I have formatted my code using `yapf`
- [x] I have tested my code by running `pytest`
- [x] I have linted my code with `pylint`
- [x] I have added a one-line description of my change to the changelog
in
      `HISTORY.md`
- [x] This PR is ready to go
@btjanaka btjanaka merged commit ff84fd2 into master Dec 9, 2023
17 checks passed
@btjanaka btjanaka deleted the pycmaes branch December 9, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant