Skip to content

Commit

Permalink
feat: Add a functional API for optimization (#98)
Browse files Browse the repository at this point in the history
* feat: Add a functional API for optimization

This commit introduces an alternative API for
EvoTorch that conforms to the functional
programming paradigm. This functional API can
be used together with `torch.func.vmap`, and
therefore can be used for optimizing not just
a single population, but a batch of populations
simultaneously.

---------

Co-authored-by: Rupesh K Srivastava <rupesh@nnaisense.com>
  • Loading branch information
engintoklu and flukeskywalker committed Jun 6, 2024
1 parent 5c58566 commit ba26dc1
Show file tree
Hide file tree
Showing 22 changed files with 4,955 additions and 13 deletions.
9 changes: 9 additions & 0 deletions examples/notebooks/Functional_API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Functional API for Optimization

As an alternative to its object-oriented stateful API, EvoTorch provides an API that conforms to the functional programming paradigm. This functional API has its own advantages like being able to work on not just a single population, but on a batch of populations.

Here are the examples demonstrating various features of this functional API:

- **[Maintaining a batch of populations using the functional EvoTorch API](batched_searches.ipynb)**: This notebook shows how one can efficiently run multiple searches simultaneously, each with its own population and hyperparameter configuration, by maintaining a batch of populations.
- **[Solving constrained optimization problems](constrained.ipynb)**: EvoTorch provides batching-friendly constraint penalization functions that can be used with both the object-oriented API and the functional API. In addition, these constraint penalization functions can be used with gradient-based optimization. This notebook demonstrates these features.
- **[Solving reinforcement learning tasks using functional evolutionary algorithms](problem.ipynb)**: The functional evolutionary algorithm implementations of EvoTorch can be used to solve problems that are expressed using the object-oriented core API of EvoTorch. To demonstrate this, this notebook instantiates a `GymNE` problem for the reinforcement learning task "CartPole-v1", and solves it using the functional `pgpe` implementation.
428 changes: 428 additions & 0 deletions examples/notebooks/Functional_API/batched_searches.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit ba26dc1

Please sign in to comment.