smarts.core.scenario module

class smarts.core.scenario.Scenario(scenario_root: str, traffic_specs: Sequence[str] = [], missions: Dict[str, NavigationMission] | None = None, social_agents: Dict[str, Tuple[Any, SocialAgent]] | None = None, log_dir: str | None = None, surface_patches: Sequence[Dict[str, Any]] | None = None, traffic_history: str | None = None, map_spec: MapSpec | None = None, route: str | None = None)[source]

The purpose of the Scenario is to provide an aggregate of all code/configuration/assets that is specialized to a scenario.

Parameters:
  • scenario_root – The scenario asset folder (i.e. ‘./scenarios/trigger’.)

  • traffic_specs – The social vehicle traffic specs.

  • missions – agent_id to mission mapping.

  • map_spec – If specified, allows specifying a MapSpec at run-time to override any spec that may have been pre-specified in the scenario folder (or the default if none were). Also see comments around the MapSpec definition.

static all_support_sumo_traffic(scenarios: Sequence[str]) bool[source]

Determines if all given scenarios support Sumo traffic simulation.

static any_support_sumo_traffic(scenarios: Sequence[str]) bool[source]

Determines if any of the given scenarios support Sumo traffic simulation.

property bubbles

Bubbles within this scenario.

static build_map(scenario_root: str) Tuple[RoadMap | None, str | None][source]

Builds a road map from the given scenario’s resources.

property controller_parameters_filepath: str

The path of the vehicle controller parameters.

create_dynamic_traffic_history_mission(vehicle_id: str, trigger_time: float, positional_radius: int) Tuple[NavigationMission, NavigationMission][source]

Builds missions out of the given vehicle information. :param vehicle_id: The id of a vehicle in the traffic history dataset. :param trigger_time: The time that this mission should become active. :param positional_radius: The goal radius for the positional goal.

Returns:

A positional mission that follows the initial

original vehicle’s travel as well as a traverse style mission which is done when the vehicle leaves the map.

Return type:

(smarts.core.plan.NavigationMission, smarts.core.plan.NavigationMission)

static discover_agent_missions(scenario_root, agents_to_be_briefed)[source]

Returns a sequence of {agent_id: mission} mappings.

If no missions are discovered we generate random ones. If there is only one agent to be briefed we return a list of {agent_id: mission} cycling through each mission. If there are multiple agents to be briefed we assume that each one is intended to get its own mission and that len(agents_to_be_briefed) == len(missions). In this case a list of one dictionary is returned.

static discover_agent_missions_count(scenario_root)[source]

Retrieve the agent missions from the given scenario directory.

static discover_friction_map(scenario_root) List[Dict[str, Any]][source]

Returns the list of surface patches parameters defined in scenario file. Each element of the list contains the parameters of the specified surface patch.

static discover_map(scenario_root: str, lanepoint_spacing: float | None = None, default_lane_width: float | None = None, shift_to_origin: bool = False) MapSpec[source]

Generates the map specification from the given scenario’s file resources.

Parameters:
  • scenarios_root – A specific scenario to run (e.g. scenarios/sumo/loop)

  • lanepoint_spacing – The distance between lane-points that represent a lane’s geometry.

  • default_lane_width – The default width of a lane from its center if it does not have a specific width.

  • shift_to_origin – Shifts the map location to near the simulation origin so that the map contains (0, 0).

Returns:

A new map spec.

discover_missions_of_traffic_histories() Dict[str, NavigationMission][source]

Retrieves the missions of traffic history vehicles.

static discover_routes(scenario_root)[source]

Discover the route files in the given scenario.

>>> Scenario.discover_routes("scenarios/sumo/intersections/2lane")
['all.rou.xml', 'horizontal.rou.xml', 'turns.rou.xml', 'unprotected_left.rou.xml', 'vertical.rou.xml']
>>> Scenario.discover_routes("scenarios/sumo/loop") # loop does not have any routes
['basic.rou.xml']
static discover_scenarios(scenario_or_scenarios_dir)[source]

Retrieve all specific scenarios in the directory tree of the given scenario directory. :param scenario_or_scenario_dir: A directory that either immediately contains a scenario or the root of a directory tree that contains multiple scenarios.

Returns:

All specific scenarios.

static discover_traffic(scenario_root: str) List[List[str] | None][source]

Discover the traffic spec files in the given scenario.

static discover_traffic_histories(scenario_root: str)[source]

Finds all existing traffic history files in the specific scenario.

static get_scenario_list(scenarios_or_scenarios_dirs: Sequence[str]) Sequence[str][source]

Find all specific scenario directories in the directory trees of the initial scenario directory.

