smarts.core.smarts module

class smarts.core.smarts.SMARTS(agent_interfaces: Dict[str, AgentInterface], traffic_sim: TrafficProvider | None = None, traffic_sims: List[TrafficProvider] | None = None, envision: Client | None = None, visdom: bool | Any | None = False, fixed_timestep_sec: float | None = 0.1, reset_agents_only: bool = False, external_provider: bool = False)[source]

The core SMARTS simulator. This is the direct interface to all parts of the simulation.

Parameters:
  • agent_interfaces (Dict[str, AgentInterface]) – The interfaces providing SMARTS with the understanding of what features each agent needs.

  • traffic_sims (Optional[List[TrafficProvider]], optional) – An optional list of traffic simulators for providing non-agent traffic. Defaults to None.

  • envision (Optional[envision.client.Client], optional) – An envision client for connecting to an envision visualization server. Defaults to None.

  • visdom (Union[bool, Any], optional) – Deprecated. Use SMARTS_VISDOM_ENABLED. A visdom client for connecting to a visdom visualization server.

  • fixed_timestep_sec (Optional[float], optional) – The fixed timestep that will be default if time is not otherwise specified at step. Defaults to 0.1.

  • reset_agents_only (bool, optional) – When specified the simulation will continue use of the current scenario. Defaults to False.

  • external_provider (bool, optional) – Creates a special provider SMARTS.external_provider that allows for inserting state. Defaults to False.

add_agent_and_switch_control(vehicle_id: str, agent_id: str, agent_interface: AgentInterface, mission: NavigationMission) Vehicle[source]

Add the new specified ego agent and then take over control of the specified vehicle.

add_agent_with_mission(agent_id: str, agent_interface: AgentInterface, mission: NavigationMission)[source]

Add an agent to the simulation. The simulation will attempt to provide a vehicle for the agent.

add_provider(provider: Provider, recovery_flags: ProviderRecoveryFlags = ProviderRecoveryFlags.EXPERIMENT_REQUIRED)[source]

Add a provider to the simulation. A provider is a co-simulator conformed to a common interface.

property agent_manager: AgentManager

The agent manager for direct agent manipulation.

attach_sensors_to_vehicles(agent_interface: AgentInterface, vehicle_ids, overwrite_sensors=False, reset_sensors=False)[source]

Set the specified vehicles with the sensors needed to satisfy the specified agent interface. See smarts.core.smarts.SMARTS.prepare_observe_from.

Parameters:
  • agent_interface (AgentInterface) – The minimum interface generating the observations.

  • vehicle_ids (Sequence[str]) – The vehicles to target.

  • overwrite_sensors (bool, optional) – If to replace existing sensors (USE CAREFULLY). Defaults to False.

  • reset_sensors (bool, optional) – If to remove all existing sensors before adding sensors (USE VERY CAREFULLY). Defaults to False.

property bc

The bullet physics client instance.

property cached_frame: SimulationFrame

Generate a frozen frame state of the simulation.

create_vehicle_in_providers(vehicle: Vehicle, agent_id: str, is_ego: bool = False)[source]

Notify providers of the existence of an agent-controlled vehicle, one of which should assume management of it.

destroy()[source]

Destroy the simulation. Cleans up all remaining simulation resources.

property dynamic_action_spaces: Set[ActionSpaceType]

The set of vehicle action spaces that use dynamics (physics).

property elapsed_sim_time: float

Elapsed time since simulation start.

property envision: Client | None

The envision instance

property external_provider: ExternalProvider

The external provider that can be used to inject vehicle states directly.

property fixed_timestep_sec: float

The simulation fixed time-step.

get_provider_by_id(requested_id) Provider | None[source]

Find the current provider by its identifier.

Parameters:

requested_id (str) – The provider identifier.

Returns:

The provider if it exists, otherwise None.

Return type:

Optional[Provider]

get_provider_by_type(requested_type) Provider | None[source]

Get The first provider that matches the requested type.

property is_rendering: bool

If the simulation has image rendering active.

property last_dt: float

The last delta time.

property local_constants

Generate the frozen state that should not change until next reset.

neighborhood_vehicles_around_vehicle(vehicle_id: str, radius: float | None = None) List[VehicleState][source]

Find vehicles in the vicinity of the target vehicle.

observe_from(vehicle_ids: Sequence[str], interface: AgentInterface) Tuple[Dict[str, Observation], Dict[str, bool]][source]

Generate observations from the specified vehicles.

Parameters:
  • vehicle_ids (Sequence[str]) – The vehicles to target.

  • interface (AgentInterface) – The intended interface generating the observations (this may be ignored.)

Returns:

A dictionary of observations and the hypothetical dones.

Return type:

Tuple[Dict[str, Observation], Dict[str, bool]]

prepare_observe_from(vehicle_ids: Sequence[str], interface: AgentInterface, overwrite_sensors, reset_sensors)[source]

Assigns the given vehicle sensors as is described by the agent interface.

