Skip to content

Commit

Permalink
Update panda3d for python 3.10 (#2080)
Browse files Browse the repository at this point in the history
* Update panda3d for python 3.10

* Unpin cloudpickle.

* Fix figure eight.

* Attempt colab fixes.

* Update setup to support python 3.10.

* Attempt further fixes.

* Fix tests.

* Update dependencies and add version install test.

* Fix checkout action.

* Remove dev tags.

* Fix wrapper numpy integer.

* Run version test only on master.

* Update changelog.
  • Loading branch information
Gamenot authored Aug 1, 2023
1 parent ae62ee5 commit 9b10fbc
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 213 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci-python-version-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: SMARTS CI Python Version Tests

on:
push:
branches:
- master

env:
venv_dir: .venv

jobs:
install_python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Update requirements
run: |
cd $GITHUB_WORKSPACE
python${{ matrix.python-version }} -m venv ${{env.venv_dir}}
. ${{env.venv_dir}}/bin/activate
pip install --upgrade pip
pip install wheel==0.38.4
pip install .[camera_obs,rllib,sumo,test,torch,train]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Copy and pasting the git commit messages is __NOT__ enough.
## [Unreleased] - XXXX-XX-XX
### Added
### Changed
- The following dependencies have been loosened: `numpy`, `opencv`, `torch`.
### Deprecated
### Fixed
- The `smarts` package now works with `python3.10` and `python3.11`.
### Removed
### Security

Expand Down
Empty file added examples/env/__init__.py
Empty file.
44 changes: 19 additions & 25 deletions examples/env/create_run_visualize.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "wkR0YvENQni4"
Expand All @@ -22,7 +23,7 @@
"outputs": [],
"source": [
"!git clone https://github.com/huawei-noah/SMARTS 2> /dev/null\n",
"!cd SMARTS && ls && git checkout develop && pip install .[camera_obs]"
"!cd SMARTS && ls && git checkout tucker/fix_for_python_3_10 && pip install .[camera_obs,gymnasium]"
]
},
{
Expand All @@ -37,12 +38,16 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"\n",
"sys.path.insert(0, \"/content/SMARTS/\")"
"sys.path.insert(0, Path(os.path.abspath(\"\")).parents[1])\n",
"print(Path(os.path.abspath(\"\")) / \"SMARTS\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "s7UtcphinvNv"
Expand All @@ -59,13 +64,14 @@
},
"outputs": [],
"source": [
"import gym\n",
"import gymnasium as gym\n",
"\n",
"from smarts.zoo import registry\n",
"from smarts.env.gymnasium.wrappers.episode_logger import EpisodeLogger"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "LFoG7Z-FobPP"
Expand All @@ -88,14 +94,13 @@
"outputs": [],
"source": [
"from smarts.core.utils.episodes import episode_range\n",
"from smarts.env.wrappers.record_video import RecordVideo\n",
"from smarts.core.utils.import_utils import import_module_from_file\n",
"\n",
"import examples.env.figure_eight_env\n",
"\n",
"env = gym.make(\"figure_eight-v0\")\n",
"env: gym.Env = RecordVideo(\n",
" env, video_folder=\"videos\", video_length=40, step_trigger=lambda s: s % 100 == 0\n",
"import_module_from_file(\n",
" \"examples.env.figure_eight_env\", Path(os.path.abspath(\"\")) / \"figure_eight_env.py\"\n",
")\n",
"\n",
"env = gym.make(\"figure_eight-v0\", disable_env_checker=True)\n",
"env: gym.Env = EpisodeLogger(env)\n",
"\n",
"import zoo.policies.keep_lane_agent\n",
Expand All @@ -104,24 +109,13 @@
"\n",
"for episode in episode_range(max_steps=450):\n",
" observation = env.reset()\n",
" reward, done, info = None, False, None\n",
" while episode.continues(observation, reward, done, info):\n",
" reward, terminated, truncated, info = None, False, False, None\n",
" while episode.continues(observation, reward, terminated, truncated, info):\n",
" action = agent.act(observation)\n",
" observation, reward, done, info = env.step(action)\n",
" observation, reward, terminated, info = env.step(action)\n",
"\n",
"env.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from smarts.env.wrappers.utils.rendering import show_notebook_videos\n",
"\n",
"show_notebook_videos()"
]
}
],
"metadata": {
Expand All @@ -130,7 +124,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.8.10 ('.venv': venv)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -148,7 +142,7 @@
},
"vscode": {
"interpreter": {
"hash": "94261e0756b8490ed1a668b85ed1da8c98261f1072b842b18d4e3da7517b644d"
"hash": "983a288b1deae516b5d1a3268f286490dc1a3bd215a042403a142fb3df5f8acd"
}
}
},
Expand Down
31 changes: 31 additions & 0 deletions examples/env/crv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys
from pathlib import Path

