nnaisense / evotorch

Advanced evolutionary computation library built directly on top of PyTorch, created at NNAISENSE.
https://evotorch.ai
Apache License 2.0
997 stars 62 forks source link

Allow the user to reach the search algorithm's internal optimizer #89

Closed engintoklu closed 11 months ago

engintoklu commented 11 months ago

With this pull request, algorithms inheriting from the base class GaussianSearchAlgorithm now have a read-only property (named optimizer) that allows the user to reach the internal optimizer object employed by the search algorithm.

By reaching this internal optimizer, the user can now read or modify its hyperparameters.

For example, the learning rate of an internal optimizer (e.g. of Adam or ClipUp) can be retrieved like this:

from evotorch.algorithms import PGPE

my_search_algorithm = PGPE(
    optimizer="adam",  # can also be "sgd" or "clipup"
    ...
)

lr = my_search_algorithm.optimizer.param_groups[0]["lr"]

If one wishes to update the learning rate, the following is possible:

my_search_algorithm.optimizer.param_groups[0]["lr"] = new_lr
codecov[bot] commented 11 months ago

Codecov Report

Attention: 20 lines in your changes are missing coverage. Please review.

Comparison is base (9d31d59) 77.83% compared to head (e79e1bc) 77.66%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #89 +/- ## ========================================== - Coverage 77.83% 77.66% -0.18% ========================================== Files 49 49 Lines 7332 7373 +41 ========================================== + Hits 5707 5726 +19 - Misses 1625 1647 +22 ``` | [Files](https://app.codecov.io/gh/nnaisense/evotorch/pull/89?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nnaisense) | Coverage Δ | | |---|---|---| | [src/evotorch/algorithms/distributed/gaussian.py](https://app.codecov.io/gh/nnaisense/evotorch/pull/89?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nnaisense#diff-c3JjL2V2b3RvcmNoL2FsZ29yaXRobXMvZGlzdHJpYnV0ZWQvZ2F1c3NpYW4ucHk=) | `83.00% <66.66%> (-0.25%)` | :arrow_down: | | [src/evotorch/optimizers.py](https://app.codecov.io/gh/nnaisense/evotorch/pull/89?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nnaisense#diff-c3JjL2V2b3RvcmNoL29wdGltaXplcnMucHk=) | `77.20% <50.00%> (-10.55%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/nnaisense/evotorch/pull/89/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nnaisense)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.