Parameters:
  • vehicle_ids (Sequence[str]) – The vehicles to target.

  • interface (AgentInterface) – The minimum interface generating the observations.

  • overwrite_sensors (bool, optional) – If to replace existing sensors (USE CAREFULLY).

  • reset_sensors (bool, optional) – If to remove all existing sensors (USE VERY CAREFULLY).

provider_for_actor(actor_id: str) Provider | None[source]

Find the provider that currently manages the given actor.

Parameters:

actor_id (str) – The actor id to query.

Returns:

The provider that manages this actor.

Return type:

(Provider|None)

provider_relinquishing_actor(current_provider: Provider | None, state: ActorState) Tuple[Provider | None, ActorProviderTransition][source]

Find a new Provider for an actor from among the Providers managed by this ProviderManager.

Returns:

A suitable new provider or None if a suitable one could not be found.

Return type:

(Provider|None)

provider_removing_actor(provider: Provider | None, actor_id: str)[source]

Called by a Provider when it is removing an actor from the simulation. It means that the Provider is indicating that the actor no longer exists. This was added for convenience, but it isn’t always necessary to be called.

property providers: List[Provider]

The current providers controlling actors within the simulation.

remove_provider(requested_type_or_provider: type | Provider)[source]

Remove a provider from the simulation.

Parameters:

requested_type (type | Provider) – The type of the provider to remove or provider to remove.

Returns:

The provider that was removed.

Return type:

Optional[Provider]

property renderer: RendererBase

The renderer singleton. On call, the sim will attempt to create it if it does not exist.

property renderer_ref: RendererBase | None

Get the reference of the renderer. This can be None.

reset(scenario: Scenario, start_time: float = 0.0) Dict[str, Observation][source]
Reset the simulation, reinitialize with the specified scenario. Then progress the

simulation up to the first time an agent returns an observation, or start_time if there are no agents in the simulation.

Parameters:
  • scenario (smarts.core.scenario.Scenario) – The scenario to reset the simulation with.

  • start_time (float) –

    The initial amount of simulation time to skip. This has implications on all time dependent systems.

    Note

    SMARTS simulates a step and then updates vehicle control. If you want a vehicle to enter at exactly 0.3 with a step of 0.1 it means the simulation should start at start_time==0.2.

Returns:

Dict[str, Observation]. This observation is as follows…
  • If no agents: the initial simulation observation at start_time

  • If agents: the first step of the simulation with an agent observation

property resetting: bool

If the simulation is currently resetting

property road_map: RoadMap

The road map api which allows lookup of road features.

property road_stiffness: Any

The stiffness of the road.

property scenario: Scenario

The current simulation scenario.

property sensor_manager: SensorManager

The sensor manager for direct manipulation.

setup(scenario: Scenario)[source]

Setup the next scenario.

property should_reset

If the simulation requires a reset.

step(agent_actions: Dict[str, Any], time_delta_since_last_step: float | None = None) Tuple[Dict[str, Observation], Dict[str, float], Dict[str, bool], Dict[str, Dict[str, float]]][source]

Progress the simulation by a fixed or specified time.

Parameters:
  • agent_actions – Actions that the agents want to perform on their actors.

  • time_delta_since_last_step – Overrides the simulation step length. Progress simulation time by the given amount. Note the time_delta_since_last_step param is in (nominal) seconds.

Returns:

The simulation step return as (observations, rewards, dones, infos).

property step_count: int

The number of steps since the last reset.

switch_control_to_agent(vehicle_id: str, agent_id: str, mission: NavigationMission, recreate: bool, is_hijacked: bool) Vehicle[source]

Give control of the specified vehicle to the given agent.

It is not possible to take over a vehicle already controlled by another agent.

switch_ego_agents(agent_interfaces: Dict[str, AgentInterface])[source]

Change the ego agents in the simulation. Effective on the next reset.

teardown()[source]

Clean up episode resources.

teardown_social_agents(agent_ids: Iterable[str])[source]

Tear-down agents in the given sequence.

Parameters:

agent_ids – A sequence of agent ids to terminate and release.

teardown_social_agents_without_actors(agent_ids: Iterable[str])[source]

Tear-down agents in the given list that have no actors registered as controlled-by or shadowed-by (for each given agent.)

Parameters:

agent_ids – Sequence of agent ids

property traffic_history_provider: TrafficHistoryProvider

The source of any traffic history data.

property traffic_sims: List[TrafficProvider]

The underlying traffic simulations.

vehicle_exited_bubble(vehicle_id: str, agent_id: str, teardown_agent: bool)[source]

Bubbles call this when a vehicle is exiting the bubble. Will try to find a new provider for the vehicle if necessary.

property vehicle_index: VehicleIndex

The vehicle index for direct vehicle manipulation.

property version: str

SMARTS version.

exception smarts.core.smarts.SMARTSDestroyedError[source]

Represents a case where SMARTS cannot operate because it is destroyed.

exception smarts.core.smarts.SMARTSNotSetupError[source]

Represents a case where SMARTS cannot operate because it is not set up yet.