import gymnasium as gym
from gymnasium.wrappers.record_video import RecordVideo

from smarts.core.utils.episodes import Episode, episode_range, episodes
from smarts.env.gymnasium.wrappers.episode_logger import EpisodeLogger
from smarts.zoo import registry

SMARTS_DIR = Path(os.path.abspath(""))
sys.path.insert(0, SMARTS_DIR)

from examples.env import figure_eight_env

env = gym.make("figure_eight-v0", disable_env_checker=True)
env: gym.Env = EpisodeLogger(env)

import zoo.policies.keep_lane_agent

agent = registry.make_agent("zoo.policies:keep-lane-agent-v0")

for episode in episode_range(max_steps=450):
observation, info = env.reset()
reward, terminated, truncated, info = None, False, False, None
while episode.continues(observation, reward, terminated, truncated, info):
action = agent.act(observation)
observation, reward, _, terminated, info = env.step(action)

env.close()
10 changes: 9 additions & 1 deletion examples/env/figure_eight_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from smarts.core.agent_interface import AgentInterface, AgentType
from smarts.env.gymnasium.wrappers.single_agent import SingleAgent
from smarts.env.utils.action_conversion import ActionOptions
from smarts.env.utils.observation_conversion import ObservationOptions

agent_interface = AgentInterface.from_type(
AgentType.Laner,
Expand All @@ -27,8 +29,14 @@ def entry_point(*args, **kwargs):
agent_interfaces={"agent-007": agent_interface},
scenarios=[scenario],
headless=True,
action_options=ActionOptions.unformatted,
observation_options=ObservationOptions.unformatted,
disable_env_checker=True,
)
env.metadata["render.modes"] = set(env.metadata["render.modes"]) | {"rgb_array"}
env.unwrapped.render_mode = "rgb_array"
env.metadata["render_modes"] = set(env.metadata.get("render_modes", ())) | {
"rgb_array"
}
return SingleAgent(env)


Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_rllib_pg_example():
from examples.rl.rllib import pg_example

