smarts.core.sumo_traffic_simulation module

class smarts.core.sumo_traffic_simulation.SumoTrafficSimulation(headless: bool = True, time_resolution: float | None = 0.1, num_external_sumo_clients: int = 0, sumo_port: int | None = None, auto_start: bool = True, allow_reload: bool = True, debug: bool = False, remove_agents_only_mode: bool = False, traci_retries: int | None = None)[source]
Parameters:
  • headless – False to run with sumo-gui. True to run with sumo

  • time_resolution

    SUMO simulation occurs in discrete time_resolution-second steps .. warning:

    Since our interface(TRACI) to SUMO is delayed by one simulation step,
    setting a higher time resolution may lead to unexpected artifacts
    

  • num_external_sumo_clients – Block and wait on the specified number of other clients to connect to SUMO.

  • sumo_port – The port that sumo will attempt to run on.

  • auto_start – False to pause simulation when SMARTS runs, and wait for user to click start on sumo-gui.

  • allow_reload – Reset SUMO instead of restarting SUMO when the current map is the same as the previous.

  • remove_agents_only_mode – Remove only agent vehicles used by SMARTS and not delete other SUMO vehicles when the traffic simulation calls to tear-down

  • traci_retries – The number of times to retry acquisition of a TraCI server before throwing an exception.

property actions

The action spaces of the provider.

property actor_ids: Iterable[str]

The vehicles that sumo manages.

Returns:

Sumo vehicle ids.

Return type:

Iterable[str]

add_actor(provider_actor: ActorState, from_provider: Provider | None = None)[source]

Management of the actor with state is being assigned (or transferred if from_provider is not None) to this Provider. Should only be called if can_accept_actor() has returned True.

can_accept_actor(state: ActorState) bool[source]

Whether this Provider can take control of an existing actor with state that was previously managed by another Provider. The state.role field should indicate the desired role, not the previous role.

property connected

Determine if the provider is still responsive. (e.g. the case that the provider is sending provider state over the internet and has stopped responding) :returns: The connection state of the provider. :rtype: bool

destroy()[source]

Clean up TraCI related connections.

property headless

Does not show TraCI visualization.

manages_actor(actor_id: str) bool[source]

Returns True if the actor referenced by actor_id is managed by this Provider.

recover(scenario: smarts.core.scenario.Scenario, elapsed_sim_time: float, error: Exception | None = None) Tuple[ProviderState, bool][source]

Attempt to reconnect the provider if an error or disconnection occurred. Implementations may choose to re-raise the passed in exception. :param scenario: The scenario of the current episode. :type scenario: Scenario :param elapsed_sim_time: The current elapsed simulation time. :type elapsed_sim_time: float :param error: An exception if an exception was thrown. :type error: Optional[Exception]

Returns:

the state of the provider upon recovery bool: The success/failure of the attempt to reconnect.

Return type:

ProviderState

property recovery_flags: ProviderRecoveryFlags

Flags specifying what this provider should do if it fails. (May be overridden by child classes.)

remove_actor(actor_id: str)[source]

The actor is being removed from the simulation.

reserve_traffic_location_for_vehicle(vehicle_id: str, reserved_location: Polygon)[source]

Reserve an area around a location where vehicles cannot spawn until a given vehicle is added. :param vehicle_id: The vehicle to wait for. :param reserved_location: The space the vehicle takes up.

reset()[source]

Reset this provider to a pre-initialized state.

route_for_vehicle(vehicle_id: str) Route | None[source]

Gets the current Route for the specified vehicle, if known.

set_manager(manager: ProviderManager)[source]

Indicate the manager that this provider should inform of all actor hand-offs.

setup(scenario) ProviderState[source]

Initialize the simulation with a new scenario.

step(actions, dt: float, elapsed_sim_time: float) ProviderState[source]

Progress the provider to generate new actor state. :param actions: one or more valid actions from the supported action_spaces of this provider :param dt: time (in seconds) to simulate during this simulation step :type dt: float :param elapsed_sim_time: amount of time (in seconds) that’s elapsed so far in the simulation :type elapsed_sim_time: float

Returns:

State representation of all actors this manages.

Return type:

ProviderState

stop_managing(actor_id: str)[source]

Tells the Provider to stop managing the specified actor; it will be managed by another Provider now.

sync(provider_state: ProviderState)[source]

Synchronize with state managed by other Providers.

teardown()[source]

Clean up provider resources.

update_route_for_vehicle(vehicle_id: str, new_route: Route)[source]

Sets a new route for vehicle_id, but only if it is different from the previously-set route (otherwise, avoids the TraCI call).

Any sumo-special roads (e.g., junction) are removed from the new route before setting it because Sumo doesn’t allow specifying these in the call to its vehicle.setRoute() and will raise an exception otherwise.

vehicle_collided(vehicle_id)[source]

Called when a vehicle this provider manages is detected to have collided with any other vehicles in the scenario.

vehicle_dest_road(vehicle_id: str) str | None[source]

Get the final road_id in the route of the given vehicle.