Skip to content

Commit

Permalink
Fix pytype types test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Jan 4, 2024
1 parent 1d3e58b commit a2d3f17
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
6 changes: 0 additions & 6 deletions examples/tools/pybullet_trajectory_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ def run(client, vehicle, plane_body_id, sliders, n_steps=1e6):
vehicle,
controller_state,
dt_sec=TIMESTEP_SEC,
heading_gain=0.05,
lateral_gain=0.65,
velocity_gain=1.8,
traction_gain=2,
derivative_activation=False,
speed_reduction_activation=False,
)

client.stepSimulation()
Expand Down
2 changes: 2 additions & 0 deletions smarts/core/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import annotations

import importlib.resources as pkg_resources
import logging
import os
Expand Down
6 changes: 5 additions & 1 deletion smarts/core/utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ class VehicleDefinitions:

data: Dict[str, Any]
"""The data associated with the vehicle definitions. This is generally vehicle type keys."""
filepath: str
filepath: Union[str, Path]
"""The path to the vehicle definitions file."""

def __post_init__(self):
if isinstance(self.filepath, Path):
object.__setattr__(self, "filepath", self.filepath.__str__())

@lru_cache(maxsize=20)
def load_vehicle_definition(self, vehicle_class: str):
"""Loads in a particular vehicle definition."""
Expand Down
4 changes: 2 additions & 2 deletions smarts/core/utils/type_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ def __init__(self, base_type: Type[T]) -> None:
self._associated_groups: Dict[T, List[Type[T]]] = defaultdict(list)
self._base_type = base_type

def clear_type(self, type_to_clear: Type[T]):
def clear_type(self, type_to_clear: Type[S]):
"""Clear all instances of the given type from this suite. This includes
all sub-classes. This should be an sub-class of the type that this suite
manages.
Args:
type_to_clear (Type[T]): The type to clear.
type_to_clear (Type[S]): The type to clear.
"""
self._assert_is_managed(type_to_clear)
t = self._associated_groups.get(type_to_clear)
Expand Down
4 changes: 2 additions & 2 deletions smarts/core/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from .vehicle_state import VEHICLE_CONFIGS, VehicleState

if TYPE_CHECKING:
from smarts.core.plan import Mission
from smarts.core import plan
from smarts.core.renderer_base import RendererBase
from smarts.core.sensor_manager import SensorManager
from smarts.core.smarts import SMARTS
Expand Down Expand Up @@ -273,7 +273,7 @@ def valid(self) -> bool:

@staticmethod
def agent_vehicle_dims(
mission: "Mission", default: Optional[str] = None
mission: "plan.Mission", default: Optional[str] = None
) -> Dimensions:
"""Get the vehicle dimensions from the mission requirements.
Args:
Expand Down
28 changes: 17 additions & 11 deletions smarts/core/vehicle_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
from .vehicle import Vehicle

if TYPE_CHECKING:
from smarts.core import plan
from smarts.core.agent_interface import AgentInterface
from smarts.core.controllers.action_space_type import ActionSpaceType
from smarts.core.plan import Plan
from smarts.core.renderer_base import RendererBase
from smarts.core.smarts import SMARTS

Expand Down Expand Up @@ -118,7 +118,9 @@ def __init__(self):
self._controller_states = {}

# Loaded from yaml file on scenario reset
self._vehicle_definitions: resources.VehicleDefinitions = {}
self._vehicle_definitions: resources.VehicleDefinitions = (
resources.VehicleDefinitions({}, "")
)

@classmethod
def identity(cls):
Expand Down Expand Up @@ -395,7 +397,7 @@ def start_agent_observation(
vehicle_id,
agent_id,
agent_interface: AgentInterface,
plan: Plan,
plan: "plan.Plan",
boid=False,
initialize_sensors=True,
):
Expand Down Expand Up @@ -556,14 +558,14 @@ def stop_agent_observation(self, vehicle_id) -> Vehicle:
@clear_cache
def relinquish_agent_control(
self, sim: SMARTS, vehicle_id: str, road_map: RoadMap
) -> Tuple[VehicleState, List[str]]:
) -> Tuple[VehicleState, Optional[RoadMap.Route]]:
"""Give control of the vehicle back to its original controller."""
self._log.debug(f"Relinquishing agent control v_id={vehicle_id}")

v_id = _2id(vehicle_id)

ss = sim.sensor_manager.sensor_state_for_actor_id(vehicle_id)
route = ss.get_plan(road_map).route
route = ss.get_plan(road_map).route if ss else None
vehicle = self.stop_agent_observation(vehicle_id)

# pytype: disable=attribute-error
Expand Down Expand Up @@ -596,7 +598,11 @@ def relinquish_agent_control(

@clear_cache
def attach_sensors_to_vehicle(
self, sim: SMARTS, vehicle_id, agent_interface: AgentInterface, plan: Plan
self,
sim: SMARTS,
vehicle_id,
agent_interface: AgentInterface,
plan: "plan.Plan",
):
"""Attach sensors as per the agent interface requirements to the specified vehicle."""
vehicle_id = _2id(vehicle_id)
Expand Down Expand Up @@ -639,6 +645,7 @@ def _switch_control_to_agent_recreate(
), f"Missing agent_interface for agent_id={agent_id}"
vehicle = self._vehicles[vehicle_id]
sensor_state = sim.sensor_manager.sensor_state_for_actor_id(vehicle.id)
assert sensor_state is not None
controller_state = self._controller_states[vehicle_id]
plan = sensor_state.get_plan(sim.road_map)

Expand All @@ -652,7 +659,7 @@ def _switch_control_to_agent_recreate(
agent_interface.action,
vehicle_definition.get("type"),
agent_interface.vehicle_class,
plan,
plan.mission,
vehicle_definition.get("dynamics_model"),
vehicle_definition.get("tire_params"),
vehicle_definition.get("visual_model"),
Expand Down Expand Up @@ -704,7 +711,7 @@ def _build_agent_vehicle(
action: Optional[ActionSpaceType],
vehicle_type: str,
vehicle_class: str,
plan: Plan,
mission: plan.Mission,
vehicle_dynamics_filepath: Optional[str],
tire_filepath: str,
visual_model_filepath: str,
Expand All @@ -715,7 +722,6 @@ def _build_agent_vehicle(
"""Create a new vehicle and set up sensors and planning information as required by the
ego agent.
"""
mission = plan.mission
chassis_dims = Vehicle.agent_vehicle_dims(mission, default=vehicle_type)

start = mission.start
Expand Down Expand Up @@ -781,7 +787,7 @@ def build_agent_vehicle(
sim: SMARTS,
agent_id,
agent_interface: AgentInterface,
plan: Plan,
plan: "plan.Plan",
trainable: bool,
initial_speed: Optional[float] = None,
boid: bool = False,
Expand All @@ -798,7 +804,7 @@ def build_agent_vehicle(
action=agent_interface.action,
vehicle_type=vehicle_definition.get("type"),
vehicle_class=agent_interface.vehicle_class,
plan=plan,
mission=plan.mission,
vehicle_dynamics_filepath=vehicle_definition.get("dynamics_model"),
tire_filepath=vehicle_definition.get("tire_params"),
visual_model_filepath=vehicle_definition.get("visual_model"),
Expand Down
6 changes: 5 additions & 1 deletion smarts/p3d/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,11 @@ def set_interest(self, interest_filter: re.Pattern, interest_color: Colors):
self._interest_color = interest_color

def create_vehicle_node(
self, glb_model: str, vid: str, color: Union[Colors, SceneColors], pose: Pose
self,
glb_model: Union[str, Path],
vid: str,
color: Union[Colors, SceneColors],
pose: Pose,
):
"""Create a vehicle node."""
if vid in self._vehicle_nodes:
Expand Down

0 comments on commit a2d3f17

Please sign in to comment.