Code Monkey home page Code Monkey logo

highwayenv's Introduction

highway-env

build Documentation Status Downloads Codacy Badge GitHub contributors

A collection of environments for autonomous driving and tactical decision-making tasks, developed and maintained by Edouard Leurent.


An episode of one of the environments available in highway-env.

The environments

Highway

env = gymnasium.make("highway-v0")

In this task, the ego-vehicle is driving on a multilane highway populated with other vehicles. The agent's objective is to reach a high speed while avoiding collisions with neighbouring vehicles. Driving on the right side of the road is also rewarded.


The highway-v0 environment.

A faster variant, highway-fast-v0 is also available, with a degraded simulation accuracy to improve speed for large-scale training.

Merge

env = gymnasium.make("merge-v0")

In this task, the ego-vehicle starts on a main highway but soon approaches a road junction with incoming vehicles on the access ramp. The agent's objective is now to maintain a high speed while making room for the vehicles so that they can safely merge in the traffic.


The merge-v0 environment.

Roundabout

env = gymnasium.make("roundabout-v0")

In this task, the ego-vehicle if approaching a roundabout with flowing traffic. It will follow its planned route automatically, but has to handle lane changes and longitudinal control to pass the roundabout as fast as possible while avoiding collisions.


The roundabout-v0 environment.

Parking

env = gymnasium.make("parking-v0")

A goal-conditioned continuous control task in which the ego-vehicle must park in a given space with the appropriate heading.


The parking-v0 environment.

Intersection

env = gymnasium.make("intersection-v0")

An intersection negotiation task with dense traffic.


The intersection-v0 environment.

Racetrack

env = gymnasium.make("racetrack-v0")

A continuous control task involving lane-keeping and obstacle avoidance.


The racetrack-v0 environment.

Examples of agents

Agents solving the highway-env environments are available in the eleurent/rl-agents and DLR-RM/stable-baselines3 repositories.

See the documentation for some examples and notebooks.


The DQN agent solving highway-v0.

This model-free value-based reinforcement learning agent performs Q-learning with function approximation, using a neural network to represent the state-action value function Q.


The DDPG agent solving parking-v0.

This model-free policy-based reinforcement learning agent is optimized directly by gradient ascent. It uses Hindsight Experience Replay to efficiently learn how to solve a goal-conditioned task.


The Value Iteration agent solving highway-v0.

The Value Iteration is only compatible with finite discrete MDPs, so the environment is first approximated by a finite-mdp environment using env.to_finite_mdp(). This simplified state representation describes the nearby traffic in terms of predicted Time-To-Collision (TTC) on each lane of the road. The transition model is simplistic and assumes that each vehicle will keep driving at a constant speed without changing lanes. This model bias can be a source of mistakes.

The agent then performs a Value Iteration to compute the corresponding optimal state-value function.

This agent leverages a transition and reward models to perform a stochastic tree search (Coulom, 2006) of the optimal trajectory. No particular assumption is required on the state representation or transition model.


The MCTS agent solving highway-v0.

Installation

pip install highway-env

Usage

import gymnasium as gym

env = gym.make('highway-v0', render_mode='human')

obs, info = env.reset()
done = truncated = False
while not (done or truncated):
    action = ... # Your agent code here
    obs, reward, done, truncated, info = env.step(action)

Documentation

Read the documentation online.

Development Roadmap

Here is the roadmap for future development work.

Citing

If you use the project in your work, please consider citing it with:

@misc{highway-env,
  author = {Leurent, Edouard},
  title = {An Environment for Autonomous Driving Decision-Making},
  year = {2018},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/eleurent/highway-env}},
}

List of publications & preprints using highway-env (please open a pull request to add missing entries):

PhD theses

Master theses

highwayenv's People

Contributors

