From 511ff02d505117bdc03a9df64d7a2603e9ce1dba Mon Sep 17 00:00:00 2001 From: Luigi Berducci Date: Thu, 1 Feb 2024 19:16:43 +0100 Subject: [PATCH] Revert "linting" This reverts commit ff7a3a16 --- examples/video_recording.py | 8 +++- examples/waypoint_follow.py | 2 +- gym/f110_gym/__init__.py | 3 +- gym/f110_gym/envs/action.py | 64 +++++++++++-------------- gym/f110_gym/envs/cubic_spline.py | 6 +-- gym/f110_gym/envs/f110_env.py | 9 ++-- gym/f110_gym/envs/f110_env_backup.py | 4 +- gym/f110_gym/envs/reset/__init__.py | 16 ++----- gym/f110_gym/test/benchmark_renderer.py | 0 tests/legacy_scan_gen.py | 6 ++- tests/test_f110_env.py | 5 +- tests/test_renderer.py | 6 ++- tests/test_scan_sim.py | 3 +- 13 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 gym/f110_gym/test/benchmark_renderer.py diff --git a/examples/video_recording.py b/examples/video_recording.py index 7ab83de6..3c593fbe 100644 --- a/examples/video_recording.py +++ b/examples/video_recording.py @@ -34,7 +34,13 @@ def main(): planner = PurePursuitPlanner(track=track, wb=0.17145 + 0.15875) poses = np.array( - [[track.raceline.xs[0], track.raceline.ys[0], track.raceline.yaws[0],]] + [ + [ + track.raceline.xs[0], + track.raceline.ys[0], + track.raceline.yaws[0], + ] + ] ) obs, info = env.reset(options={"poses": poses}) diff --git a/examples/waypoint_follow.py b/examples/waypoint_follow.py index 46d7a950..596ac28b 100644 --- a/examples/waypoint_follow.py +++ b/examples/waypoint_follow.py @@ -166,7 +166,7 @@ def get_actuation(pose_theta, lookahead_point, position, lookahead_distance, whe speed = lookahead_point[2] if np.abs(waypoint_y) < 1e-6: return speed, 0.0 - radius = 1 / (2.0 * waypoint_y / lookahead_distance ** 2) + radius = 1 / (2.0 * waypoint_y / lookahead_distance**2) steering_angle = np.arctan(wheelbase / radius) return speed, steering_angle diff --git a/gym/f110_gym/__init__.py b/gym/f110_gym/__init__.py index a993eb05..20052799 100644 --- a/gym/f110_gym/__init__.py +++ b/gym/f110_gym/__init__.py @@ -1,5 +1,6 @@ import gymnasium as gym gym.register( - id="f110-v0", entry_point="f110_gym.envs:F110Env", + id="f110-v0", + entry_point="f110_gym.envs:F110Env", ) diff --git a/gym/f110_gym/envs/action.py b/gym/f110_gym/envs/action.py index 080348e4..fcdbc817 100644 --- a/gym/f110_gym/envs/action.py +++ b/gym/f110_gym/envs/action.py @@ -21,8 +21,7 @@ def from_string(action: str): return SpeedAction else: raise ValueError(f"Unknown action type {action}") - - + class LongitudinalAction: def __init__(self) -> None: self._type = None @@ -40,10 +39,7 @@ def type(self) -> str: @property def space(self) -> gym.Space: - return gym.spaces.Box( - low=self.lower_limit, high=self.upper_limit, dtype=np.float32 - ) - + return gym.spaces.Box(low=self.lower_limit, high=self.upper_limit, dtype=np.float32) class AcclAction(LongitudinalAction): def __init__(self, params: Dict) -> None: @@ -54,7 +50,6 @@ def __init__(self, params: Dict) -> None: def act(self, action: Tuple[float, float], state, params) -> float: return action - class SpeedAction(LongitudinalAction): def __init__(self, params: Dict) -> None: super().__init__() @@ -65,12 +60,15 @@ def act( self, action: Tuple[float, float], state: np.ndarray, params: Dict ) -> float: accl = pid_accl( - action, state[3], params["a_max"], params["v_max"], params["v_min"], + action, + state[3], + params["a_max"], + params["v_max"], + params["v_min"], ) return accl - class SteerAction: def __init__(self) -> None: self._type = None @@ -85,13 +83,10 @@ def act(self, steer_action: Any, **kwargs) -> float: @property def type(self) -> str: return self._type - + @property def space(self) -> gym.Space: - return gym.spaces.Box( - low=self.lower_limit, high=self.upper_limit, dtype=np.float32 - ) - + return gym.spaces.Box(low=self.lower_limit, high=self.upper_limit, dtype=np.float32) class SteeringAngleAction(SteerAction): def __init__(self, params: Dict) -> None: @@ -101,11 +96,14 @@ def __init__(self, params: Dict) -> None: def act( self, action: Tuple[float, float], state: np.ndarray, params: Dict - ) -> float: - sv = pid_steer(action, state[2], params["sv_max"],) + ) -> float: + sv = pid_steer( + action, + state[2], + params["sv_max"], + ) return sv - - + class SteeringSpeedAction(SteerAction): def __init__(self, params: Dict) -> None: super().__init__() @@ -114,10 +112,9 @@ def __init__(self, params: Dict) -> None: def act( self, action: Tuple[float, float], state: np.ndarray, params: Dict - ) -> float: + ) -> float: return action - class SteerActionEnum(Enum): Steering_Angle = 1 Steering_Speed = 2 @@ -131,12 +128,11 @@ def from_string(action: str): else: raise ValueError(f"Unknown action type {action}") - class CarAction: - def __init__(self, control_mode: list[str, str], params: Dict) -> None: + def __init__(self, control_mode : list[str, str], params: Dict) -> None: long_act_type_fn = None steer_act_type_fn = None - if type(control_mode) == str: # only one control mode specified + if type(control_mode) == str: # only one control mode specified try: long_act_type_fn = LongitudinalActionEnum.from_string(control_mode) except ValueError: @@ -146,24 +142,24 @@ def __init__(self, control_mode: list[str, str], params: Dict) -> None: raise ValueError(f"Unknown control mode {control_mode}") if control_mode == "steering_speed": warnings.warn( - f"Only one control mode specified, using {control_mode} for steering and defaulting to acceleration for longitudinal control" + f'Only one control mode specified, using {control_mode} for steering and defaulting to acceleration for longitudinal control' ) long_act_type_fn = LongitudinalActionEnum.from_string("accl") else: warnings.warn( - f"Only one control mode specified, using {control_mode} for steering and defaulting to speed for longitudinal control" + f'Only one control mode specified, using {control_mode} for steering and defaulting to speed for longitudinal control' ) long_act_type_fn = LongitudinalActionEnum.from_string("speed") else: if control_mode == "accl": warnings.warn( - f"Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering speed for steering" + f'Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering speed for steering' ) steer_act_type_fn = SteerActionEnum.from_string("steering_speed") else: warnings.warn( - f"Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering angle for steering" + f'Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering angle for steering' ) steer_act_type_fn = SteerActionEnum.from_string("steering_angle") @@ -172,9 +168,9 @@ def __init__(self, control_mode: list[str, str], params: Dict) -> None: steer_act_type_fn = SteerActionEnum.from_string(control_mode[1]) else: raise ValueError(f"Unknown control mode {control_mode}") - - self._longitudinal_action: LongitudinalAction = long_act_type_fn(params) - self._steer_action: SteerAction = steer_act_type_fn(params) + + self._longitudinal_action : LongitudinalAction = long_act_type_fn(params) + self._steer_action : SteerAction = steer_act_type_fn(params) @abstractmethod def act(self, action: Any, **kwargs) -> Tuple[float, float]: @@ -188,12 +184,8 @@ def type(self) -> Tuple[str, str]: @property def space(self) -> gym.Space: - low = np.array( - [self._steer_action.lower_limit, self._longitudinal_action.lower_limit] - ).astype(np.float32) - high = np.array( - [self._steer_action.upper_limit, self._longitudinal_action.upper_limit] - ).astype(np.float32) + low = np.array([self._steer_action.lower_limit, self._longitudinal_action.lower_limit]).astype(np.float32) + high = np.array([self._steer_action.upper_limit, self._longitudinal_action.upper_limit]).astype(np.float32) return gym.spaces.Box(low=low, high=high, shape=(2,), dtype=np.float32) diff --git a/gym/f110_gym/envs/cubic_spline.py b/gym/f110_gym/envs/cubic_spline.py index 5ed193d6..8b1a0fab 100644 --- a/gym/f110_gym/envs/cubic_spline.py +++ b/gym/f110_gym/envs/cubic_spline.py @@ -64,7 +64,7 @@ def calc_position(self, x): i = self.__search_index(x) dx = x - self.x[i] position = ( - self.a[i] + self.b[i] * dx + self.c[i] * dx ** 2.0 + self.d[i] * dx ** 3.0 + self.a[i] + self.b[i] * dx + self.c[i] * dx**2.0 + self.d[i] * dx**3.0 ) return position @@ -86,7 +86,7 @@ def calc_first_derivative(self, x): i = self.__search_index(x) dx = x - self.x[i] - dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx ** 2.0 + dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx**2.0 return dy def calc_second_derivative(self, x): @@ -205,7 +205,7 @@ def calc_curvature(self, s): ddx = self.sx.calc_second_derivative(s) dy = self.sy.calc_first_derivative(s) ddy = self.sy.calc_second_derivative(s) - k = (ddy * dx - ddx * dy) / ((dx ** 2 + dy ** 2) ** (3 / 2)) + k = (ddy * dx - ddx * dy) / ((dx**2 + dy**2) ** (3 / 2)) return k def calc_yaw(self, s): diff --git a/gym/f110_gym/envs/f110_env.py b/gym/f110_gym/envs/f110_env.py index b021d326..bb14d753 100644 --- a/gym/f110_gym/envs/f110_env.py +++ b/gym/f110_gym/envs/f110_env.py @@ -27,7 +27,8 @@ # gym imports import gymnasium as gym -from f110_gym.envs.action import CarAction, from_single_to_multi_action_space +from f110_gym.envs.action import (CarAction, + from_single_to_multi_action_space) from f110_gym.envs.integrator import IntegratorType from f110_gym.envs.rendering import make_renderer @@ -239,9 +240,7 @@ def configure(self, config: dict) -> None: if hasattr(self, "action_space"): # if some parameters changed, recompute action space - self.action_type = CarAction( - self.config["control_input"], params=self.params - ) + self.action_type = CarAction(self.config["control_input"], params=self.params) self.action_space = from_single_to_multi_action_space( self.action_type.space, self.num_agents ) @@ -273,7 +272,7 @@ def _check_done(self): temp_y[idx2] = -right_t - temp_y[idx2] temp_y[np.invert(np.logical_or(idx1, idx2))] = 0 - dist2 = delta_pt[0, :] ** 2 + temp_y ** 2 + dist2 = delta_pt[0, :] ** 2 + temp_y**2 closes = dist2 <= 0.1 for i in range(self.num_agents): if closes[i] and not self.near_starts[i]: diff --git a/gym/f110_gym/envs/f110_env_backup.py b/gym/f110_gym/envs/f110_env_backup.py index 62644e62..b488492d 100644 --- a/gym/f110_gym/envs/f110_env_backup.py +++ b/gym/f110_gym/envs/f110_env_backup.py @@ -263,7 +263,7 @@ def _check_done(self): temp_y[idx2] = -right_t - temp_y[idx2] temp_y[np.invert(np.logical_or(idx1, idx2))] = 0 - dist2 = delta_pt[0, :] ** 2 + temp_y ** 2 + dist2 = delta_pt[0, :] ** 2 + temp_y**2 closes = dist2 <= 0.1 for i in range(self.num_agents): if closes[i] and not self.near_starts[i]: @@ -291,7 +291,7 @@ def _check_done(self): temp_y = -right_t - delta_pt[1] else: temp_y = 0 - dist2 = delta_pt[0] ** 2 + temp_y ** 2 + dist2 = delta_pt[0] ** 2 + temp_y**2 close = dist2 <= 0.1 # close = dist_to_start <= self.start_thresh if close and not self.near_start: diff --git a/gym/f110_gym/envs/reset/__init__.py b/gym/f110_gym/envs/reset/__init__.py index d15f0379..d5f56ea1 100644 --- a/gym/f110_gym/envs/reset/__init__.py +++ b/gym/f110_gym/envs/reset/__init__.py @@ -13,19 +13,9 @@ def make_reset_fn(type: str | None, track: Track, num_agents: int, **kwargs) -> refline = {"cl": track.centerline, "rl": track.raceline}[refline_token] reset_fn = {"grid": GridResetFn, "random": AllTrackResetFn}[reset_token] shuffle = {"static": False, "random": True}[shuffle_token] - options = {"cl": {"move_laterally": True}, "rl": {"move_laterally": False}}[ - refline_token - ] + options = {"cl": {"move_laterally": True}, "rl": {"move_laterally": False}}[refline_token] except Exception as ex: - raise ValueError( - f"Invalid reset function type: {type}. Expected format: __" - ) from ex + raise ValueError(f"Invalid reset function type: {type}. Expected format: __") from ex - return reset_fn( - reference_line=refline, - num_agents=num_agents, - shuffle=shuffle, - **options, - **kwargs, - ) + return reset_fn(reference_line=refline, num_agents=num_agents, shuffle=shuffle, **options, **kwargs) diff --git a/gym/f110_gym/test/benchmark_renderer.py b/gym/f110_gym/test/benchmark_renderer.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/legacy_scan_gen.py b/tests/legacy_scan_gen.py index 62e24a55..0fe7d58b 100644 --- a/tests/legacy_scan_gen.py +++ b/tests/legacy_scan_gen.py @@ -25,7 +25,11 @@ env = gym.make( "f110_gym:f110-v0", - config={"map": map_name, "num_agents": 1, "params": params,}, + config={ + "map": map_name, + "num_agents": 1, + "params": params, + }, ) scan = np.empty((num_test, 1080)) diff --git a/tests/test_f110_env.py b/tests/test_f110_env.py index fdc8513f..053a2b20 100644 --- a/tests/test_f110_env.py +++ b/tests/test_f110_env.py @@ -17,7 +17,10 @@ def _make_env(self, config={}): } conf = deep_update(conf, config) - env = gym.make("f110_gym:f110-v0", config=conf,) + env = gym.make( + "f110_gym:f110-v0", + config=conf, + ) return env def test_gymnasium_api(self): diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 80f98600..b0eda58a 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -24,7 +24,11 @@ def _make_env(config={}, render_mode=None) -> F110Env: } config = deep_update(base_config, config) - env = gym.make("f110_gym:f110-v0", config=config, render_mode=render_mode,) + env = gym.make( + "f110_gym:f110-v0", + config=config, + render_mode=render_mode, + ) return env diff --git a/tests/test_scan_sim.py b/tests/test_scan_sim.py index d943f458..3dc859ed 100644 --- a/tests/test_scan_sim.py +++ b/tests/test_scan_sim.py @@ -56,7 +56,7 @@ def _test_map_scan(self, map_name: str, debug=False): test_pose = self.test_poses[i] new_scan[i, :] = scan_sim.scan(pose=test_pose, rng=scan_rng) diff = self.sample_scans[map_name] - new_scan - mse = np.mean(diff ** 2) + mse = np.mean(diff**2) if debug: # plotting @@ -69,6 +69,7 @@ def _test_map_scan(self, map_name: str, debug=False): self.assertLess(mse, 2.0) + def test_map_spielberg(self, debug=False): self._test_map_scan("Spielberg", debug=debug)