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 3 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Renamed `rllib/rllib.py` to `rllib/pg_pbt_example.py`.
- 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.
- Changed all uses of `gym` to use `gymnasium`.
### 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 `hiway-v0` env.
- Removed `TruncatedDistribution` from scenario studio.
- Removed `scipy` as a core package dependency.
- Removed `gym` as a core dependency.
### 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
32 changes: 1 addition & 31 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
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
2 changes: 1 addition & 1 deletion examples/rl/drive/inference/contrib_policy/filter_obs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
from typing import Any, Dict, Sequence, Tuple

import gym
import gymnasium as gym
import numpy as np

from smarts.core.agent_interface import RGB
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Callable, Tuple

import gym
import gymnasium as gym
import numpy as np

from smarts.core.controllers import ActionSpaceType
Expand Down
2 changes: 1 addition & 1 deletion examples/rl/drive/inference/contrib_policy/frame_stack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
from collections import deque

import gym
import gymnasium as gym
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion examples/rl/drive/inference/contrib_policy/make_dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict

import gym
import gymnasium as gym
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion examples/rl/drive/inference/contrib_policy/network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import torch as th
import torch.nn as nn
from stable_baselines3.common.preprocessing import get_flattened_obs_dim
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
2 changes: 1 addition & 1 deletion examples/rl/drive/train/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from itertools import cycle, islice
from typing import Any, Dict

import gym
import gymnasium as gym

# Load inference module to register agent
import inference
Expand Down
2 changes: 1 addition & 1 deletion examples/rl/platoon/inference/contrib_policy/filter_obs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
from typing import Any, Dict, Sequence, Tuple

import gym
import gymnasium as gym
import numpy as np

from smarts.core.agent_interface import RGB
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Callable, Tuple

import gym
import gymnasium as gym
import numpy as np

from smarts.core.controllers import ActionSpaceType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
from collections import deque

import gym
import gymnasium as gym
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion examples/rl/platoon/inference/contrib_policy/make_dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict

import gym
import gymnasium as gym
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion examples/rl/platoon/inference/contrib_policy/network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import torch as th
import torch.nn as nn
from stable_baselines3.common.preprocessing import get_flattened_obs_dim
Expand Down
2 changes: 1 addition & 1 deletion examples/rl/platoon/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
4 changes: 3 additions & 1 deletion examples/rl/platoon/train/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from itertools import cycle, islice
from typing import Any, Dict

import gym
import gymnasium as gym

sys.modules["gym"] = gym

# Load inference module to register agent
import inference
Expand Down
6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ install_requires =
pybullet>=3,<4.0

# The following are planned for removal
gym>=0.17.3,<=0.19.0
cloudpickle>=1.3.0,<=2.1.0

[options.packages.find]
Expand Down Expand Up @@ -70,7 +69,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 @@ -89,13 +87,12 @@ gym =
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 @@ -135,7 +132,6 @@ all =
%(extras)s
%(gym)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
2 changes: 1 addition & 1 deletion smarts/env/gymnasium/wrappers/api_reversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.
from typing import Any, Dict, SupportsFloat, Tuple

import gym
import gymnasium as gym


class Api021Reversion(gym.Wrapper):
Adaickalavan marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading