Reporting Bugs in Flatland

Have you found any BUG in the Flatland environment code or have a request for an essential FEATURE? Please let us know so we can fix and enhance Flatland to become a great multi-agent environment.

According to my understanding, in the RailEnv.step() function, agent positions are not updated synchronuoulsly, but in numerical order. This means that agent 2 can directly follow agent on the track, but agent 1 cannot directly follow agent 2 (because the cell is seen as occupied by agent 2, although this agent is about to move). In my opinion, it would be better to either update positions in a random order, or preferably, temporarily update all the positions and then check for conflicts before confirming.

1 Like

Hi everyone!

I would like to report a bug of Flatland 2.0, connected with stochastic events.

As you can see, a stochastic event occurs with my agent on the first step. Then my agent waits for several steps, sending to the system “4” (or nothing).

However, when this stochastic event ends, something throws the agent out of railway system (or out of a map in my example). You can see that position of the agent is (-1, 2).

Note that this problem occurs in many different cases when an agent waits during stochastic event is ending.

Simulate the bug with following code (just copy to jupyter):

import time
from flatland.envs.observations import TreeObsForRailEnv
from flatland.envs.predictions import ShortestPathPredictorForRailEnv
from flatland.envs.rail_env import RailEnv
from flatland.envs.rail_generators import sparse_rail_generator
from flatland.envs.schedule_generators import sparse_schedule_generator
from flatland.utils.rendertools import RenderTool

stochastic_data = {'prop_malfunction': 1.,  # Percentage of defective agents
                   'malfunction_rate': 70,  # Rate of malfunction occurence
                   'min_duration': 2,  # Minimal duration of malfunction
                   'max_duration': 5  # Max duration of malfunction

speed_ration_map = {1.: 1.,  # Fast passenger train
                    1. / 2.: 0.,  # Fast freight train
                    1. / 3.: 0.,  # Slow commuter train
                    1. / 4.: 0.}  # Slow freight train

env = RailEnv(width=25,
              rail_generator=sparse_rail_generator(num_cities=5,  # Number of cities in map (where train stations are)
                                                   num_intersections=4,  # Number of intersections (no start / target)
                                                   num_trainstations=25,  # Number of possible start/targets on map
                                                   min_node_dist=6,  # Minimal distance of nodes
                                                   node_radius=3,  # Proximity of stations to city center
                                                   num_neighb=3,  # Number of connections to other cities/intersections
                                                   seed=215545,  # Random seed
              stochastic_data=stochastic_data,  # Malfunction data generator

env_renderer = RenderTool(env)
env_renderer.render_env(show=True, frames=False, show_observations=False)
_action = dict()

for step in range(4):
    #_action[0] = 4
    obs, all_rewards, done, info = env.step(_action)
    env_renderer.render_env(show=True, frames=False, show_observations=False)
print("Here position of the agent is invalid")

Thank you for fixing this bug. Hope, it won`t be difficult.

Thanks for reporting. I opened an issue.


I would like to report a bug in the Sparse Rail generator. Very often it happens that trains are placed onto the map with invalid starting orientation as depicted in the attachment. According to the allowed transitions the train cannot move anywhere as it is facing in a direction that should never be allowed on the rail.

I have tried to pre-generate few instances for testing the new algorithm and this problem has been repeatedly occurring with different setups.

Thank you very much for the fix or clarification.

Best Regards,


1 Like

Hi Filip

Thank you for reporting this bug. I am working on improving the sparse railway generator, respectively we might replace this with a new one or we will introduce a new generator.

But the bug has to be fixed anywhy.

To track the bug fix:


Hi Filip

I just merged the latest change into master branch. Can you check if the bug is resolved, do you have a test python script?

kind regards