Co-simulation#

class invertedai.cosimulation.BasicCosimulation(location: str, conditional_agent_properties: Optional[List[AgentProperties]] = None, conditional_agent_agent_states: Optional[List[AgentState]] = None, num_non_ego_conditional_agents: Optional[int] = 0, **kwargs)[source]#

Stateful wrapper around the Inverted AI API to simplify co-simulation. All keyword arguments to large_initialize() can be passed to the constructor here and a sufficient combination of them must be passed as required by large_initialize(). This wrapper caches static agent properties and propagates the recurrent state, so that only states of conditional agents need to be exchanged with it to perform co-simulation. Typically, each time step requires a single call to self.step().

This wrapper only supports a minimal co-simulation functionality. For more advanced use cases, call large_initialize() and large_drive() directly.

location:

Location name as expected by large_initialize() and large_drive().

conditional_agent_properties:

Agent properties for all conditional agents that must be given to the API so the NPC agents are aware of them. Please refer to the documentation for large_initialize() for more information on how to format this parameter (treating the conditional agents as “predefined agents”). Furthermore, any predefined agents for which the user wishes the IAI API to control must be defined at the end of this list.

conditional_agent_agent_states:

Agent states for all conditional agents that must be given to the API so the NPC agents are aware of their states. Please refer to the documentation for large_initialize() for more information on how to format this parameter (treating the ego agents as “predefined agents”). Furthermore, any predefined agents for which the user wishes the IAI API to control must be defined at the end of this list.

num_non_ego_conditional_agents:

The ego agents are the subset of the conditional agents that are NOT controlled by the Inverted AI API. This parameter allows some of the conditional agents with predefined states and properties to nonetheless be controlled by the Inverted AI API. The non-ego conditional agents must be placed at the end of the conditional agents list and the ego agents must be placed at the beginning of the conditional agents list.

property agent_count: int#

The total number of agents, both ego and NPCs.

property agent_properties: List[AgentProperties]#

The properties (length, width, rear_axis_offset, max_speed) for all agents, including ego.

property agent_states: List[AgentState]#

The predicted states for all agents, including ego.

property ego_properties: List[AgentProperties]#

Returns the properties of ego agents in order. The NPC agents are excluded.

property ego_states: List[AgentState]#

Returns the predicted states of ego agents in order. The NPC agents are excluded.

property light_states: Optional[Dict[int, TrafficLightState]]#

Returns the traffic light states if any exists on the map.

property location: str#

Location name as recognized by Inverted AI API.

property npc_properties: List[AgentProperties]#

Returns the properties of NPCs (non-ego agents) in order. The ego agents are excluded.

property npc_recurrent_states: List[RecurrentState]#

Returns the recurrent states of NPCs (non-ego agents) in order. The ego agents are excluded.

property npc_states: List[AgentState]#

Returns the predicted states of NPCs (non-ego agents) in order. The predictions for ego agents are excluded.

property response: Union[DriveResponse, InitializeResponse]#

Get the current response data object containing all information received from the API.

step(current_conditional_agent_states: List[AgentState], **kwargs) None[source]#

Calls large_drive() to advance the simulation by one time step. Current states of ego agents need to be provided to synchronize with your local simulator. This function assumes the conditional agents are placed at the beginning of given agent states list. All remaining keyword arguments to large_drive() can be passed to this function here to receive the desired information from the API.

current_conditional_agent_states:

States of ego agents before the step which must match the number of given ego, conditional agents during initialization.