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

Gymnasium Upgrade #142

Merged
merged 68 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0d15ab6
gymnasium compatibility
Vittorio-Caggiano Dec 4, 2023
af13c63
fix simplified gym import
Vittorio-Caggiano Dec 12, 2023
e074db6
rewrite step totally oblivious to the gym version
Vittorio-Caggiano Dec 13, 2023
ad4e66a
update doc with gym/gymnasium aspecific import
Vittorio-Caggiano Dec 13, 2023
e899c85
fix test with gym/gymnasium
Vittorio-Caggiano Dec 13, 2023
8948b95
remove temp files
Vittorio-Caggiano Dec 13, 2023
74f2075
remove pin on
Vittorio-Caggiano Dec 13, 2023
8d8b5a5
add packaging dependency
Vittorio-Caggiano Dec 13, 2023
952287c
add missing fields for gym<=0.24
Vittorio-Caggiano Dec 13, 2023
875f907
fix step call for gym/gymnasium
Vittorio-Caggiano Dec 13, 2023
087f0ff
change reference to boading ball base env
Vittorio-Caggiano Dec 13, 2023
15bb47a
exclude mjrl tutorial
Vittorio-Caggiano Dec 13, 2023
af0c33b
add see for gymnasium
Vittorio-Caggiano Dec 14, 2023
c60740b
add explicitely seed
Vittorio-Caggiano Dec 14, 2023
4643149
move to gymnasium as default
Vittorio-Caggiano Dec 14, 2023
9a3aeb5
make the check not cyclical
Vittorio-Caggiano Dec 14, 2023
25300b5
show list packages
Vittorio-Caggiano Dec 14, 2023
67afdb6
update to gym/gymnasium
Vittorio-Caggiano Dec 17, 2023
374aa4f
add ci test for gym/gymnasium/stable-baselines3
Vittorio-Caggiano Dec 17, 2023
b089163
Merge branch 'dev' into add_gymnasium
Vittorio-Caggiano Dec 17, 2023
fe37e19
add ci test for gym/gymnasium/stable-baselines3
Vittorio-Caggiano Dec 17, 2023
0f9f3cb
add deprl package
Vittorio-Caggiano Dec 17, 2023
293b9b3
remove deprl test
Vittorio-Caggiano Dec 17, 2023
ca28e42
add gym/gymnasium/sb3 ci test
Vittorio-Caggiano Dec 17, 2023
8e03840
Reverting unwanted changes - mostly links and keywords
Dec 18, 2023
5c7f286
add gym/gymnasium/sb3 ci test
Vittorio-Caggiano Dec 18, 2023
d7305ea
restoring SAR tutorial
Vittorio-Caggiano Dec 18, 2023
606065c
clean up comments
Vittorio-Caggiano Dec 18, 2023
5e07c28
clean up comments
Vittorio-Caggiano Dec 18, 2023
cf6faf2
restore reference to robohive
Vittorio-Caggiano Dec 18, 2023
b3809b0
restore chasetag to latest version
Vittorio-Caggiano Dec 18, 2023
0451659
fix SAR tutorial
Vittorio-Caggiano Dec 18, 2023
e490086
remove promt as it triggers errors on mac on closing the session... t…
Vittorio-Caggiano Dec 18, 2023
8577a50
add control for checking missing gym/gymnasium
Vittorio-Caggiano Dec 18, 2023
b791669
add gym as startd requirement instead of gymnasium
Vittorio-Caggiano Dec 18, 2023
6d4c478
add test for sb for both gym and gymnasium
Vittorio-Caggiano Dec 18, 2023
a45eb97
add test sb3 with gym/gymnasium only on a smaller subset of tasks
Vittorio-Caggiano Dec 18, 2023
a48a242
replace gym with numpy random generator cc: @Pierre
Vittorio-Caggiano Dec 18, 2023
26107f8
test sb3 only with gymnasium
Vittorio-Caggiano Dec 18, 2023
1cec851
add torchrl script
Vittorio-Caggiano Dec 19, 2023
35a1827
update readme with torchrl info
Vittorio-Caggiano Dec 19, 2023
5efdf93
Update torchrl_job_script.py
vmoens Dec 19, 2023
2525133
Merge pull request #125 from MyoHub/add_torchrl
vmoens Dec 19, 2023
08a72a9
MAJOR: Gym/Gymnasium import. examine_sim upgraded to mujoco. hardcode…
vikashplus Dec 29, 2023
9cbac90
MINOR: Typo and minor update to readme
vikashplus Dec 29, 2023
8ea8f53
MINOR: Updating link
vikashplus Dec 29, 2023
bcf8bc4
FEATURE: Moving gym import to __init__ for a shorter import statement…
vikashplus Dec 29, 2023
d02006c
FEATURE: Moving gym import to __init__ for a shorter import statement
vikashplus Dec 29, 2023
0f89888
Finalizing gymnasium upgrade
vikashplus Jan 1, 2024
c47c536
Merge branch 'dev' into add_gymnasium
Vittorio-Caggiano Jan 3, 2024
e9bd387
Merge pull request #141 from MyoHub/add_gymnasium_bkp
vikashplus Jan 20, 2024
f9873cb
FEATURE+BUGFIX: Pulling updates from RoboHive 77b4347
vikashplus Jan 20, 2024
b1d8c54
MINOR: Formatting
vikashplus Jan 20, 2024
12de572
update changelog
Vittorio-Caggiano Feb 4, 2024
06c2a26
update changelog
Vittorio-Caggiano Feb 4, 2024
e89c652
update ack on changelog
Vittorio-Caggiano Feb 4, 2024
e601f2f
update PR # on changelog
Vittorio-Caggiano Feb 4, 2024
c2d9d7a
BUGFIX+TESTS: fixed env unwrapped bug. Paths were using wrapped envs.…
vikashplus Mar 9, 2024
90e163a
MINOR: improved names
vikashplus Mar 11, 2024
be14198
MINOR: forcing filename update
vikashplus Mar 11, 2024
ea5921d
Merge pull request #155 from MyoHub/naming_consistency
vikashplus Mar 12, 2024
df971d2
add task customization instructions
Vittorio-Caggiano Mar 25, 2024
27214b0
update task customization instructions
Vittorio-Caggiano Mar 25, 2024
d3c54cb
BUGFIX: Offline rendering bugfixes wrt to flipped images and default …
vikashplus Apr 30, 2024
2902cf2
Upgrading tests to catch gym incompatibility when custom reset is pro…
vikashplus Apr 30, 2024
825f026
DOCS: Improving docs for prompt utils
vikashplus Apr 30, 2024
481d4ca
update gh actions versions
Vittorio-Caggiano Apr 30, 2024
a0bd8de
update readme
Vittorio-Caggiano May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
[FEATURE] Support for both Gym/Gymnasium (#142)
[FEATURE] Add support for TorchRL by @vmoens (5efdf93)

## [2.2.0] - 2024-01-20
[FEATURE] Inverse dynamics tutorial. Thanks to @andreh1111 #121
[RELEASE] MyoArm and MyoLeg models (4c01023, cd9a25e)
[RELEASE] MyoChallenge'23 environments release (#128)
[BUGFIX] Fixed heightfield collisions for myoleg scenes #132
[BUGFIX] Fixed names of data keys from _int to _init in myodm by @andreh1111 in (#119)

## [1.3.0] - 2023-01-11
- Rebase and building on RoboHive v0.3
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: echo "SYSTEM_VERSION_COMPAT=0" >> $GITHUB_ENV

- name: Checkout repository and submodules
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -60,14 +60,14 @@ jobs:

- name: Enable Conda (macOS)
if: ${{ runner.os == 'macOS' }}
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-activate-base: false
python-version: 3.8

- name: Enable Conda (window/ubuntu)
if: ${{ runner.os != 'macOS' }}
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-activate-base: false

Expand Down Expand Up @@ -114,5 +114,9 @@ jobs:
- name: Run Test jupyter-notebooks tutorials
if: ${{ runner.os == 'Linux' }}
run: |
conda activate $CONDA_DEFAULT_ENV
source myosuite/tests/test_tutorials.sh
source myosuite/tests/test_tutorials.sh

- name: Run Test gym/gymnasium + stable-baselines3
if: ${{ runner.os == 'Linux' }}
run: |
source myosuite/tests/test_versions.sh
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ It is possible to create and interface with MyoSuite environments just like any


```python
import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoElbowPose1D6MRandom-v0')
env.reset()
for _ in range(1000):
Expand Down
3 changes: 1 addition & 2 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ For example, to use the ``myoElbowPose1D6MRandom-v0`` environment it is possible

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoElbowPose1D6MRandom-v0')
env.reset()
for _ in range(1000):
Expand Down
97 changes: 83 additions & 14 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Example on how to use an environment e.g. send random movements

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoElbowPose1D6MRandom-v0')
env.reset()
for _ in range(1000):
Expand All @@ -43,8 +42,7 @@ Example on how to generate and visualize a movement e.g. index flexion, and visu

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoHandPoseRandom-v0')
env.reset()
for _ in range(1000):
Expand All @@ -60,8 +58,7 @@ Example on using a policy e.g. elbow flexion, and change non-stationaries

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
policy = "iterations/best_policy.pickle"

import pickle
Expand All @@ -83,8 +80,7 @@ This example shows how to add fatigue to a model. It tests random actions on a m

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoElbowPose1D6MRandom-v0')
env.reset()
for _ in range(1000):
Expand All @@ -108,8 +104,7 @@ This example shows how to add sarcopenia or muscle weakness to a model. It tests

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoElbowPose1D6MRandom-v0')
env.reset()
for _ in range(1000):
Expand All @@ -134,8 +129,7 @@ This example shows how load a model with physical tendon transfer.

.. code-block:: python

import myosuite
import gym
from myosuite.utils import gym
env = gym.make('myoHandKeyTurnFixed-v0')
env.reset()
for _ in range(1000):
Expand Down Expand Up @@ -171,8 +165,7 @@ If you want to load and execute the pre-trained DEP-RL baseline. Make sure that

.. code-block:: python

import gym
import myosuite
from myosuite.utils import gym
import deprl

# we can pass arguments to the environments here
Expand All @@ -192,3 +185,79 @@ Load MyoReflex Baseline

To load and execute the MyoReflex controller with baseline parameters.
Run the MyoReflex tutorial `here <https://github.com/facebookresearch/myosuite/tree/main/docs/source/tutorials/4b_reflex>`__



Customizing Tasks
=================

In order to create a new customized task, there are two places where you need to act:

1. Set up a new environment class for the new task

2. Register the new task

Set up a new environment
+++++++++++++++++++++++++

Environment classes are developed according to the `OpenAI Gym definition <https://www.gymlibrary.dev/content/environment_creation/>`__
and contain all the information specific for a task,
to interact with the environment, to observe it and to
act on it. In addition, each environment class contains
a reward function which converts the observation into a
number that establishes how good the observation is with
respect to the task objectives. In order to create a new
task, a new environment class needs to be generated eg.
reach2_v0.py (see for example how `reach_v0.py <https://github.com/MyoHub/myosuite/blob/main/myosuite/envs/myo/myobase/reach_v0.py>`__ is structured).
In this file, it is possible to specify the type of observation (eg. joint angles, velocities, forces), actions (e.g. muscle, motors), goal, and reward.


.. code-block:: python

from myosuite.envs.myo.base_v0 import BaseV0

# Class extends Basev0
class NewReachEnvV0(BaseV0):
....

# defines the observation
def get_obs_dict(self, sim):
....

# defines the rewards
def get_reward_dict(self, obs_dict):
...

#reset condition that
def reset(self):
...

.. _setup_base_class:


Register the new environment
++++++++++++++++++++++++++++++

Once defined the task `reach2_v0.py`, the new environment needs to be registered to be
visible when importing `myosuite`. This is achieved by introducing the new environment in
the `__init__.py` (called when the library is imported) where the registration routine happens.
The registration of the new enviornment is obtained adding:

.. code-block:: python

from gym.envs.registration import register

register(id='newReachTask-v0',
entry_point='myosuite.envs.myo.myobase.reach_v0:NewReachEnvV0', # where to find the new Environment Class
max_episode_steps=200, # duration of the episode
kwargs={
'model_path': curr_dir+'/../assets/hand/myohand_pose.xml', # where the xml file of the environment is located
'target_reach_range': {'IFtip': ((0.1, 0.05, 0.20), (0.2, 0.05, 0.20)),}, # this is used in the setup to define the goal e.g. rando position of the team between 0.1 and 0.2 in the x coordinates
'normalize_act': True, # if to use normalized actions using a sigmoid function.
'frame_skip': 5, # collect a sample every 5 iteration step
}
)


.. _register_new_environment:

3 changes: 1 addition & 2 deletions docs/source/tutorials/1_Get_Started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
}
],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down
5 changes: 2 additions & 3 deletions docs/source/tutorials/2_Load_policy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down Expand Up @@ -79,7 +78,7 @@
" frames.append(frame)\n",
" o = env.get_obs()\n",
" a = pi.get_action(o)[0]\n",
" next_o, r, done, ifo = env.step(a) # take an action based on the current observation\n",
" next_o, r, done, *_, ifo = env.step(a) # take an action based on the current observation\n",
"env.close()\n",
"\n",
"os.makedirs('videos', exist_ok=True)\n",
Expand Down
5 changes: 2 additions & 3 deletions docs/source/tutorials/3_Analyse_movements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down Expand Up @@ -45,7 +44,7 @@
" for _ in range(100): # 100 samples for each episode\n",
" o = env.get_obs()\n",
" a = pi.predict(o)[0]\n",
" next_o, r, done, ifo = env.step(a) # take a random action\n",
" next_o, r, done, *_, ifo = env.step(a) # take a random action\n",
" \n",
" data_store.append({\"action\":a.copy(), \n",
" \"jpos\":env.sim.data.qpos.copy(), \n",
Expand Down
5 changes: 2 additions & 3 deletions docs/source/tutorials/4_Train_policy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down Expand Up @@ -122,7 +121,7 @@
" frames.append(frame[::-1,:,:])\n",
" o = env.get_obs()\n",
" a = pi.get_action(o)[0]\n",
" next_o, r, done, ifo = env.step(a) # take an action based on the current observation\n",
" next_o, r, done, *_, ifo = env.step(a) # take an action based on the current observation\n",
"env.close()\n",
"\n",
"os.makedirs('videos', exist_ok=True)\n",
Expand Down
17 changes: 4 additions & 13 deletions docs/source/tutorials/4a_deprl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
}
],
"source": [
"\n",
"import gym, myosuite\n",
"import deprl\n",
"import gym"
"from myosuite.utils import gym\n",
"import deprl"
]
},
{
Expand Down Expand Up @@ -75,10 +73,10 @@
"source": [
"policy = deprl.load_baseline(env)\n",
"\n",
"obs = env.reset()\n",
"obs = env.reset()[0]\n",
"for _ in range(T):\n",
" action = policy(obs)\n",
" obs, rew, done, info = env.step(action)\n",
" obs, rew, done, *_, info = env.step(action)\n",
" if done:\n",
" break\n",
"env.close()\n",
Expand All @@ -95,13 +93,6 @@
"source": [
"If you want to load your own policy, replace `deprl.load_baseline(env)` with `deprl.load(path, env)`. This will automatically load it for you. We also provide more advanced commands like `python -m deprl.play --path /folder/` to setup a visualization script."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
5 changes: 2 additions & 3 deletions docs/source/tutorials/4c_Train_SB_policy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down Expand Up @@ -92,7 +91,7 @@
" frames.append(frame[::-1,:,:])\n",
" o = env.get_obs()\n",
" a = pi.predict(o)[0]\n",
" next_o, r, done, ifo = env.step(a) # take an action based on the current observation\n",
" next_o, r, done, *_, ifo = env.step(a) # take an action based on the current observation\n",
"env.close()\n",
"\n",
"os.makedirs('videos', exist_ok=True)\n",
Expand Down
3 changes: 1 addition & 2 deletions docs/source/tutorials/5_Move_Hand_Fingers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import myosuite\n",
"import gym\n",
"from myosuite.utils import gym\n",
"import skvideo.io\n",
"import numpy as np\n",
"import os"
Expand Down
Loading
Loading