Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre commit #611

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-docs-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
folder: _build
clean-exclude: |
v*.*/
main
main
2 changes: 1 addition & 1 deletion .github/workflows/manual-build-docs-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ jobs:
folder: _build
clean-exclude: |
v*.*/
main
main
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ dmypy.json

# Cython debug symbols
cython_debug/

36 changes: 31 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-symlinks
- id: destroyed-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-ast
- id: check-added-large-files
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: debug-statements
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args:
- --ignore-words-list=ser,theses,bu,ois
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
args:
- '--per-file-ignores=**/__init__.py:F401,F403,E402'
# - '--per-file-ignores=*/__init__.py:F401'
- --ignore=E203,W503,E741,E731
- --max-complexity=30
- --max-line-length=456
- --show-source
- --statistics
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/python/black
rev: 23.3.0
rev: 24.4.2
hooks:
- id: black
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,3 @@ Master theses
* [Multi-Agent Reinforcement Learning with Application on Traffic Flow Control](https://www.diva-portal.org/smash/get/diva2:1573441/FULLTEXT01.pdf) (Jun 2021)
* [Deep Reinforcement Learning for Automated Parking](https://repositorio-aberto.up.pt/bitstream/10216/136074/2/494682.pdf) (Aug 2021)
* [Deep Reinforcement Learning and Imitation Learning for Autonomous Driving in a Minimalist Environment](https://www.academia.edu/107587654/Deep_Reinforcement_Learning_and_Imitation_Learning_for_Autonomous_Driving_in_a_Minimalist_Environment) (Jun 2021)


2 changes: 1 addition & 1 deletion docs/404.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ hide-toc: true

# 404

## Page Not Found
## Page Not Found
2 changes: 1 addition & 1 deletion docs/bibliography/biblio.bib
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ @misc{Qi2017pointnet
eprint={1612.00593},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
}
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import highway_env # noqa: F401


project = "highway-env"
copyright = "2023 Farama Foundation"
author = "Farama Foundation"
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ bibliography/index

Github <https://github.com/Farama-Foundation/HighwayEnv>
Contribute to the Docs <https://github.com/Farama-Foundation/HighwayEnv/blob/main/docs/README.md>
```
```
24 changes: 12 additions & 12 deletions docs/observations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import gymnasium as gym
import highway_env

env = gym.make(
'highway-v0',
'highway-v0',
config={
"observation": {
"type": "OccupancyGrid",
Expand Down Expand Up @@ -246,10 +246,10 @@ For instance, consider a vehicle at 25m on the right-lane of the ego-vehicle and
```{eval-rst}
.. table:: $15$ m/s

== == == == == == == == == ==
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
== == == == == == == == == ==
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
== == == == == == == == == ==
```

Expand Down Expand Up @@ -288,18 +288,18 @@ The top row corresponds to the left-lane, the middle row corresponds to the lane

The {py:class}`~highway_env.envs.common.observation.LidarObservation` divides the space around the vehicle into angular sectors, and returns an array with one row per angular sector and two columns:
- distance to the nearest collidable object (vehicles or obstacles)
- component of the objects's relative velocity along that direction
- component of the objects's relative velocity along that direction

The angular sector of index 0 corresponds to an angle 0 (east), and then each index/sector increases the angle (south, west, north).
The angular sector of index 0 corresponds to an angle 0 (east), and then each index/sector increases the angle (south, west, north).

For example, for a grid of 8 cells, an obstacle 10 meters away in the south and moving towards the north at 1m/s would lead to the following observation:

```{eval-rst}
.. table:: the Lidar observation
.. table:: the Lidar observation

=== ===
0 0
0 0
0 0
0 0
10 -1
0 0
0 0
Expand All @@ -325,7 +325,7 @@ Here is an example of what the distance grid may look like in the parking env:
"vehicles_count": 3,
})
env.reset()

plt.imshow(env.render())
plt.show()
```
Expand Down
1 change: 1 addition & 0 deletions docs/scripts/move_404.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Provide a path")
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ rewards/index
graphics/index
multi_agent
make_your_own
```
```
3 changes: 2 additions & 1 deletion highway_env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from gymnasium.envs.registration import register

__version__ = "1.10.0"

__version__ = "2.0.0"

try:
from farama_notifications import notifications
Expand Down
2 changes: 2 additions & 0 deletions highway_env/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from highway_env.envs.two_way_env import TwoWayEnv
from highway_env.envs.u_turn_env import UTurnEnv


__all__ = [
"ExitEnv",
"HighwayEnv",
Expand All @@ -28,6 +29,7 @@
"MergeEnv",
"ParkingEnv",
"ParkingEnvActionRepeat",
"ParkingEnvParkedVehicles",
"RacetrackEnv",
"RoundaboutEnv",
"TwoWayEnv",
Expand Down
42 changes: 22 additions & 20 deletions highway_env/envs/common/abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import copy
import os
from typing import Dict, List, Optional, Text, Tuple, TypeVar
from typing import TypeVar

import gymnasium as gym
import numpy as np
Expand All @@ -16,11 +18,11 @@
from highway_env.vehicle.behavior import IDMVehicle
from highway_env.vehicle.kinematics import Vehicle


Observation = TypeVar("Observation")


class AbstractEnv(gym.Env):

"""
A generic environment for various tasks involving a vehicle driving on a road.

Expand All @@ -31,15 +33,15 @@ class AbstractEnv(gym.Env):

observation_type: ObservationType
action_type: ActionType
_record_video_wrapper: Optional[RecordVideo]
_record_video_wrapper: RecordVideo | None
metadata = {
"render_modes": ["human", "rgb_array"],
}

PERCEPTION_DISTANCE = 5.0 * Vehicle.MAX_SPEED
"""The maximum distance of any vehicle present in the observation [m]"""

def __init__(self, config: dict = None, render_mode: Optional[str] = None) -> None:
def __init__(self, config: dict = None, render_mode: str | None = None) -> None:
super().__init__()

# Configuration
Expand Down Expand Up @@ -136,7 +138,7 @@ def _reward(self, action: Action) -> float:
"""
raise NotImplementedError

def _rewards(self, action: Action) -> Dict[Text, float]:
def _rewards(self, action: Action) -> dict[str, float]:
"""
Returns a multi-objective vector of rewards.

Expand Down Expand Up @@ -164,7 +166,7 @@ def _is_truncated(self) -> bool:
"""
raise NotImplementedError

def _info(self, obs: Observation, action: Optional[Action] = None) -> dict:
def _info(self, obs: Observation, action: Action | None = None) -> dict:
"""
Return a dictionary of additional information

Expand All @@ -186,9 +188,9 @@ def _info(self, obs: Observation, action: Optional[Action] = None) -> dict:
def reset(
self,
*,
seed: Optional[int] = None,
options: Optional[dict] = None,
) -> Tuple[Observation, dict]:
seed: int | None = None,
options: dict | None = None,
) -> tuple[Observation, dict]:
"""
Reset the environment to it's initial configuration

Expand Down Expand Up @@ -219,7 +221,7 @@ def _reset(self) -> None:
"""
raise NotImplementedError()

def step(self, action: Action) -> Tuple[Observation, float, bool, bool, dict]:
def step(self, action: Action) -> tuple[Observation, float, bool, bool, dict]:
"""
Perform an action and step the environment dynamics.

Expand Down Expand Up @@ -247,7 +249,7 @@ def step(self, action: Action) -> Tuple[Observation, float, bool, bool, dict]:

return obs, reward, terminated, truncated, info

def _simulate(self, action: Optional[Action] = None) -> None:
def _simulate(self, action: Action | None = None) -> None:
"""Perform several steps of simulation with constant action."""
frames = int(
self.config["simulation_frequency"] // self.config["policy_frequency"]
Expand Down Expand Up @@ -279,7 +281,7 @@ def _simulate(self, action: Optional[Action] = None) -> None:

self.enable_auto_render = False

def render(self) -> Optional[np.ndarray]:
def render(self) -> np.ndarray | None:
"""
Render the environment.

Expand Down Expand Up @@ -317,7 +319,7 @@ def close(self) -> None:
self.viewer.close()
self.viewer = None

def get_available_actions(self) -> List[int]:
def get_available_actions(self) -> list[int]:
return self.action_type.get_available_actions()

def set_record_video_wrapper(self, wrapper: RecordVideo):
Expand All @@ -337,7 +339,7 @@ def _automatic_rendering(self) -> None:
else:
self.render()

def simplify(self) -> "AbstractEnv":
def simplify(self) -> AbstractEnv:
"""
Return a simplified copy of the environment where distant vehicles have been removed from the road.

Expand All @@ -354,7 +356,7 @@ def simplify(self) -> "AbstractEnv":

return state_copy

def change_vehicles(self, vehicle_class_path: str) -> "AbstractEnv":
def change_vehicles(self, vehicle_class_path: str) -> AbstractEnv:
"""
Change the type of all vehicles on the road

Expand All @@ -371,7 +373,7 @@ def change_vehicles(self, vehicle_class_path: str) -> "AbstractEnv":
vehicles[i] = vehicle_class.create_from(v)
return env_copy

def set_preferred_lane(self, preferred_lane: int = None) -> "AbstractEnv":
def set_preferred_lane(self, preferred_lane: int = None) -> AbstractEnv:
env_copy = copy.deepcopy(self)
if preferred_lane:
for v in env_copy.road.vehicles:
Expand All @@ -381,30 +383,30 @@ def set_preferred_lane(self, preferred_lane: int = None) -> "AbstractEnv":
v.LANE_CHANGE_MAX_BRAKING_IMPOSED = 1000
return env_copy

def set_route_at_intersection(self, _to: str) -> "AbstractEnv":
def set_route_at_intersection(self, _to: str) -> AbstractEnv:
env_copy = copy.deepcopy(self)
for v in env_copy.road.vehicles:
if isinstance(v, IDMVehicle):
v.set_route_at_intersection(_to)
return env_copy

def set_vehicle_field(self, args: Tuple[str, object]) -> "AbstractEnv":
def set_vehicle_field(self, args: tuple[str, object]) -> AbstractEnv:
field, value = args
env_copy = copy.deepcopy(self)
for v in env_copy.road.vehicles:
if v is not self.vehicle:
setattr(v, field, value)
return env_copy

def call_vehicle_method(self, args: Tuple[str, Tuple[object]]) -> "AbstractEnv":
def call_vehicle_method(self, args: tuple[str, tuple[object]]) -> AbstractEnv:
method, method_args = args
env_copy = copy.deepcopy(self)
for i, v in enumerate(env_copy.road.vehicles):
if hasattr(v, method):
env_copy.road.vehicles[i] = getattr(v, method)(*method_args)
return env_copy

def randomize_behavior(self) -> "AbstractEnv":
def randomize_behavior(self) -> AbstractEnv:
env_copy = copy.deepcopy(self)
for v in env_copy.road.vehicles:
if isinstance(v, IDMVehicle):
Expand Down
Loading
Loading