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

Extract visdom. #2003

Merged
merged 4 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Copy and pasting the git commit messages is __NOT__ enough.

## [Unreleased]
### Added
- `visdom` can now be configured through the engine.ini configuration file `visdom:enabled`, `visdom:hostname`, and `visdom:port` (environment variables `SMARTS_VISDOM_ENABLED`, `SMARTS_VISDOM_HOSTNAME`, `SMARTS_VISDOM_PORT`.)
### Changed
### Deprecated
- `visdom` is set to be removed from the SMARTS object parameters.
### Fixed
### Removed
### Security
Expand Down
2 changes: 0 additions & 2 deletions docs/sim/env.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Refer to :class:`~smarts.env.hiway_env.HiWayEnv` for more details.
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.
visdom=False, # Visdom visualization of observations. False to disable. Only supported in HiwayEnv.
seed=42, # RNG seed. Seeds are set at the start of simulation, and never automatically re-seeded.
)

Expand Down Expand Up @@ -60,7 +59,6 @@ exactly matches the `env.observation_space`, and `ObservationOptions.multi_agent
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.
visdom=False, # Visdom visualization of observations. False to disable. Only supported in HiwayEnv.
seed=42, # RNG seed. Seeds are set at the start of simulation, and never automatically re-seeded.
observation_options=ObservationOptions.multi_agent, # Configures between padded and un-padded agents in observations.
)
Expand Down
23 changes: 11 additions & 12 deletions docs/sim/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,19 @@ Start the visdom server before running the scenario and open the server URL in y
.. code-block:: bash

# Install visdom
$ pip install visdom
# Start the server
$ visdom
$ pip install smarts[visdom]

Enable Visdom in the SMARTS environment by setting ``visdom=True``. For example:
Enable Visdom in the SMARTS environment by setting ``SMARTS_VISDOM_ENABLED``. For example:

.. code-block:: python

env = gym.make(
"smarts.env:hiway-v0", # env entry name
...
visdom=True, # whether or not to enable visdom visualization (see Appendix).
...
)
.. code-block:: ini

; ./smarts_engine.ini | ~/.smarts/engine.ini | /etc/smarts/engine.ini | $PYTHON_PATH/smarts/engine.ini
[core]
...
[visdom]
enabled=True
hostname="http://localhost"
port=8097

Below is a sample visualization of an agent's camera sensor observations.

Expand Down
1 change: 0 additions & 1 deletion examples/control/ego_open_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def main(scenarios, headless, num_episodes):
scenarios=scenarios,
agent_interfaces={AGENT_ID: open_agent_spec.interface},
headless=headless,
visdom=False,
sumo_headless=True,
)

Expand Down
11 changes: 3 additions & 8 deletions examples/replay/replay_klws_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ def copytree(src, dst, symlinks=False, ignore=None):
if os.path.lexists(d):
os.remove(d)
os.symlink(os.readlink(s), d)
try:
st = os.lstat(s)
mode = stat.S_IMODE(st.st_mode)
os.lchmod(d, mode)
except Exception as e:
print(e)
pass # lchmod not available
st = os.lstat(s)
mode = stat.S_IMODE(st.st_mode)
os.chmod(d, mode, follow_symlinks=False)
elif os.path.isdir(s):
copytree(s, d, symlinks, ignore)
else:
Expand Down Expand Up @@ -81,7 +77,6 @@ def main(scenarios, sim_name, headless, seed, speed, max_steps, save_dir, write)
agent_specs={AGENT_ID: agent_spec},
sim_name=sim_name,
headless=headless,
visdom=False,
timestep_sec=0.1,
sumo_headless=True,
seed=seed,
Expand Down
1 change: 0 additions & 1 deletion examples/rl/intersection/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
smarts:
# Environment
visdom: False # If True, enables Visdom display.
sumo_gui: False # If True, enables sumo-gui display.
img_meters: 50 # Observation image area size in meters.
img_pixels: 112 # Observation image size in pixels.
Expand Down
12 changes: 9 additions & 3 deletions examples/rl/intersection/intersection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@
" env = gym.make(\n",
" \"smarts.env:intersection-v0\",\n",
" headless=True,\n",
" visdom=False,\n",
" sumo_headless=True,\n",
" img_meters=config[\"img_meters\"],\n",
" img_pixels=config[\"img_pixels\"],\n",
Expand Down Expand Up @@ -512,11 +511,18 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"name": "python",
"version": "3.8.10"
},
"vscode": {
"interpreter": {
"hash": "983a288b1deae516b5d1a3268f286490dc1a3bd215a042403a142fb3df5f8acd"
}
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion examples/rl/racing/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
smarts:
seed: 42
visdom: False
rgb_meters: 64 # Height and width (meters) of RGB image in SMARTS observation
rgb_pixels: 64 # Height and width (pixels) of RGB image in SMARTS observation
max_episode_steps: 300 # 30 seconds. Maximum steps per episode.
Expand Down
1 change: 0 additions & 1 deletion examples/rl/racing/smarts_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def make(env_name: Optional[str], config: Dict[str, Any], seed: int) -> gym.Env:
scenarios=scenarios,
agent_specs=agent_specs,
headless=config["headless"],
visdom=config["visdom"],
seed=seed,
sim_name=env_name,
)
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ install_requires =
shapely>=2.0.0
tableprint>=0.9.1
trimesh==3.9.29 # Used for writing .glb files
visdom>=0.1.8.9
# The following are for Scenario Studio
yattag>=1.14.0
# The following is for both SS and Envision
Expand Down Expand Up @@ -119,6 +118,8 @@ opendrive =
opendrive2lanelet>=1.2.1
argoverse =
av2>=0.2.1
visdom =
visdom>=0.1.8.9

[aliases]
test=pytest
32 changes: 24 additions & 8 deletions smarts/core/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from .utils.id import Id
from .utils.math import rounder_for_dt
from .utils.pybullet import bullet_client as bc
from .utils.visdom_client import VisdomClient
from .vehicle import Vehicle
from .vehicle_index import VehicleIndex
from .vehicle_state import Collision, VehicleState, neighborhood_vehicles_around_vehicle
Expand Down Expand Up @@ -100,7 +99,7 @@ class SMARTS(ProviderManager):
agent_interfaces (Dict[str, AgentInterface]): The interfaces providing SMARTS with the understanding of what features each agent needs.
traffic_sims (Optional[List[TrafficProvider]], optional): An optional list of traffic simulators for providing non-agent traffic. Defaults to None.
envision (Optional[EnvisionClient], optional): An envision client for connecting to an envision visualization server. Defaults to None.
visdom (Optional[VisdomClient], optional): A visdom client for connecting to a visdom visualization server. Defaults to None.
visdom (Union[bool, Any], optional): Deprecated. Use SMARTS_VISDOM_ENABLED. A visdom client for connecting to a visdom visualization server.
fixed_timestep_sec (Optional[float], optional): The fixed timestep that will be default if time is not otherwise specified at step. Defaults to 0.1.
reset_agents_only (bool, optional): When specified the simulation will continue use of the current scenario. Defaults to False.
zoo_addrs (Optional[Tuple[str, int]], optional): The (ip:port) values of remote agent workers for externally hosted agents. Defaults to None.
Expand All @@ -114,12 +113,13 @@ def __init__(
traffic_sim: Optional[TrafficProvider] = None,
traffic_sims: Optional[List[TrafficProvider]] = None,
envision: Optional[EnvisionClient] = None,
visdom: Optional[VisdomClient] = None,
visdom: Optional[Union[bool, Any]] = False,
fixed_timestep_sec: Optional[float] = 0.1,
reset_agents_only: bool = False,
zoo_addrs: Optional[Tuple[str, int]] = None,
external_provider: bool = False,
):
conf = config()
self._log = logging.getLogger(self.__class__.__name__)
self._log.setLevel(level=logging.ERROR)
self._sim_id = Id.new("smarts")
Expand All @@ -128,7 +128,23 @@ def __init__(
self._scenario: Optional[Scenario] = None
self._renderer: RendererBase = None
self._envision: Optional[EnvisionClient] = envision
self._visdom: Optional[VisdomClient] = visdom
if visdom is not False or visdom is not None:
warnings.warn(
"Using visdom through the arguments is deprecated. Please use engine configuration or SMARTS_VISDOM_ENABLED."
)
else:
visdom = None

self._visdom: Any = None
if conf("visdom", "enabled", default=False, cast=bool) or visdom is True:
from smarts.visdom.visdom_client import VisdomClient

self._visdom = VisdomClient(
hostname=conf("visdom", "hostname", default="http://localhost"),
port=conf("visdom", "port", default=8097),
)
elif not isinstance(self._visdom, bool):
self._visdom = visdom
self._external_provider: ExternalProvider = None
self._resetting = False
self._reset_required = False
Expand Down Expand Up @@ -1458,18 +1474,18 @@ def _bullet_id_to_vehicle(self, bullet_id):

def _check_ground_plane(self):
rescale_plane = False
map_min = np.array(self._map_bb.min_pt)[:2] if self._map_bb else None
map_max = np.array(self._map_bb.max_pt)[:2] if self._map_bb else None
map_min = np.array(self._map_bb.min_pt)[:2] if self._map_bb else np.array([])
map_max = np.array(self._map_bb.max_pt)[:2] if self._map_bb else np.array([])
for vehicle_id in self._vehicle_index.agent_vehicle_ids():
vehicle = self._vehicle_index.vehicle_by_id(vehicle_id)
map_spot = vehicle.pose.point.as_np_array[:2]
if map_min is None:
if len(map_min) == 0:
map_min = map_spot
rescale_plane = True
elif any(map_spot < map_min):
map_min = np.minimum(map_spot, map_min)
rescale_plane = True
if map_max is None:
if len(map_max) == 0:
map_max = map_spot
rescale_plane = True
elif any(map_spot > map_max):
Expand Down
1 change: 0 additions & 1 deletion smarts/core/tests/test_env_frame_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def env_and_spec(scenarios, seed, headless=True, max_episode_steps=None):
agent_specs={AGENT_ID: agent_spec},
sim_name=None,
headless=headless,
visdom=False,
timestep_sec=0.1,
sumo_headless=True,
seed=seed,
Expand Down
1 change: 0 additions & 1 deletion smarts/core/tests/test_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def run_scenario(
agent_specs={AGENT_ID: agent_spec},
sim_name=sim_name,
headless=headless,
visdom=False,
fixed_timestep_sec=0.1,
sumo_headless=True,
seed=seed,
Expand Down
1 change: 0 additions & 1 deletion smarts/core/tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def env(agent_spec: AgentSpec):
scenarios=["scenarios/sumo/figure_eight"],
agent_interfaces={AGENT_ID: agent_spec.interface},
headless=True,
visdom=False,
fixed_timestep_sec=0.1,
seed=42,
)
Expand Down
1 change: 0 additions & 1 deletion smarts/core/tests/test_smarts_memory_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def act(self, obs):
scenarios=scenarios,
agent_specs={agent_id: agent_spec},
headless=True,
visdom=False,
fixed_timestep_sec=TIMESTEP_SEC,
sumo_headless=True,
seed=seed,
Expand Down
4 changes: 0 additions & 4 deletions smarts/env/gymnasium/driving_smarts_2023_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def driving_smarts_2023_env(
agent_interface: AgentInterface,
seed: int = 42,
headless: bool = True,
visdom: bool = False,
sumo_headless: bool = True,
envision_record_data_replay_path: Optional[str] = None,
):
Expand Down Expand Up @@ -99,8 +98,6 @@ def driving_smarts_2023_env(
seed (int, optional): Random number generator seed. Defaults to 42.
headless (bool, optional): If True, disables visualization in
Envision. Defaults to False.
visdom (bool, optional): If True, enables visualization of observed
RGB images in Visdom. Defaults to False.
sumo_headless (bool, optional): If True, disables visualization in
SUMO GUI. Defaults to True.
envision_record_data_replay_path (Optional[str], optional):
Expand Down Expand Up @@ -143,7 +140,6 @@ def driving_smarts_2023_env(
agent_interfaces=agent_interfaces,
sim_name="Driving_Smarts_2023",
headless=headless,
visdom=visdom,
seed=seed,
sumo_options=SumoOptions(headless=sumo_headless),
visualization_client_builder=visualization_client_builder,
Expand Down
9 changes: 3 additions & 6 deletions smarts/env/gymnasium/hiway_env_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# THE SOFTWARE.
import logging
import os
import warnings
from enum import IntEnum
from functools import partial
from pathlib import Path
Expand Down Expand Up @@ -51,7 +52,6 @@
from smarts.core.local_traffic_provider import LocalTrafficProvider
from smarts.core.scenario import Scenario
from smarts.core.sumo_traffic_simulation import SumoTrafficSimulation
from smarts.core.utils.visdom_client import VisdomClient
from smarts.env.utils.action_conversion import ActionOptions, ActionSpacesFormatter
from smarts.env.utils.observation_conversion import (
ObservationOptions,
Expand Down Expand Up @@ -103,8 +103,7 @@ class HiWayEnvV1(gym.Env):
scenarios provided over successive resets.
headless (bool, optional): If True, disables visualization in
Envision. Defaults to False.
visdom (bool, optional): If True, enables visualization of observed
RGB images in Visdom. Defaults to False.
visdom (bool): Deprecated. Use SMARTS_VISDOM_ENABLED.
fixed_timestep_sec (float, optional): Step duration for
all components of the simulation. May be None if time deltas
are externally-driven. Defaults to None.
Expand Down Expand Up @@ -184,8 +183,6 @@ def __init__(

self._env_renderer = None

visdom_client = VisdomClient() if visdom else None

traffic_sims = []
if Scenario.any_support_sumo_traffic(scenarios):
if isinstance(sumo_options, tuple):
Expand Down Expand Up @@ -221,7 +218,7 @@ def __init__(
agent_interfaces=agent_interfaces,
traffic_sims=traffic_sims,
envision=visualization_client,
visdom=visdom_client,
visdom=visdom,
fixed_timestep_sec=fixed_timestep_sec,
zoo_addrs=zoo_addrs,
)
Expand Down
4 changes: 0 additions & 4 deletions smarts/env/gymnasium/platoon_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def platoon_env(
agent_interface: AgentInterface,
seed: int = 42,
headless: bool = True,
visdom: bool = False,
sumo_headless: bool = True,
envision_record_data_replay_path: Optional[str] = None,
):
Expand Down Expand Up @@ -104,8 +103,6 @@ def platoon_env(
seed (int, optional): Random number generator seed. Defaults to 42.
headless (bool, optional): If True, disables visualization in
Envision. Defaults to False.
visdom (bool, optional): If True, enables visualization of observed
RGB images in Visdom. Defaults to False.
sumo_headless (bool, optional): If True, disables visualization in
SUMO GUI. Defaults to True.
envision_record_data_replay_path (Optional[str], optional):
Expand Down Expand Up @@ -148,7 +145,6 @@ def platoon_env(
agent_interfaces=agent_interfaces,
sim_name="VehicleFollowing",
headless=headless,
visdom=visdom,
seed=seed,
sumo_options=SumoOptions(headless=sumo_headless),
visualization_client_builder=visualization_client_builder,
Expand Down
Loading