amrmkayid avatar araffin avatar ashishrana160796 avatar cisimon7 avatar codacy-badger avatar dongleecsu avatar eleurent avatar freemedom avatar jjshoots avatar kexianshen avatar kohmat avatar liuqianqian-x avatar lorandcheng avatar lucalazzaroni avatar lucasalegre avatar lucasboyer avatar lucasschott avatar m-naumann avatar m-stoll avatar ma-rapp avatar mcflywzx avatar mgoulao avatar mhtb32 avatar mxttak avatar pseudo-rnd-thoughts avatar qgallouedec avatar vinnnyr avatar yuvraj-dhepe avatar zerongxi avatar zyang37 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

highwayenv's Issues

The install of the project

Hello! When i run the command in the terminal , the terminal tell me successfully,but i can't find the project in my computer, how can i do next ? Thanks for your reply!!

Does it supposed to support Python 2.7? Maybe time to dump it...

Among the code, there are many __future__ imports for python 2.7 compatibility and in setup.py, it is listed as a supported version, but there are many lines that use features from python 3.x, among this line in envs/highway_env.py:

config = super().default_config()

Which uses kind of super call python 2.7 doesn't support.

As python 2.7 has passed its end of life, I suggest dumping all unnecessary future imports and make the code working and clean for just python 3.x(preferably 3.6) and above.

p.s: Pycharm IDE helps find many of python 2.7 incompatibilities as warnings.

Can MCTS agent runs in real-time?

Hi Eleurent,

Thank you for the great repo!
The performance of the MCTS agent looks amazing in the last GIF (in this repo's README). And I tried to run the MCTS agent (configs) from rl-agent repo on the highway-v0 task. But it seemed the agent cannot control the vehicle in real-time. The performance was also not as good as in the MCTS GIF.
Are there any further configurations I missed? or the MCTS algorithm itself is hard to run in real-time?

Thanks,
Dong

Converting `highway-v0` to continuous control

Hello! I'd like to know what is the best way to make a version of highway-v0 with continuous controls (steering and acceleration).

Looking at the source code, I reckon that the most straightforward way would be to implement a subclass of HighwayEnv and override its step method. It would then call

self.vehicle.act(
    {"acceleration": action[0] * self.ACCELERATION_RANGE,
    "steering": action[1] * self.STEERING_RANGE}
)

and then self.simulate() with no arguments, bypassing the automatic steering and acceleration presets.

However, I'm not sure how to detect lane changes, which are necessary for calculating the reward. Any help would be appreciated, as there's quite a bit of code to look at.

Great job with the simulations btw!

Google Colab examples not working

Hi!
I was checking your project and decided to start by running the given examples. Unfortunately, I stumbled upon issues in all of them...

In the first two (parking_model_based.ipynb; highway_planning.ipynb), the problem was that the module xdpyinfo! was missing/not found. The output was an error message asking to: Please install xdpyinfo!. I tried pip install and apt-get it but with no success...

The third one (parking_her.ipynb), returns a message stating ModuleNotFoundError: No module named 'tensorflow.contrib'. After reading about it at Tensorflow website, I found out that the module 'tensorflow.contrib' is deprecated and the module that your script is trying to access has either migrated or been deleted.

KeyError: Ellipsis

after installing the package and importing it,

import gym
import highway_env

env = gym.make("highway-v0")

done = False
while not done:
    action = ... # Your agent code here
    obs, reward, done, _ = env.step(action)
    env.render()

I get this error

KeyError: Ellipsis

Pretrained model

Hi eleurent,

Thank you very much for your excellent work. I also noticed that you have another repo "rl-agents" for training agents in this environment. I have set up the DQN agents using your baseline config. However, I cannot generate a policy like your Gif. Could you please help me?

Language: Speed vs Velocity

Velocity is used to denote vector quantities, while speed is scalar.
In this project, velocity is used everywhere, so the wording should be fixed.

Low level control: steer, accel, brake

Hi,
Thank you for the great environments. I have a question about if it is possible to do low-level control in any of the available envs? I just found high-level commands. For example for intersection, it would be great if we can control steer, accel, and brake using RL. Do you have any suggestions for starting point to add this feature? It would be beneficial for RL community too.
Update: It seems parking env has continuous action space.

Ego attention understanding

Hi,

I'm interested to use your ego attention method in your paper with highway env. But I don't know about rl-agent and want to use it in my own PyTorch implementation.
As I understood from your paper:

  • Encoders in fig3 of the paper: first you get the state for the ego-agent and feed it into one MLP (embedding_layer) and the state of other agents into another MLP (others_embedding_layer). The output of this would be some vectors for each agent with the same size.

  • Ego-attention (fig 3): Then you Lk, Lv, Lq that you learn them using GD to generate q0, k0,...,kn, v0,...,vn which are some scalar values. Then you create Q (scalar), K (vector), and V (vector) and use it in eq. 3. The output of this would be a weighted vector with a size similar to V. This is the output of ego-attention box in fig. 2. right?

  • Decoder (fig.2): And this is an MLP net that generates action-value functions in DQN for example.

Are these understandings correct?

And another question: here N is the number of agents in the scene. Where do you handle variable number of agents?

Hello!

Hi, I have some question that if i want to use DQN and DDQN to train the agent in the high_env, which json file should i choose ? I notice that there is a file named "no_dueling.json" in the /scripts/configs/HighwayEnv/agents/DQNAgent, but in the model.py there is not Unknown model type to match with the "no_dueling.json", what should i do ? thanks for you help!

Global path generation

Hi Eleurent! I was wondering if there is way, I can publish waypoints in terms of [x, y, theta] given a start and a goal position

Vehicle count in merge/roundabout env

Hi @eleurent , I'm trying to use the merge/roundabout environment, and it seems that the vehicle count and the number of lanes cannot be set as the same way in highway env as follows:
config.update({
"observation": {
"type": "Kinematics"
},
"lanes_count": 4,
"vehicles_count": 50,
"duration": 40, # [s]
"initial_spacing": 2,
"collision_reward": self.COLLISION_REWARD
})
So can they be changed in merge or roundablut? If yes, how?

By the way, the type built in for merge task and roundabout task is OccupancyGrid, can I change it into Kinematic? Is it still valid?

Looking forward to your replay.

Errors while setting up

Hi Eleurent,

Thanks for the amazing repository.

When I was trying to build the project, I ended up in below errors could you please help me to fix.

  1. install with Python3 br />
    When I try with pip3 install --user git+https://github.com/eleurent/highway-env I am getting the below error and installation is not successful.
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-sir6pe48/matplotlib/
  1. When I try pip install --user git+https://github.com/eleurent/highway-env (which does the installation on Python2.7) installation is successful. However I am not able to import the highway_env
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import highway_env
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kishor/.local/lib/python2.7/site-packages/highway_env/__init__.py", line 2, in <module>
    import highway_env.envs
  File "/home/kishor/.local/lib/python2.7/site-packages/highway_env/envs/__init__.py", line 1, in <module>
    from highway_env.envs.highway_env import *
ImportError: No module named envs.highway_env
>>> 

Thank you.

Error importing highway_env

Hello,

I have tried installing with pip and pip3 as well. Using pip as follows:

pip install --user git+https://github.com/eleurent/highway-env gives following error message

import highway_env
Traceback (most recent call last):
File "", line 1, in
File "/home/marco/.local/lib/python2.7/site-packages/highway_env/init.py", line 2, in
import highway_env.envs
File "/home/marco/.local/lib/python2.7/site-packages/highway_env/envs/init.py", line 1, in
from highway_env.envs.highway_env import *
File "/home/marco/.local/lib/python2.7/site-packages/highway_env/envs/highway_env.py", line 3, in
from highway_env import utils
ImportError: cannot import name utils

if I install using pip3 with the following
pip3 install --user git+https://github.com/eleurent/highway-env I get the following error message

import highway_env
Traceback (most recent call last):
File "", line 1, in
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/init.py", line 2, in
import highway_env.envs
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/envs/init.py", line 1, in
from highway_env.envs.highway_env import *
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/envs/highway_env.py", line 4, in
from highway_env.envs.common.abstract import AbstractEnv
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/envs/common/abstract.py", line 8, in
from highway_env.envs.common.observation import observation_factory
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/envs/common/observation.py", line 7, in
from highway_env.road.lane import AbstractLane
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/road/lane.py", line 5, in
from highway_env.vehicle.kinematics import Vehicle
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/vehicle/kinematics.py", line 9, in
from highway_env.road.road import Road, LaneIndex
File "/home/marco/.local/lib/python3.6/site-packages/highway_env/road/road.py", line 7, in
from highway_env.road.lane import LineType, StraightLane
ImportError: cannot import name 'LineType'

Thank you for the help!

DDPG + HER - ParkingEnv-v0

Hello,

I'm currently checking performance on ParkingEnv of a new HER implementation for stable-baselines (see hill-a/stable-baselines#273) and I was wondering what hyperparameters did you use for that environment?

Especially, how many steps, and what were ddpg hyperparams, her hyperparams (and which implementations)?
I'm also interested in knowing what was the best mean reward achieved in your experiment ;)

Currently, after 1e6 steps, with default hyperparams, normal noise of std 0.15, using 'future" goal selection strategy with k=4, I got a mean reward around 9.
The learned policy looks ok but not as good as your result.

PS: It seems that you are using a deprecated feature of gym, but I can open another issue for that
the warning:

warnings.warn("DEPRECATION WARNING wrapper_config.TimeLimit has been deprecated. 
Replace any calls to `register(tags={'wrapper_config.TimeLimit.max_episode_steps': 200)}`
with `register(max_episode_steps=200)`.
This change was made 2017/1/31 and is included in gym version 0.8.0.
If you are getting many of these warnings, you may need to update switch from universe 0.21.3 to retro (https://github.com/openai/retro)")

Hello, the problem is about the "remap" function

Hi, i look the file named utils.py which the path is highway_env/envs/common/utils.py, in the file, i noticed that define a function named "remap", and in the highway_env.py, the "remap" function is used to caculate the reward , but i can't understand the reward function which in highway_env.py 81 lines, i don't understand why the reward function is this form, maybe it‘s normalization ?I' don't think my idea is right, can you tell me ? Thanks for you reply!

Changes needed for README.md

In vehicle/dynamics.py file, the kinematic model is implanted like this:

v = self.velocity * np.array([np.cos(self.heading), np.sin(self.heading)])
self.position += v * dt
self.heading += self.velocity * np.tan(self.action['steering']) / self.LENGTH * dt
self.velocity += self.action['acceleration'] * dt

This is for the model which is based on rear wheel position, not center of gravity position mentioned in the README file. Maybe that file needs some corrections.

You can find further explanation here.

Possibility of adding pedestrians

Hello,

I there a possibility to add pedestrians in this simulator?

Or is there a possibility to provide support for pedestrians in the near future?

Thank you.

Code in envs/common/observation.py

Thank you for your efforts for this great environment !

I found a small problem in envs/common/observation.py line 244 and 245, the" x ", "y" should be "vx","vy"?

Looking forward to your reply.

Highway environment for DQN agents

Thank you for your efforts for this great environment !

I'm training a DQN agents on highway-v0 environments. I have conducted some experiments based on your setting in rl_agents/highway/DQN_agents for about 1k episodes but still failed to get stable DQN agents. So I wonder how many episodes the training for DQN agents will take under the settings in that directory to achieve great performance similar with what you show in the video. It will help if you can detail your training settings.

In addition, the simulation for each episode is kind of slow for training. So Does there exist some tools to accelerate the simulation if I don't render the environments for faster training.(usually run DQN for 1k episodes will take 1h)

Feature suggestion - Common interface for road objects

As we agree, using objects of type Obstacle isn't meaningful and convenient for goals. Also, the Obstacle class inherits from Vehicle and contains a massive amount of unnecessary overload.

Here is my suggestion for the new interface:

Common properties:

  • position
  • shape (we can stick with rectangular for now)
  • heading_angle (for rotation ability)
  • dimensions (length and width for rectangle, radius for circle)
  • lane
  • road

Common methods:

  • make_on_lane()

Some inherited classes can be Obstacle and Landmark(or Goal).

I suggest refactoring check_collision() method the way that it checks intersections with Landmark instances regardless of the COLLISION_ENABLED property.

Please feel free to add your thoughts to complete the idea.

Scaling to multiple agents

Thanks for creating this easy to use environment for urban scenarios.
I wanted to use this environment for multi agent learning. Currently, single agent learning is supported. Are there any plans for scaling it up for multi agents?

Unreachable code in envs/common

I think this line is unreachable because it comes after an exception raise.

    def set_preferred_lane(self, preferred_lane=None):
        env_copy = copy.deepcopy(self)
        if preferred_lane:
            for v in env_copy.road.vehicles:
                if isinstance(v, IDMVehicle):
                    raise NotImplementedError
                else:
                    raise NotImplementedError
                    # Vehicle with lane preference are also less cautious
                    v.LANE_CHANGE_MAX_BRAKING_IMPOSED = 1000
        return env_copy

Also this is another piece of unreachable code because it comes after return statement:

def set_agent_action_sequence(self, actions):
        """
            Set the sequence of actions chosen by the agent, so that it can be displayed
        :param actions: list of action, following the env's action space specification
        """
        return
        if isinstance(self.env.action_space, Discrete):
            actions = [self.env.ACTIONS[a] for a in actions]
        if len(actions) > 1:
            self.vehicle_trajectory = self.env.vehicle.predict_trajectory(actions,
                                                                          1 / self.env.config["policy_frequency"],
                                                                          1 / 3 / self.env.config["policy_frequency"],
                                                                          1 / self.env.SIMULATION_FREQUENCY)

about the paper

I can not find the paper about this rep by google, can you share the paper with me

highway-v0 simulation speed is slow

Thank you for the great environment !

I'm training the highway-v0 and the fps is 1 which is too slow to see the result in reinforcement learning.

Is there any bottleneck or need change config in the code?

I think it shows same fps, if I turn on the render or not.

-------------edit-------------

I changed SIMULATION_FREQUENCY in abstract.py, and it's much faster.

Is there any problem if i train with SIMULATION_FREQUENCY = 1 (which is same with policy hz) first, and render with SIMULATION_FREQUENCY = 10 ?

merging issue

Ok! Done successfully! Thks!
Aiming at the merging env, do you also use the rl algorithm?And I can see that the host vehicle is in the main lane, I wonder if the method of RL algorithm you did can handle the case where the host vehicle is in the ramp. Before the acceleration lane of ramp is end, the host can merging into the main lane successfully.

Improvement suggestion - Adding action type to config dictionary

The AbstractEnv class' default is discrete action space and actions. Thus, in continuous action environments such as parking-env, a bit of extra work is needed for API user:

    def define_spaces(self):
        super().define_spaces()
        self.action_space = spaces.Box(-1., 1., shape=(2,), dtype=np.float32)

Here, the user should override action_space after it is assigned once before in super().define_spaces().

Again in step() method, the action is passed to _simulate() which expects discrete actions, so one should override step() method to manually pass the action to vehicle.act() and do rest of steps needed in step(), as it is done in ParkingEnv.

Although it is not a big deal with the current size of the project, I think this can decrease code reusability in future, and it may be better to add a config keyword like:

"action": {
    "type": "Continuous"  # or "Discrete"
}

And then do some groundwork in AbstractEnv class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.