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

Make EvoTorch future-proof #77

Merged
merged 10 commits into from
Oct 2, 2023
Merged

Make EvoTorch future-proof #77

merged 10 commits into from
Oct 2, 2023

Conversation

engintoklu
Copy link
Collaborator

Some of the dependencies of EvoTorch became deprecated over time. This pull request aims to replace those deprecated requirements with their up-to-date counterparts. In more details, the following changes are introduced:

  • If available, use torch.func instead of functorch
  • For getting the storage address of a tensor, use x.untyped_storage().data_ptr() instead of x.storage().data_ptr(), if available
  • Use gymnasium instead of gym
  • Introduce an EvoTorch-specific adapter between gymnasium and brax, instead of relying on the deprecated gym wrapper of brax

Status.
Currently, the unit tests pass successfully. Apart from the unit tests, test runs are still needed to ensure the correctness of these changes.

Some of the dependencies of EvoTorch became
deprecated over time. This commit aims to
replace those deprecated requirements with their
up-to-date counterparts.
In more details, the following changes are
introduced:

- If available, use `torch.func` instead of
  `functorch`
- For getting the storage address of a tensor,
  use `x.untyped_storage().data_ptr()`
  instead of `x.storage().data_ptr()`,
  if available
- Use `gymnasium` instead of `gym`
- Introduce an EvoTorch-specific adapter between
  `gymnasium` and `brax`, instead of relying on
  the deprecated `gym` wrapper of `brax`

Status: after the changes introduced by this
commit, the unit tests pass successfully.
Apart from the unit tests, test runs are still
needed to ensure the correctness of these
changes.
@engintoklu engintoklu self-assigned this May 28, 2023
@engintoklu engintoklu added the enhancement New feature or request label May 28, 2023
@codecov
Copy link

codecov bot commented May 28, 2023

Codecov Report

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

Comparison is base (9d31d59) 77.83% compared to head (29f5103) 76.90%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
- Coverage   77.83%   76.90%   -0.94%     
==========================================
  Files          49       49              
  Lines        7332     7455     +123     
==========================================
+ Hits         5707     5733      +26     
- Misses       1625     1722      +97     
Files Coverage Δ
src/evotorch/algorithms/mapelites.py 83.87% <100.00%> (+0.17%) ⬆️
src/evotorch/core.py 74.34% <100.00%> (-0.16%) ⬇️
src/evotorch/neuroevolution/gymne.py 79.37% <100.00%> (-0.16%) ⬇️
src/evotorch/neuroevolution/net/rl.py 51.63% <100.00%> (ø)
src/evotorch/neuroevolution/vecgymne.py 79.70% <100.00%> (ø)
src/evotorch/tools/__init__.py 100.00% <ø> (ø)
src/evotorch/tools/readonlytensor.py 72.82% <100.00%> (+0.29%) ⬆️
src/evotorch/logging.py 90.29% <75.00%> (-0.31%) ⬇️
src/evotorch/tools/objectarray.py 72.51% <80.00%> (-0.27%) ⬇️
src/evotorch/neuroevolution/net/functional.py 93.75% <92.00%> (+1.02%) ⬆️
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This commit updates the example notebooks
demonstrating reinforcement learning and model
predictive control, so that they adopt the API
of the `gymnasium` library.
Brax v0.9.0 has a new set of implementations
for its tasks. The old ones (which were the
default until brax v0.1.2) are now within the
namespace `brax.v1`.
This commit extends `VecGymNE` with the ability
to instantiate tasks from the namespace
`brax.v1`, so that it will be possible to
reproduce older results.
The pybullet humanoid example within the
directory `examples/scripts/` is updated so that
it works correctly with the new `GymNE`
(which now uses the `gymnasium` library).

At the moment of writing this, PyBullet
environments (within the module `pybullet_envs`)
do not have direct interfaces for `gymnasium`,
and they fail with the latest version of the
classical `gym` (i.e. gym v0.26).
Therefore, for the pybullet humanoid example to
work, one needs to install the classical `gym`
like this: `pip install 'gym<0.26'`
(while ensuring that `gymnasium` is also
installed).
examples/scripts/rl_enjoy.py Outdated Show resolved Hide resolved
examples/scripts/rl_enjoy.py Outdated Show resolved Hide resolved
src/evotorch/neuroevolution/net/rl.py Outdated Show resolved Hide resolved
src/evotorch/neuroevolution/net/vecrl.py Outdated Show resolved Hide resolved
src/evotorch/neuroevolution/net/vecrl.py Outdated Show resolved Hide resolved
src/evotorch/neuroevolution/net/vecrl.py Outdated Show resolved Hide resolved
@Higgcz Higgcz marked this pull request as ready for review October 2, 2023 15:06
@Higgcz Higgcz changed the title WIP: Make EvoTorch future-proof Make EvoTorch future-proof Oct 2, 2023
@Higgcz Higgcz merged commit dddc9c5 into master Oct 2, 2023
4 checks passed
@Higgcz Higgcz deleted the feature/future-proof branch October 2, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants