Skip to content

Commit

Permalink
Allow random routes to vary across traffic groups. (#2112)
Browse files Browse the repository at this point in the history
* Allow random routes to vary across traffic groups.

* Update changelog.

* Vary seed using interation instead.

* Remove unused imports.
  • Loading branch information
Gamenot authored Nov 16, 2023
1 parent c164c5c commit dfe0645
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
### Changed
### Deprecated
### Fixed
- Fixed an issue where `RandomRoute` would always give the same route across traffic groups in scenario studio.
- Fixed an issue where `SMARTS` might not be explicitly destroyed in the `ros_driver`.
- Fixed issue where `SumoTrafficSimulation` could get locked up on reset if a scenario had only 1 map but multiple scenario variations.
- Fixed an issue where an out-of-scope method reference caused a pickling error.
Expand Down
6 changes: 4 additions & 2 deletions scenarios/sumo/intersections/4lane/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@
),
]

variations = 40
scenario = Scenario(
traffic={
"basic": Traffic(
f"t{i}": Traffic(
flows=[
Flow(
route=RandomRoute(),
repeat_route=True,
rate=3600,
randomly_spaced=True,
actors={TrafficActor(name="car"): 1.0},
)
]
)
for i in range(variations)
},
ego_missions=ego_missions,
map_spec=MapSpec(
Expand Down
5 changes: 4 additions & 1 deletion smarts/sstudio/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import tempfile
from typing import Optional

import numpy as np
from yattag import Doc, indent

from smarts.core.road_map import RoadMap
from smarts.core.utils.file import make_dir_in_smarts_log_dir, replace
from smarts.core.utils.math import wrap_value

from . import types

Expand Down Expand Up @@ -184,6 +186,7 @@ def plan_and_save(

from smarts.core.utils.sumo import sumolib

int32_limits = np.iinfo(np.int32)
duarouter_path = sumolib.checkBinary("duarouter")
subprocess.check_call(
[
Expand All @@ -197,7 +200,7 @@ def plan_and_save(
"--output-file",
route_path,
"--seed",
str(seed),
str(wrap_value(seed, int32_limits.min, int32_limits.max)),
"--ignore-errors",
"false",
"--no-step-log",
Expand Down
8 changes: 6 additions & 2 deletions smarts/sstudio/genscenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import cloudpickle
import yaml

import smarts.core
from smarts.core.default_map_builder import find_mapfile_in_dir
from smarts.core.utils.file import file_md5_hash, path2hash, pickle_hash
from smarts.core.utils.logging import timeit
Expand Down Expand Up @@ -164,6 +165,7 @@ def gen_scenario(
"""
# XXX: For now this simply coalesces the sub-calls but in the future this allows
# us to simplify our serialization between SStudio and SMARTS.
smarts.core.seed(seed)

scenario_dir = os.path.abspath(str(output_dir))
build_dir = os.path.join(scenario_dir, "build")
Expand Down Expand Up @@ -242,12 +244,14 @@ def gen_scenario(
db_conn, scenario.traffic, artifact_paths, obj_hash, map_needs_rebuild
):
with timeit("traffic", logger.info):
for name, traffic in scenario.traffic.items():

for iteration, (name, traffic) in enumerate(scenario.traffic.items()):
derived_seed = seed + iteration
gen_traffic(
scenario=scenario_dir,
traffic=traffic,
name=name,
seed=seed,
seed=derived_seed,
map_spec=map_spec,
)
_update_artifacts(db_conn, artifact_paths, obj_hash)
Expand Down

0 comments on commit dfe0645

Please sign in to comment.