Skip to content

Commit

Permalink
GitHub Actions: Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Adaickalavan committed Mar 28, 2022
1 parent 0f0b14d commit ce1d17b
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 40 deletions.
3 changes: 2 additions & 1 deletion envision/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
# Mapping of simulation ID to the Frames data store
FRAMES = {}

class AllowCORSMixin():

class AllowCORSMixin:
"""A mixin that adds CORS headers to the page."""

_HAS_DYNAMIC_ATTRIBUTES = True
Expand Down
11 changes: 7 additions & 4 deletions smarts/core/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# THE SOFTWARE.

import logging
from typing import Any, Dict, Set, Tuple, Optional, Union
from typing import Any, Dict, Optional, Set, Tuple, Union

import cloudpickle

Expand Down Expand Up @@ -161,7 +161,10 @@ def observe_from(
def observe(
self, sim
) -> Tuple[
Dict[str, Union[Dict[str, Observation], Observation]], Dict[str, Union[Dict[str, float], float]], Dict[str, Union[Dict[str, float], float]], Dict[str, Union[Dict[str, bool], bool]]
Dict[str, Union[Dict[str, Observation], Observation]],
Dict[str, Union[Dict[str, float], float]],
Dict[str, Union[Dict[str, float], float]],
Dict[str, Union[Dict[str, bool], bool]],
]:
"""Generate observations from all vehicles associated with an active agent."""
observations = {}
Expand Down Expand Up @@ -224,7 +227,7 @@ def observe(
else:
logging.log(
logging.DEBUG,
f"Agent `{agent_id}` has raised done with {obs.events}",
f"Agent `{agent_id}` has raised done with {obs.events}",
)

rewards[agent_id] = vehicle.trip_meter_sensor(increment=True)
Expand All @@ -234,7 +237,7 @@ def observe(
dones = {agent_id: True for agent_id in self.agent_ids}
dones["__sim__"] = True

return observations, rewards, scores, dones
return observations, rewards, scores, dones

def _vehicle_reward(self, vehicle_id, sim) -> float:
return sim.vehicle_index.vehicle_by_id(vehicle_id).trip_meter_sensor(
Expand Down
6 changes: 3 additions & 3 deletions smarts/core/bubble_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ def admissibility(
# pytype: disable=unsupported-operands
all_hijacked_vehicle_ids = (
current_hijacked_vehicle_ids
| vehicle_ids_by_bubble_state[BubbleState.InAirlock][self]
| vehicle_ids_by_bubble_state[BubbleState.InAirlock][self]
) - {vehicle_id}

all_shadowed_vehicle_ids = (
current_shadowed_vehicle_ids
| vehicle_ids_by_bubble_state[BubbleState.InBubble][self]
| vehicle_ids_by_bubble_state[BubbleState.InBubble][self]
) - {vehicle_id}
# pytype: enable=unsupported-operands

Expand Down Expand Up @@ -510,7 +510,7 @@ def _airlock_social_vehicle_with_social_agent(
)

if social_agent is None:
return
return

self._start_social_agent(
sim, agent_id, social_agent, social_agent_actor, bubble
Expand Down
1 change: 1 addition & 0 deletions smarts/core/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def set_pose(self, pose: Pose):
chassis."""
raise NotImplementedError


class BoxChassis(Chassis):
"""Control a vehicle by setting its absolute position and heading. The collision
shape of the vehicle is a box of the provided dimensions.
Expand Down
3 changes: 2 additions & 1 deletion smarts/core/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

import math
import random
import numpy as np
from dataclasses import dataclass, field
from typing import Optional, Tuple, Union

import numpy as np

from smarts.sstudio.types import EntryTactic, TrapEntryTactic

from .coordinates import Dimensions, Heading, Point, Pose, RefLinePoint
Expand Down
4 changes: 3 additions & 1 deletion smarts/core/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ class Sensors:
_log = logging.getLogger("Sensors")

@staticmethod
def observe_batch(sim, agent_id, sensor_states, vehicles) -> Tuple[Dict[str, Observation], Dict[str, bool]]:
def observe_batch(
sim, agent_id, sensor_states, vehicles
) -> Tuple[Dict[str, Observation], Dict[str, bool]]:
"""Operates all sensors on a batch of vehicles for a single agent."""
# TODO: Replace this with a more efficient implementation that _actually_
# does batching
Expand Down
1 change: 1 addition & 0 deletions smarts/core/tests/test_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def notebook():
_, tmppath = tempfile.mkstemp(suffix=".ipynb")
with open(tmppath, "w") as f:
import smarts.core.tests

# pytype: disable=module-attr
f.write(importlib_resources.read_text(smarts.core.tests, NOTEBOOK_NAME))
# pytype: enable=module-attr
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import gym
import numpy as np
import pytest
from panda3d.core import OrthographicLens, Point2, Point3
from panda3d.core import OrthographicLens, Point2, Point3

from smarts.core.agent import Agent
from smarts.core.agent_interface import (
Expand Down
3 changes: 2 additions & 1 deletion smarts/core/tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def smarts_wo_renderer():
@pytest.fixture
def scenario():
mission = Mission(
start=Start(np.array([71.65, 63.78]), Heading(math.pi * 0.91)), goal=EndlessGoal()
start=Start(np.array([71.65, 63.78]), Heading(math.pi * 0.91)),
goal=EndlessGoal(),
)
scenario = Scenario(
scenario_root="scenarios/loop",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_trajectory_interpolation_provider_in_smarts(smarts, agent_spec, scenari
if agent_obs.events.reached_goal:
reached_goal = True
break

curr_position = agent_obs.ego_vehicle_state.position
curr_heading = agent_obs.ego_vehicle_state.heading
curr_speed = agent_obs.ego_vehicle_state.speed
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def import_module_from_file(module_name, path: Path):
spec = importlib.util.spec_from_file_location(module_name, f"{path}")
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module) # pytype: disable=attribute-error
spec.loader.exec_module(module) # pytype: disable=attribute-error
11 changes: 7 additions & 4 deletions smarts/core/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
from dataclasses import dataclass
from functools import lru_cache
from typing import Any, Dict, List, Tuple, Optional, Sequence, Union
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union

import numpy as np

Expand All @@ -31,7 +31,7 @@

from . import models
from .chassis import AckermannChassis, BoxChassis, Chassis
from .colors import SceneColors, Colors
from .colors import Colors, SceneColors
from .coordinates import Dimensions, Heading, Pose
from .sensors import (
AccelerometerSensor,
Expand Down Expand Up @@ -142,7 +142,8 @@ class VehicleConfig:

class Vehicle:
"""Represents a single vehicle."""
_HAS_DYNAMIC_ATTRIBUTES=True

_HAS_DYNAMIC_ATTRIBUTES = True

_HAS_DYNAMIC_ATTRIBUTES = True # pytype dynamic

Expand Down Expand Up @@ -385,7 +386,9 @@ def build_agent_vehicle(
else:
start_pose = Pose.from_center(start.position, start.heading)

vehicle_color = SceneColors.Agent.value if trainable else SceneColors.SocialAgent.value
vehicle_color = (
SceneColors.Agent.value if trainable else SceneColors.SocialAgent.value
)

if agent_interface.vehicle_type == "sedan":
urdf_name = "vehicle"
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/vehicle_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def stop_agent_observation(self, vehicle_id):

vehicle = self._vehicles[vehicle_id]
# pytype: disable=attribute-error
Vehicle.detach_all_sensors_from_vehicle(vehicle)
Vehicle.detach_all_sensors_from_vehicle(vehicle)
# pytype: enable=attribute-error

v_index = self._controlled_by["vehicle_id"] == vehicle_id
Expand Down
2 changes: 1 addition & 1 deletion smarts/env/wrappers/frame_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _get_observations(
frames_list = list(self._frames[agent_id])
new_frames[agent_id] = copy.deepcopy(frames_list)

return dict(new_frames)
return dict(new_frames)

def step(
self, agent_actions: Dict
Expand Down
26 changes: 15 additions & 11 deletions smarts/ros/src/smarts_ros/scripts/ros_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from threading import Lock
from typing import Any, Dict, Optional, Sequence, Tuple

import numpy as np
import numpy as np
import rospy
from smarts_ros.msg import (
AgentReport,
Expand All @@ -41,7 +41,7 @@
from smarts_ros.srv import SmartsInfo, SmartsInfoRequest, SmartsInfoResponse

from envision.client import Client as Envision
from smarts.core.coordinates import Dimensions, Heading, Pose, Point
from smarts.core.coordinates import Dimensions, Heading, Point, Pose
from smarts.core.plan import (
EndlessGoal,
Mission,
Expand Down Expand Up @@ -283,13 +283,17 @@ def _decode_vehicle_type(vehicle_type: int) -> str:
@staticmethod
def _pose_from_ros(ros_pose) -> Pose:
return Pose(
position=np.array([ros_pose.position.x, ros_pose.position.y, ros_pose.position.z]),
orientation=np.array([
ros_pose.orientation.x,
ros_pose.orientation.y,
ros_pose.orientation.z,
ros_pose.orientation.w,
]),
position=np.array(
[ros_pose.position.x, ros_pose.position.y, ros_pose.position.z]
),
orientation=np.array(
[
ros_pose.orientation.x,
ros_pose.orientation.y,
ros_pose.orientation.z,
ros_pose.orientation.w,
]
),
)

def _agent_spec_callback(self, ros_agent_spec: AgentSpec):
Expand All @@ -299,7 +303,7 @@ def _agent_spec_callback(self, ros_agent_spec: AgentSpec):
task = ros_agent_spec.tasks[0]
task_params = json.loads(task.params_json) if task.params_json else {}
task_version = task.task_ver or "latest"
agent_locator = f"{self._zoo_module}:{task.task_ref}-{task_version}" # pytype: disable=attribute-error
agent_locator = f"{self._zoo_module}:{task.task_ref}-{task_version}" # pytype: disable=attribute-error
agent_spec = None
try:
agent_spec = registry.make(agent_locator, **task_params)
Expand Down Expand Up @@ -647,7 +651,7 @@ def run_forever(self):
raise RuntimeError("must call setup_smarts() first.")

# pytype: disable=attribute-error
rospy.Service(self._service_name, SmartsInfo, self._get_smarts_info)
rospy.Service(self._service_name, SmartsInfo, self._get_smarts_info)
# pytype: enable=attribute-error

warned_scenario = False
Expand Down
2 changes: 1 addition & 1 deletion smarts/ros/src/smarts_ros/scripts/test_smarts_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _reset_callback(self, reset_msg: SmartsReset):
self._create_agent()
for agent_spec in self._agents.values():
# pytype: disable=attribute-error
self._agent_publisher.publish(agent_spec)
self._agent_publisher.publish(agent_spec)
# pytype: enable=attribute-error

def run_forever(self):
Expand Down
7 changes: 4 additions & 3 deletions ultra/tests/test_episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
import ray

from smarts.zoo.registry import make
from ultra.utils.episode import episodes, Episode
from ultra.utils.episode import Episode, episodes

AGENT_ID = "001"
timestep_sec = 0.1
seed = 2
task_id = "00"
task_level = "easy"


class EpisodeTest(unittest.TestCase):
# Put generated files and folders in this directory.
OUTPUT_DIRECTORY = "tests/episode_test/"
Expand Down Expand Up @@ -115,8 +116,8 @@ def run_experiment():
# # abs(result[key] - episode_info["Train"][AGENT_ID].data[key]) <= 0.001
# # )

@unittest.skip("Experiment test is not necessary at this time.")
def test_episode_counter(self):
@unittest.skip("Experiment test is not necessary at this time.")
def test_episode_counter(self):
@ray.remote(max_calls=1, num_gpus=0, num_cpus=1)
def run_experiment():
agent, env = prepare_test_env_agent()
Expand Down
7 changes: 3 additions & 4 deletions ultra/tests/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import time
import unittest


import dill
import dill
import gym
import ray

Expand Down Expand Up @@ -378,7 +377,7 @@ def extract(path):
)

try:
policy_class = m.group(0) # pytype: disable=attribute-error
policy_class = m.group(0) # pytype: disable=attribute-error
except AttributeError as e:
self.assertTrue(False)

Expand Down Expand Up @@ -472,7 +471,7 @@ def run_experiment(scenario_info, num_agents, log_dir, headless=True):
active_agent_ids = observations.keys() & next_observations.keys()
# pytype: disable=attribute-error
loss_outputs = {
agent_id: agents[agent_id].step(
agent_id: agents[agent_id].step(
state=observations[agent_id],
action=actions[agent_id],
reward=rewards[agent_id],
Expand Down
2 changes: 1 addition & 1 deletion ultra/ultra/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.
import os
import pickle
from typing import Sequence, Tuple, Optional
from typing import Optional, Sequence, Tuple

# Set environment to better support Ray
os.environ["MKL_NUM_THREADS"] = "1"
Expand Down
1 change: 1 addition & 0 deletions zoo/policies/open-agent/open_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# pytype: disable=attribute-error


def angle_error(a, b):

return cs.fabs(
Expand Down

0 comments on commit ce1d17b

Please sign in to comment.