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

Remove gym dependency #2074

Merged
merged 9 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-base-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
. ${{env.venv_dir}}/bin/activate
pip install --upgrade pip
pip install wheel==0.38.4
pip install -e .[camera_obs,opendrive,test,test_notebook,torch,train,gym,argoverse,envision,sumo]
pip install -e .[camera_obs,opendrive,test,test_notebook,torch,train,gif_recorder,gymnasium,argoverse,envision,sumo]
if echo ${{matrix.tests}} | grep -q -e "test_rllib_hiway_env.py" -e "test_examples.py"; then pip install -e .[rllib]; fi
if echo ${{matrix.tests}} | grep -q -e "/smarts/ray"; then pip install -e .[ray]; fi
- name: Build scenarios
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
pip install --upgrade pip
pip install wheel==0.38.4
pip install -e ./../../../.[camera_obs,argoverse,sumo,test]
pip install -e ./inference/
pip install -e ./inference/
- name: Run smoke tests
run: |
cd ${GITHUB_WORKSPACE}/examples/rl/${{matrix.tests}}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Loosened constraint of `gymnasium` from `==0.27.0` to `>=0.26.3`.
- `LaneFollowingController` now uses a different pole placement method to compute lateral/heading gains. Numerical behaviour is unchanged. Performance is slightly faster.
- Upgraded Stable Baselines3 from v1.7.0 to v2.0.0, and switched to Gymnasium backend, in Drive and VehicleFollowing RL examples.
- Changed all uses of `gym` to use `gymnasium`.
- Changed `gymnasium` to be an optional dependency. Use `pip install -e .[gymnasium]` to install it.
- Renamed the `[gym]` optional install to `[gif_recorder]`.
### Deprecated
### Fixed
- Missing neighborhood vehicle state `'lane_id'` is now added to the `hiway-v1` formatted observations.
- Fixed a regression where `pybullet` build time messages returned.
### Removed
- Removed `TruncatedDistribution` from scenario studio.
- Removed `scipy` as a core package dependency.
- Removed `gym` as a core package dependency.
- Removed `hiway-v0` env.
- Removed `Api021Reversion` gym wrapper class.
### Security

## [1.2.0] # 2023-06-14
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test: build-all-scenarios
--dist=loadscope \
-n `expr \( \`nproc\` \/ 2 \& \`nproc\` \> 3 \) \| 2` \
--nb-exec-timeout 65536 \
./examples/tests ./smarts/env ./envision ./smarts/core ./smarts/sstudio ./tests \
./examples/tests ./smarts/env ./envision ./smarts/core ./smarts/sstudio \
--ignore=./smarts/core/waymo_map.py \
--ignore=./smarts/core/argoverse_map.py \
--ignore=./smarts/core/tests/test_argoverse.py \
Expand All @@ -18,6 +18,7 @@ test: build-all-scenarios
--ignore=./smarts/core/tests/test_notebook.py \
--ignore=./smarts/env/tests/test_benchmark.py \
--ignore=./examples/tests/test_learning.py \
--ignore=./examples/tests/test_rl.py \
-k 'not test_long_determinism'
rm -f .coverage.*
rm -f .coverage*
Expand Down
45 changes: 1 addition & 44 deletions docs/sim/env.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,11 @@ Base environments
SMARTS environment module is defined in :mod:`~smarts.env` package. Currently SMARTS provides two kinds of training
environments, namely:

+ ``HiWayEnv`` utilizing a ``gymnasium.Env`` interface
+ ``HiWayEnvV1`` utilizing a ``gymnasium.Env`` interface
+ ``RLlibHiwayEnv`` customized for `RLlib <https://docs.ray.io/en/latest/rllib/index.html>`_ training

.. image:: ../_static/env.png

HiWayEnv
^^^^^^^^

``HiWayEnv`` inherits class ``gymnasium.Env`` and supports gym APIs like ``reset``, ``step``, ``close``. An usage example is shown below.
Refer to :class:`~smarts.env.hiway_env.HiWayEnv` for more details.

.. code-block:: python

import gymnasium as gym
# Make env
env = gym.make(
"smarts.env:hiway-v0", # Env entry name.
scenarios=[scenario_path], # List of paths to scenario folders.
agent_interfaces={AGENT_ID: agent_spec.interface}, # Dictionary mapping agents to agent interfaces.
headless=False, # False to enable Envision visualization of the environment.
seed=42, # RNG seed. Seeds are set at the start of simulation, and never automatically re-seeded.
)

# Reset env and build agent.
observations = env.reset()
agent = agent_spec.build_agent()

# Step env.
agent_obs = observations[AGENT_ID]
agent_action = agent.act(agent_obs)
observations, rewards, dones, infos = env.step({AGENT_ID: agent_action})

