Skip to content

Commit

Permalink
Upgrade gym to Gymnasium (#35)
Browse files Browse the repository at this point in the history
* Simplify extras_require

* Rm gym-robotics ; gym -> gymnasium

* Python 3.10

* new extra dependency in CI

* `import gym` -> `import gymnasium as gym`

* render.modes -> render_modes

* reset returns info

* black and isort

* Fix CI extra requires

* Remove SB3 and numpgw extra dependency

* obs or state -> observation

* black

* replavec done by trun and term when appeled

* black

* gym -> gymnasium

* Step return trunc and term

* compute_reward returns float32, is_success returns bool

* float64 -> float32

* fix typing

* black

* Allow return tuple documentation

* Fix doc

* Remove unused import

* panda_tasks in a single file

* black

* fix pip install notebook

* improve save_restore documentation

* documentation save and restore state

* Python version in CI: 3.X to '3.X'

* profile black to isort

* typo

* fix reset arg and dtype

* Fix CI because pytype can't be installed on windows

* v3

* Clean notebook
  • Loading branch information
qgallouedec authored Oct 12, 2022
1 parent bdc9ae1 commit e23e0c9
Show file tree
Hide file tree
Showing 42 changed files with 578 additions and 593 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -18,7 +18,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[tests]
pip install -e .
pip install pytest-cov
- name: Test with pytest
run: |
pytest --cov=./ --cov-report=xml
Expand All @@ -28,7 +29,7 @@ jobs:
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
codestyle_and_doc:
codestyle_type_and_doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -39,14 +40,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[docs,codestyle]
pip install -e .[develop]
- name: Pytype
run: |
pytype panda_gym
- name: Check codestyle
run: |
black -l 127 --check panda_gym test
isort -l 127 --check panda_gym test
isort -l 127 --profile black --check panda_gym test
- name: Make docs
run: |
make html
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# panda-gym

Set of OpenAI/gym robotic environments based on PyBullet physics engine.
Set of robotic environments based on PyBullet physics engine and gymnasium.

[![PyPI version](https://img.shields.io/pypi/v/panda-gym.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/panda-gym/)
[![Downloads](https://pepy.tech/badge/panda-gym)](https://pepy.tech/project/panda-gym)
Expand Down Expand Up @@ -32,16 +32,19 @@ pip install -e panda-gym
## Usage

```python
import gym
import gymnasium as gym
import panda_gym

env = gym.make('PandaReach-v2', render=True)
env = gym.make('PandaReach-v3', render=True)

obs = env.reset()
done = False
while not done:
observation, info = env.reset()

for _ in range(1000):
action = env.action_space.sample() # random action
obs, reward, done, info = env.step(action)
observation, reward, terminated, truncated, info = env.step(action)

if terminated or truncated:
observation, info = env.reset()

env.close()
```
Expand All @@ -52,12 +55,12 @@ You can also [![Open in Colab](https://colab.research.google.com/assets/colab-ba

| | |
| :------------------------------: | :--------------------------------------------: |
| `PandaReach-v2` | `PandaPush-v2` |
| ![PandaReach-v2](docs/_static/img/reach.png) | ![PandaPush-v2](docs/_static/img/push.png) |
| `PandaSlide-v2` | `PandaPickAndPlace-v2` |
| ![PandaSlide-v2](docs/_static/img/slide.png) | ![PandaPickAndPlace-v2](docs/_static/img/pickandplace.png) |
| `PandaStack-v2` | `PandaFlip-v2` |
| ![PandaStack-v2](docs/_static/img/stack.png) | ![PandaFlip-v2](docs/_static/img/flip.png) |
| `PandaReach-v3` | `PandaPush-v3` |
| ![PandaReach-v3](docs/_static/img/reach.png) | ![PandaPush-v3](docs/_static/img/push.png) |
| `PandaSlide-v3` | `PandaPickAndPlace-v3` |
| ![PandaSlide-v3](docs/_static/img/slide.png) | ![PandaPickAndPlace-v3](docs/_static/img/pickandplace.png) |
| `PandaStack-v3` | `PandaFlip-v3` |
| ![PandaStack-v3](docs/_static/img/stack.png) | ![PandaFlip-v3](docs/_static/img/flip.png) |

## Baselines results

Expand Down
267 changes: 113 additions & 154 deletions docs/_static/notebook/PickAndPlace.ipynb
Original file line number Diff line number Diff line change
@@ -1,157 +1,116 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/qgallouedec/panda-gym/blob/colab/PickAndPlace.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TFFVaHq_7fSe"
},
"source": [
"# `panda-gym` code example\n",
"\n",
"## Install `panda-gym`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gvS3_Wp_6rqE",
"outputId": "0c25d21e-d823-4b4c-88bd-6eb1a0425acd"
},
"outputs": [],
"source": [
"!pip install panda-gym"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qE8atPQm870Q"
},
"source": [
"## Interract"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "gLQSKOE_8_kB"
},
"outputs": [],
"source": [
"import gym\n",
"import panda_gym\n",
"\n",
"env = gym.make('PandaPickAndPlace-v2', render=True)\n",
"state = env.reset()\n",
"\n",
"done = False\n",
"images = [env.render('rgb_array')]\n",
"while not done:\n",
" action = env.action_space.sample()\n",
" state, reward, done, info = env.step(action)\n",
" images.append(env.render('rgb_array'))\n",
"\n",
"env.close()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Nkl-EtEZ_EQH"
},
"source": [
"## Convert into animation\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "E2eWDjPZsQc5",
"outputId": "83bb407d-ea87-49a3-e61d-291f7db7f824"
},
"outputs": [],
"source": [
"!pip3 install numpngw\n",
"from numpngw import write_apng\n",
"\n",
"write_apng('anim.png', images, delay=40) # real-time rendering = 40 ms between frames"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dFadL1ne_NG8"
},
"source": [
"## Show animation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 737
},
"id": "5mJ2AQYN-22E",
"outputId": "620d7be1-13cf-4c60-a934-a1806e1bc4a9"
},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"\n",
"Image(filename=\"anim.png\")"
]
}
],
"metadata": {
"colab": {
"authorship_tag": "ABX9TyPoojQ0oWlcLJWd6nANAzj6",
"collapsed_sections": [],
"include_colab_link": true,
"name": "PickAndPlace.ipynb",
"provenance": []
},
"interpreter": {
"hash": "8e193b2e5d21c2e374c02529de74b36a677b513007ad2ca2b9715beb5c35b2ac"
},
"kernelspec": {
"display_name": "Python 3.7.5 64-bit ('env': venv)",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.9"
}
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/qgallouedec/panda-gym/blob/colab/PickAndPlace.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
"nbformat": 4,
"nbformat_minor": 0
{
"cell_type": "markdown",
"metadata": {
"id": "TFFVaHq_7fSe"
},
"source": [
"# `panda-gym` code example\n",
"\n",
"## Install `panda-gym`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install panda-gym"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qE8atPQm870Q"
},
"source": [
"## Interract"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import gymnasium as gym\n",
"import panda_gym\n",
"\n",
"env = gym.make(\"PandaPickAndPlace-v3\", render=True)\n",
"observation, info = env.reset()\n",
"\n",
"images = [env.render(\"rgb_array\")]\n",
"for _ in range(1000):\n",
" action = env.action_space.sample()\n",
" observation, reward, terminated, truncated, info = env.step(action)\n",
" images.append(env.render(\"rgb_array\"))\n",
"\n",
" if terminated or truncated:\n",
" observation, info = env.reset()\n",
" images.append(env.render(\"rgb_array\"))\n",
"\n",
"env.close()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Nkl-EtEZ_EQH"
},
"source": [
"## Convert into animation\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip3 install numpngw\n",
"from numpngw import write_apng\n",
"\n",
"write_apng(\"anim.png\", images, delay=40) # real-time rendering = 40 ms between frames"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dFadL1ne_NG8"
},
"source": [
"## Show animation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"\n",
"Image(filename=\"anim.png\")"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit e23e0c9

Please sign in to comment.