Skip to content

Commit

Permalink
Release 0 6 1 rc1 (huawei-noah#1396)
Browse files Browse the repository at this point in the history
Co-authored-by: Allan Liu <[email protected]>
Co-authored-by: qianyi-sun <[email protected]>
Co-authored-by: adai <[email protected]>
Co-authored-by: Saul Field <[email protected]>
Co-authored-by: Rutvik Gupta <[email protected]>
  • Loading branch information
6 people authored Apr 19, 2022
1 parent 7ff9f0a commit 3ef5650
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 98 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/ci-format.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: SMARTS CI Format

on:
push:
branches-ignore:
- master
pull_request:
branches-ignore:
- master
on: [push, pull_request]

env:
venv_dir: .venv
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Copy and pasting the git commit messages is __NOT__ enough.

# [Unreleased]

### [0.6.1rc1] 15-04-18
### Fixed
- Gracefully handle `EndlessGoal` missions in the MaRL benchmark. Relative goal distance with `EndlessGoal` will be now always be 0.
- Restore `rl-agent` to working order. Version incremented to `1.1.0`.
- Update `rl-agent` wheel.
- Add workaround for issue where traffic history starts offroad by fixing `scl scenario build`'s `--allow-offset-map` to work with traffic history.

### [0.6.1rc0] 15-04-16
### Added
- Added `get_vehicle_start_time()` method for scenarios with traffic history data. See Issue #1210.
Expand Down
5 changes: 3 additions & 2 deletions baselines/marl_benchmark/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ def cal_goal_relative_pos(env_obs: Observation, _):

ego_state = env_obs.ego_vehicle_state
goal = ego_state.mission.goal
assert isinstance(goal, PositionalGoal), goal

ego_pos = ego_state.position[:2]
goal_pos = goal.position # the position of mission goal is 2-dimensional.
goal_pos = getattr(
goal, "position", ego_pos
) # the position of mission goal is 2-dimensional.
vector = np.asarray([goal_pos[0] - ego_pos[0], goal_pos[1] - ego_pos[1]])
# space = SPACE_LIB["goal_relative_pos"](None)
# return vector / (space.high - space.low)
Expand Down
2 changes: 1 addition & 1 deletion baselines/marl_benchmark/metrics/basic_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def agent_info_adapter(env_obs, shaped_reward: float, raw_info: dict):
info["collision"] = 1 if len(env_obs.events.collisions) > 0 else 0

goal = env_obs.ego_vehicle_state.mission.goal
goal_pos = goal.position
ego_2d_pos = env_obs.ego_vehicle_state.position[:2]
goal_pos = getattr(goal, "position", ego_2d_pos)

info["distance_to_goal"] = distance.euclidean(ego_2d_pos, goal_pos)
info["distance_to_center"] = CalObs.cal_distance_to_center(env_obs, "")
Expand Down
10 changes: 2 additions & 8 deletions baselines/marl_benchmark/wrappers/rllib/frame_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,14 @@ def func(env_obs_seq, env_reward):
# ======== Penalty: distance to goal =========
goal = last_env_obs.ego_vehicle_state.mission.goal
ego_2d_position = last_env_obs.ego_vehicle_state.position[:2]
if hasattr(goal, "position"):
goal_position = goal.position
else:
goal_position = ego_2d_position
goal_position = getattr(goal, "position", ego_2d_position)
goal_dist = distance.euclidean(ego_2d_position, goal_position)
penalty += -0.01 * goal_dist

old_obs = env_obs_seq[-2]
old_goal = old_obs.ego_vehicle_state.mission.goal
old_ego_2d_position = old_obs.ego_vehicle_state.position[:2]
if hasattr(old_goal, "position"):
old_goal_position = old_goal.position
else:
old_goal_position = old_ego_2d_position
old_goal_position = getattr(old_goal, "position", old_ego_2d_position)
old_goal_dist = distance.euclidean(old_ego_2d_position, old_goal_position)
penalty += 0.1 * (old_goal_dist - goal_dist) # 0.05

Expand Down
2 changes: 1 addition & 1 deletion cli/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _build_single_scenario(clean: bool, allow_offset_map: bool, scenario: str):
from smarts.core.scenario import Scenario

traffic_histories = Scenario.discover_traffic_histories(scenario_root_str)
shift_to_origin = not allow_offset_map or bool(traffic_histories)
shift_to_origin = not allow_offset_map

map_spec = Scenario.discover_map(scenario_root_str, shift_to_origin=shift_to_origin)
road_map, _ = map_spec.builder_fn(map_spec)
Expand Down
2 changes: 1 addition & 1 deletion docs/sim/scenario_studio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Then in the scenario.py file:
t.SocialAgentActor(
name="my-rl-agent",
agent_locator="rl_agent:rl_agent-v0"
agent_locator="rl_agent:rl_agent-v1"
)
Expand Down
Empty file added examples/rllib/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ hyperlink==21.0.0
idna==3.3
ijson==3.1.4
importlib-metadata==4.11.3
importlib-resources==5.7.0
importlib-resources==5.7.1
incremental==21.3.0
iniconfig==1.1.1
ipykernel==6.13.0
Expand All @@ -70,7 +70,7 @@ jsonpatch==1.32
jsonpointer==2.3
jsonschema==4.4.0
jupyter-client==7.2.2
jupyter-core==4.9.2
jupyter-core==4.10.0
jupyter-server==1.16.0
jupyter-server-mathjax==0.2.5
jupyterlab-pygments==0.2.2
Expand Down Expand Up @@ -170,7 +170,7 @@ tornado==6.1
traitlets==5.1.1
trimesh==3.9.29
Twisted==22.4.0
typing_extensions==4.1.1
typing_extensions==4.2.0
urllib3==1.26.9
visdom==0.1.8.9
wcwidth==0.2.5
Expand Down
4 changes: 4 additions & 0 deletions scenarios/NGSIM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Once that is done, you should be able to build your scenarios in the normal way,
```bash
scl scenario build-all --clean scenarios/NGSIM
```
or the following command to disable generating `shifted_map-AUTOGEN.net.xml`
```bash
scl scenario build-all --clean --allow-offset-map scenarios/NGSIM
```

For each traffic history `.yml` file specified in your `scenario.py`,
this will creates a cooresponding `.shf` file that SMARTS will use
Expand Down
42 changes: 21 additions & 21 deletions scenarios/NGSIM/us101/map.net.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2022-03-11 18:22:26 by Eclipse SUMO netconvert Version 1.10.0
<!-- generated on 2022-03-28 22:28:01 by Eclipse SUMO netedit Version 1.12.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">
<input>
<sumo-net-file value="NGSIM/us101/map.net.xml"/>
<sumo-net-file value="scenarios/NGSIM/us101/map.net.xml"/>
</input>
<output>
<output-file value="NGSIM/us101/shifted_map-AUTOGEN.net.xml"/>
<output-file value="scenarios/NGSIM/us101/map.net.xml"/>
</output>
<processing>
<geometry.min-radius.fix.railways value="false"/>
<geometry.max-grade.fix value="false"/>
<offset.disable-normalization value="false"/>
<offset.disable-normalization value="true"/>
<lefthand value="false"/>
</processing>
Expand All @@ -39,34 +39,34 @@

<net version="1.9" junctionCornerDetail="5" limitTurnSpeed="5.50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd">

<location netOffset="-17.37,-3.00" convBoundary="0.00,0.00,5.05,656.00" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>
<location netOffset="-17.37,-3.00" convBoundary="17.12,0.00,22.55,656.00" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>

<edge id="E0" from="J0" to="J1" priority="-1">
<lane id="E0_0" index="0" speed="13.89" length="656.00" width="3.50" shape="-15.62,656.00 -15.62,0.00"/>
<lane id="E0_1" index="1" speed="13.89" length="656.00" width="3.50" shape="-12.12,656.00 -12.12,0.00"/>
<lane id="E0_2" index="2" speed="13.89" length="656.00" width="3.50" shape="-8.62,656.00 -8.62,0.00"/>
<lane id="E0_3" index="3" speed="13.89" length="656.00" width="3.50" shape="-5.12,656.00 -5.12,0.00"/>
<lane id="E0_4" index="4" speed="13.89" length="656.00" width="3.50" acceleration="1" shape="-1.62,656.00 -1.62,0.00"/>
<lane id="E0_0" index="0" speed="13.89" length="656.00" width="3.50" shape="1.88,656.00 1.88,0.00"/>
<lane id="E0_1" index="1" speed="13.89" length="656.00" width="3.50" shape="5.38,656.00 5.38,0.00"/>
<lane id="E0_2" index="2" speed="13.89" length="656.00" width="3.50" shape="8.88,656.00 8.88,0.00"/>
<lane id="E0_3" index="3" speed="13.89" length="656.00" width="3.50" shape="12.38,656.00 12.38,0.00"/>
<lane id="E0_4" index="4" speed="13.89" length="656.00" width="3.50" acceleration="1" shape="15.88,656.00 15.88,0.00"/>
</edge>
<edge id="E2" from="J7" to="J8" priority="-1" shape="2.75,132.35 1.78,143.30 1.32,149.16 0.82,156.44 0.42,163.86 0.03,171.62 0.03,179.98 0.02,187.62 0.01,196.23 0.00,413.13">
<lane id="E2_0" index="0" speed="13.89" length="280.88" width="3.70" shape="4.59,132.51 3.62,143.46 3.17,149.29 2.67,156.55 2.27,163.96 1.88,171.67 1.88,179.98 1.87,187.62 1.86,196.23 1.85,411.65"/>
<edge id="E2" from="J7" to="J8" priority="-1" shape="20.25,132.35 19.32,141.71 18.86,146.52 18.26,153.27 17.43,160.48 17.23,171.73 17.12,178.90 17.22,185.68 17.21,195.58 17.50,413.13">
<lane id="E2_0" index="0" speed="13.89" length="280.93" width="3.70" shape="22.09,132.53 21.16,141.89 20.70,146.69 20.10,153.46 19.28,160.60 19.08,171.76 18.97,178.90 19.07,185.67 19.06,195.58 19.35,411.64"/>
</edge>
<edge id="E3" from="J9" to="J10" priority="-1">
<lane id="E3_0" index="0" speed="13.89" length="41.51" shape="6.64,132.56 1.69,173.77"/>
<lane id="E3_0" index="0" speed="13.89" length="41.51" shape="24.14,132.56 19.19,173.77"/>
</edge>
<edge id="E4" from="J8" to="J11" priority="-1">
<lane id="E4_0" index="0" speed="13.89" length="84.64" width="4.00" shape="2.07,414.51 6.38,497.56"/>
<lane id="E4_0" index="0" speed="13.89" length="84.64" width="4.00" shape="19.57,414.51 23.88,497.56"/>
</edge>

<junction id="J0" type="dead_end" x="0.13" y="656.00" incLanes="" intLanes="" shape="0.13,656.00 -15.87,656.00" customShape="1"/>
<junction id="J1" type="dead_end" x="0.13" y="0.00" incLanes="E0_0 E0_1 E0_2 E0_3 E0_4" intLanes="" shape="-16.07,0.00 0.63,0.00" customShape="1"/>
<junction id="J10" type="dead_end" x="0.10" y="173.58" incLanes="E3_0" intLanes="" shape="3.28,173.96 0.10,173.58"/>
<junction id="J11" type="dead_end" x="4.38" y="497.66" incLanes="E4_0" intLanes="" shape="8.37,497.45 4.38,497.66"/>
<junction id="J7" type="dead_end" x="2.75" y="132.35" incLanes="" intLanes="" shape="2.75,132.35 6.44,132.68" fringe="inner"/>
<junction id="J8" type="priority" x="0.00" y="413.13" incLanes="E2_0" intLanes="" shape="0.08,414.61 4.07,414.40 3.70,411.65 0.00,411.65">
<junction id="J0" type="dead_end" x="17.63" y="656.00" incLanes="" intLanes="" shape="17.63,656.00 0.00,656.00" customShape="1"/>
<junction id="J1" type="dead_end" x="17.63" y="0.00" incLanes="E0_0 E0_1 E0_2 E0_3 E0_4" intLanes="" shape="0.00,0.00 18.13,0.00" customShape="1"/>
<junction id="J10" type="dead_end" x="17.60" y="173.58" incLanes="E3_0" intLanes="" shape="20.78,173.96 17.60,173.58"/>
<junction id="J11" type="dead_end" x="21.88" y="497.66" incLanes="E4_0" intLanes="" shape="25.87,497.45 21.88,497.66"/>
<junction id="J7" type="dead_end" x="20.25" y="132.35" incLanes="" intLanes="" shape="20.25,132.35 23.93,132.72" fringe="inner"/>
<junction id="J8" type="priority" x="17.50" y="413.13" incLanes="E2_0" intLanes="" shape="17.58,414.61 21.57,414.40 21.20,411.64 17.50,411.64">
<request index="0" response="0" foes="0"/>
</junction>
<junction id="J9" type="dead_end" x="5.05" y="132.37" incLanes="" intLanes="" shape="5.05,132.37 8.23,132.75"/>
<junction id="J9" type="dead_end" x="22.55" y="132.37" incLanes="" intLanes="" shape="22.55,132.37 25.73,132.75"/>

<connection from="E2" to="E4" fromLane="0" toLane="0" dir="s" state="M"/>

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
description="Scalable Multi-Agent RL Training School",
long_description=long_description,
long_description_content_type="text/markdown",
version="0.6.1rc0",
version="0.6.1rc1",
packages=find_packages(exclude=("tests", "examples")),
include_package_data=True,
zip_safe=True,
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/utils/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def record_step(self, observations=None, rewards=None, dones=None, infos=None):
"""Record a step end."""
self.steps += 1

if not isinstance(observations, dict):
if not isinstance(dones, dict):
observations, rewards, dones, infos = self._convert_to_dict(
observations, rewards, dones, infos
)
Expand Down
2 changes: 1 addition & 1 deletion smarts/ros/src/smarts_ros/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>smarts_ros</name>
<version>0.6.1rc0</version>
<version>0.6.1rc1</version>
<description>The SMARTS package includes a node to wrap and drive a SMARTS simulation,
publishing the state updates after each step.</description>

Expand Down
4 changes: 2 additions & 2 deletions zoo/evaluation/batch_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ agent_list:
rate: 1

group_3:
- locator: rl_agent:rl-agent-v0
- locator: rl_agent:rl-agent-v1
name: normal_speed_agent
params:
goal_is_nearby_threshold: 40
Expand All @@ -86,7 +86,7 @@ agent_list:
target_speed: 15
lane_change_speed: 12.5

- locator: rl_agent:rl-agent-v0
- locator: rl_agent:rl-agent-v1
name: low_speed_agent
params:
goal_is_nearby_threshold: 40
Expand Down
Binary file not shown.
85 changes: 44 additions & 41 deletions zoo/policies/rl-agent/rl_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import rl_agent

from smarts.zoo.agent_spec import AgentSpec
from smarts.zoo.registry import register

from .agent import RLAgent
from .lane_space import (
ACTION_SPACE,
Expand All @@ -14,41 +11,47 @@
get_observation_adapter,
)

VERSION = "1.0.0"


def entrypoint(
goal_is_nearby_threshold=40,
lane_end_threshold=51,
lane_crash_distance_threshold=6,
lane_crash_ttc_threshold=2,
intersection_crash_distance_threshold=6,
intersection_crash_ttc_threshold=5,
target_speed=15,
lane_change_speed=12.5,
):
with pkg_resources.path(rl_agent, "checkpoint") as checkpoint_path:
return AgentSpec(
interface=agent_interface,
observation_adapter=get_observation_adapter(
goal_is_nearby_threshold=goal_is_nearby_threshold,
lane_end_threshold=lane_end_threshold,
lane_crash_distance_threshold=lane_crash_distance_threshold,
lane_crash_ttc_threshold=lane_crash_ttc_threshold,
intersection_crash_distance_threshold=intersection_crash_distance_threshold,
intersection_crash_ttc_threshold=intersection_crash_ttc_threshold,
),
action_adapter=get_action_adapter(
target_speed=target_speed,
lane_change_speed=lane_change_speed,
),
agent_builder=lambda: RLAgent(
load_path=str((checkpoint_path / "checkpoint").absolute()),
policy_name="default_policy",
observation_space=OBSERVATION_SPACE,
action_space=ACTION_SPACE,
),
)


register(locator="rl-agent-v1", entry_point=entrypoint)
VERSION = "1.1.0"

try:
from smarts.zoo.agent_spec import AgentSpec
from smarts.zoo.registry import register

def entrypoint(
goal_is_nearby_threshold=40,
lane_end_threshold=51,
lane_crash_distance_threshold=6,
lane_crash_ttc_threshold=2,
intersection_crash_distance_threshold=6,
intersection_crash_ttc_threshold=5,
target_speed=15,
lane_change_speed=12.5,
):
with pkg_resources.path(rl_agent, "checkpoint") as checkpoint_path:
return AgentSpec(
interface=agent_interface,
observation_adapter=get_observation_adapter(
goal_is_nearby_threshold=goal_is_nearby_threshold,
lane_end_threshold=lane_end_threshold,
lane_crash_distance_threshold=lane_crash_distance_threshold,
lane_crash_ttc_threshold=lane_crash_ttc_threshold,
intersection_crash_distance_threshold=intersection_crash_distance_threshold,
intersection_crash_ttc_threshold=intersection_crash_ttc_threshold,
),
action_adapter=get_action_adapter(
target_speed=target_speed,
lane_change_speed=lane_change_speed,
),
agent_builder=lambda: RLAgent(
load_path=str((checkpoint_path / "checkpoint").absolute()),
policy_name="default_policy",
observation_space=OBSERVATION_SPACE,
action_space=ACTION_SPACE,
),
)

register(locator="rl-agent-v1", entry_point=entrypoint)
except:

def entrypoint(**args):
raise ImportError("SMARTS has not been installed. Use `pip install smarts`")
13 changes: 10 additions & 3 deletions zoo/policies/rl-agent/rl_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from pathlib import Path

import gym
import tensorflow as tf
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
from ray.rllib.agents.ppo.ppo_tf_policy import PPOTFPolicy as LoadPolicy
from ray.rllib.models import ModelCatalog

Expand All @@ -31,13 +33,18 @@ def __init__(self, load_path, policy_name, observation_space, action_space):
return

self._prep = ModelCatalog.get_preprocessor_for_space(self._observation_space)
self._sess = tf.compat.v1.Session(graph=tf.Graph())
self._sess = tf.Session(graph=tf.Graph())
self._sess.__enter__()

with tf.name_scope(self._policy_name):
# obs_space need to be flattened before passed to PPOTFPolicy
flat_obs_space = self._prep.observation_space
self.policy = LoadPolicy(flat_obs_space, self._action_space, {})

self.policy = LoadPolicy(
flat_obs_space,
self._action_space,
{},
)
objs = pickle.load(open(self._checkpoint_path, "rb"))
objs = pickle.loads(objs["worker"])
state = objs["state"]
Expand Down
2 changes: 1 addition & 1 deletion zoo/policies/rl-agent/rl_agent/lane_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def observation_adapter(env_obs):

# get goal
goal = env_obs.ego_vehicle_state.mission.goal
goal_position = goal.position
goal_position = getattr(goal, "position", ego_state.position[:2])

(
lane_ttc,
Expand Down
2 changes: 1 addition & 1 deletion zoo/policies/rl-agent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
version=VERSION,
packages=["rl_agent"],
include_package_data=True,
install_requires=["smarts", "tensorflow==2.2.1", "ray[rllib]==1.0.1.post1"],
install_requires=["smarts>=0.6.1rc1", "tensorflow==2.4", "ray[rllib]==1.0.1.post1"],
)
Loading

0 comments on commit 3ef5650

Please sign in to comment.