main = pg_example.main
with tempfile.TemporaryDirectory() as result_dir, tempfile.TemporaryDirectory() as model_dir:
with tempfile.TemporaryDirectory() as result_dir:
main(
scenarios=["./scenarios/sumo/loop"],
envision=False,
Expand Down
22 changes: 11 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ classifiers=
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
License :: OSI Approved :: MIT License

[options]
Expand All @@ -25,8 +26,7 @@ install_requires =
setuptools>=41.0.0,!=50.0
click>=7.1.2 # used in scl
# numpy>=1.19.5 required for tf 2.4
# numpy<1.24 required for ray (see https://github.com/ray-project/ray/issues/31258)
numpy>=1.19.5,<1.24.0
numpy>=1.19.5
psutil>=5.4.8
shapely>=2.0.0
tableprint>=0.9.1
Expand All @@ -35,8 +35,8 @@ install_requires =
PyYAML>=3.13
twisted>=21.7.0 # for scenario requirements.txt files

pybullet>=3,<4.0 # planned to be made optional
cloudpickle>=1.3.0,<=2.1.0 # planned for removal
pybullet>=3,<4.0 # planned to be made optional (For >3.9 this requires python3.<ver>-dev)
cloudpickle>=1.3.0 # planned for removal

[options.packages.find]
exclude =
Expand All @@ -52,7 +52,7 @@ argoverse =
av2>=0.2.1
Rtree>=0.9.7
camera_obs =
Panda3D==1.10.9
Panda3D>=1.10.13
panda3d-gltf==0.13
dev =
black[jupyter]==22.6.0
Expand Down Expand Up @@ -86,8 +86,8 @@ opendrive =
opendrive2lanelet>=1.2.1
Rtree>=0.9.7
rllib =
opencv-python==4.1.2.30
opencv-python-headless==4.1.2.30
opencv-python>=4.1.2.30,<5.0
opencv-python-headless>=4.1.2.30,<5.0
ray[rllib]~=2.5.0
tensorflow-probability
ray =
Expand All @@ -96,7 +96,7 @@ ros =
catkin_pkg
rospkg
sumo =
eclipse-sumo>=1.12.0 # sumo
eclipse-sumo>=1.12.0
Rtree>=0.9.7 # technically optional, but used by sumo internally for performance (see `getNeighboringLanes()`)
test = # The following are for testing
pytest>=6.2.5
Expand All @@ -109,8 +109,8 @@ test_notebook =
jupyter-client>=7.1.2
pytest-notebook>=0.7.0
torch =
torch==1.4.0
torchvision==0.5.0
torch>=1.4.0
torchvision>=0.5.0
train =
tensorflow>=2.4.0
visdom =
Expand All @@ -130,8 +130,8 @@ all =
%(gif_recorder)s
%(gymnasium)s
%(opendrive)s
%(ray)s
%(rllib)s
# %(ray)s # incompatible with [rllib] for now
%(ros)s
%(sumo)s
%(test)s
Expand Down
8 changes: 4 additions & 4 deletions smarts/core/utils/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ class Episode:
def __init__(self, episodes: Episodes):
self._episodes = episodes

def continues(self, observation, reward, done, info) -> bool:
def continues(self, observation, reward, terminated, truncated, info) -> bool:
"""Determine if the current episode can continue."""

self._episodes.current_step += 1

if self._episodes.current_step >= self._episodes.max_steps:
return False
if isinstance(done, dict):
return not done.get("__all__", all(done.values()))
return not done
if isinstance(terminated, dict):
return not terminated.get("__all__", all(terminated.values()))
return not terminated


def episode_range(max_steps):
Expand Down
2 changes: 1 addition & 1 deletion smarts/engine.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[benchmark]
[core]
debug = false
debug = False
observation_workers = 0
reset_retries = 0
[controllers]
Expand Down
5 changes: 4 additions & 1 deletion smarts/env/gymnasium/hiway_env_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ def render(
Note:
Make sure that your class's :attr:`metadata` ``"render_modes"`` key includes the list of supported modes.
"""
if "rgb_array" in self.metadata["render_modes"]:
if (
"rgb_array" in self.metadata["render_modes"]
or self.render_mode == "rgb_array"
):
if self._env_renderer is None:
from smarts.env.utils.record import AgentCameraRGBRender

Expand Down
2 changes: 1 addition & 1 deletion smarts/env/gymnasium/wrappers/metric/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def nearest_waypoint(
Returns:
Tuple[Tuple[int, int], Optional[int]] : `matrix` index of shape (a,b) and scalar `point` index.
"""
cur_point_index = ((np.int(1e10), np.int(1e10)), None)
cur_point_index = ((np.int32(1e10), np.int32(1e10)), None)

if points.shape == (0,):
return cur_point_index
Expand Down
Loading

0 comments on commit 9b10fbc

Please sign in to comment.