# Close env.
env.close()

HiWayEnvV1
^^^^^^^^^^

Expand Down Expand Up @@ -78,19 +48,6 @@ exactly matches the `env.observation_space`, and `ObservationOptions.multi_agent
# Close env.
env.close()

To use this environment with certain frameworks you may want to convert the environment back into a 0.21 api version of gym.
This can be done with :class:`~smarts.env.gymnasium.wrappers.api_reversion.Api021Reversion`.

.. code-block:: python

import gymnasium as gym
# Make env
env = gym.make(
"smarts.env:hiway-v1", # Env entry name.
scenarios=[scenario_path], # List of paths to scenario folders.
)
env = Api021Reversion(env) # Turns the environment into roughly a 0.21 gym environment

RLlibHiwayEnv
^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion docs/sim/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ For recording, simply feed ``envision_record_data_replay_path`` with desired rec
.. code-block:: python

env = gym.make(
"smarts.env:hiway-v0",
"smarts.env:hiway-v1",
scenarios=args.scenarios,
agents={AGENT_ID: agent},
headless=args.headless,
Expand Down
1 change: 0 additions & 1 deletion examples/rl/drive/train/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def make_env(env_id, scenario, agent_spec: AgentSpec, config, seed):
from reward import Reward
from stable_baselines3.common.monitor import Monitor

from smarts.env.gymnasium.wrappers.api_reversion import Api021Reversion
from smarts.env.gymnasium.wrappers.single_agent import SingleAgent

env = gym.make(
Expand Down
2 changes: 1 addition & 1 deletion examples/rl/drive/train/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
from contrib_policy.filter_obs import FilterObs
from contrib_policy.format_action import FormatAction
from contrib_policy.frame_stack import FrameStack
Expand Down
1 change: 0 additions & 1 deletion examples/rl/platoon/train/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def make_env(env_id, scenario, agent_spec: AgentSpec, config, seed):
from reward import Reward
from stable_baselines3.common.monitor import Monitor

from smarts.env.gymnasium.wrappers.api_reversion import Api021Reversion
from smarts.env.gymnasium.wrappers.single_agent import SingleAgent

env = gym.make(
Expand Down
21 changes: 8 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ install_requires =
PyYAML>=3.13
twisted>=21.7.0 # for scenario requirements.txt files

# The following are planned to be made optional
gymnasium>=0.26.3
pybullet>=3,<4.0

# The following are planned for removal
gym>=0.17.3,<=0.19.0
cloudpickle>=1.3.0,<=2.1.0
pybullet>=3,<4.0 # planned to be made optional
cloudpickle>=1.3.0,<=2.1.0 # planned for removal

[options.packages.find]
exclude =
Expand Down Expand Up @@ -70,7 +65,6 @@ dev =
diagnostic =
py-cpuinfo==9.0.0
mdutils==1.4.0
gym>=0.17.3,<=0.19.0
matplotlib>=3.2.2
doc =
myst-parser>=0.18.1
Expand All @@ -84,18 +78,19 @@ envision =
websocket-client>=1.2.1
ijson>=3.1.4
extras = pynput>=1.7.4 # Used by HumanKeyboardAgent
gym =
gif_recorder =
moviepy == 1.0.3
gymnasium =
gymnasium>=0.26.3
opendrive =
opendrive2lanelet>=1.2.1
Rtree>=0.9.7
remote_agent =
grpcio==1.32.0
rllib =
opencv-python==4.1.2.30
opencv-python-headless==4.1.2.30
ray[rllib]~=2.5.0
tensorflow-probability
tensorflow>=2.12.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember adding it to get a test to pass. I'll try removing it.

ray =
ray~=2.5.0
ros =
Expand Down Expand Up @@ -133,9 +128,9 @@ all =
%(doc)s
%(envision)s
%(extras)s
%(gym)s
%(gif_recorder)s
%(gymnasium)s
%(opendrive)s
%(remote_agent)s
%(rllib)s
# %(ray)s # incompatible with [rllib] for now
%(ros)s
Expand Down
7 changes: 0 additions & 7 deletions smarts/env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,5 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from gym.envs.registration import register

register(
id="hiway-v0",
entry_point="smarts.env.hiway_env:HiWayEnv",
)

# Do NOT remove.
import smarts.env.gymnasium
3 changes: 2 additions & 1 deletion smarts/env/gymnasium/hiway_env_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

import gymnasium as gym
import numpy as np
from gym import spaces

from gymnasium import spaces
from gymnasium.core import ActType, ObsType
from gymnasium.envs.registration import EnvSpec

Expand Down
42 changes: 0 additions & 42 deletions smarts/env/gymnasium/wrappers/api_reversion.py

This file was deleted.

Loading