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

Allow random routes to vary across traffic groups. #2112

Merged
merged 4 commits into from
Nov 16, 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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should wrap the seed here (at the point where it is introduced) instead of later where it is used in generator.plan_and_save().

Copy link
Collaborator Author

@Gamenot Gamenot Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, if we wrap over the integer at this level then the implementation will affect how we use this method. Which is a big no in my opinion.

map_spec=map_spec,
)
_update_artifacts(db_conn, artifact_paths, obj_hash)
Expand Down