get_vehicle_goal(vehicle_id: str) Point[source]

Get the final position for a history vehicle.

get_vehicle_start_at_time(vehicle_id: str, start_time: float) Tuple[Start, float][source]

Returns a Start object that can be used to create a Mission for a vehicle from a traffic history dataset starting at its location at start_time. Also returns its speed at that time.

history_missions_for_window(exists_at_or_after: float, ends_before: float, minimum_vehicle_window: float, filter: Callable[[Iterable[TrafficHistoryVehicleWindow]], Iterable[TrafficHistoryVehicleWindow]] | None = None) Sequence[NavigationMission][source]

Discovers vehicle missions for the given window of time.

Parameters:
  • exists_at_or_after (float) – The starting time of any vehicles to query for.

  • ends_before (float) – The last point in time a vehicle should be in the simulation. Vehicles ending after that time are not considered.

  • minimum_vehicle_window (float) – The minimum time that a vehicle must be in the simulation to be considered for a mission.

  • filter – A filter in the form of (func(Sequence[TrafficHistoryVehicleWindow]) -> Sequence[TrafficHistoryVehicleWindow]), which passes in traffic vehicle information and then should be used purely to filter the sequence down.

Returns:

A set of missions derived from the traffic history.

Return type:

List[smarts.core.plan.NavigationMission]

static is_valid_scenario(scenario_root) bool[source]

Checks if the scenario_root directory matches our expected scenario structure

>>> Scenario.is_valid_scenario("scenarios/sumo/loop")
True
>>> Scenario.is_valid_scenario("scenarios/non_existant")
False
property map_glb_filepath

The map geometry file-path.

static map_glb_meta_for_file(filepath)[source]

The map metadata given a file.

property map_glb_metadata

The metadata for the current map .glb file.

property map_spec: MapSpec | None

The map spec for the road map used in this scenario.

property metadata: Dict

Scenario metadata values.

Returns:

The values.

Return type:

Dict

mission(agent_id) NavigationMission | None[source]

Get the mission assigned to the given agent.

property missions: Dict[str, NavigationMission]

Agent missions contained within this scenario.

property name: str

The name of the scenario.

static next(scenario_iterator, log_id='') Scenario[source]

Utility to override specific attributes from a scenario iterator

property plane_filepath: str

The ground plane.

property road_map: RoadMap

The road map of the scenario.

property road_map_hash

A hash value of this road map.

property root_filepath: str

The root directory of the scenario.

property route: str | None

The traffic route file name.

property route_filepath

The file-path to the traffic route file.

property route_files_enabled

If there is a traffic route file.

property scenario_hash: str

A hash of the scenario.

static scenario_variations(scenarios_or_scenarios_dirs: Sequence[str], agents_to_be_briefed: Sequence[str], shuffle_scenarios: bool = True, circular: bool = True) Generator[Scenario, None, None][source]

Generate a cycle of scenario configurations.

Parameters:
  • scenarios_or_scenarios_dirs (Sequence[str]) – A sequence of either the scenario to run (see scenarios/ for some samples you can use) OR a directory of scenarios to sample from.

  • agents_to_be_briefed – Agent IDs that will be assigned a mission (“briefed” on a mission).

Returns:

A generator that serves up Scenarios.

set_ego_missions(ego_missions: Dict[str, NavigationMission])[source]

Replaces the ego missions within the scenario. :param ego_missions: Ego agent ids mapped to missions.

property social_agents: Dict[str, Tuple[Any, SocialAgent]]

Managed social agents within this scenario.

property supports_sumo_traffic: bool

Returns True if this scenario uses a Sumo road network.

property surface_patches

A list of surface areas with dynamics implications (e.g. icy road.)

property tire_parameters_filepath: str

The path of the tire model’s parameters.

property traffic_history: TrafficHistory | None

Traffic history contained within this scenario.

property traffic_specs: Sequence[str]

The traffic spec file names to use for this scenario.

unique_sumo_log_file()[source]

A unique logging file for SUMO logging.

static variations_for_all_scenario_roots(scenario_roots, agents_to_be_briefed, shuffle_scenarios=True) Generator[Scenario, None, None][source]

Convert scenario roots to concrete scenarios. :param scenario_roots: Scenario directories containing scenario resource files. :param agents_to_be_briefed: Agent IDs that will be assigned a mission (“briefed” on a mission). :param shuffle_scenarios: Return scenarios in a pseudo-random order.

Returns:

A generator that serves up Scenarios.

property vehicle_definitions_filepath: str

The path to the default list of vehicle definitions.

property vehicle_filepath: str | None

The file-path of the vehicle’s physics model.