LucasAlegre / sumo-rl

Reinforcement Learning environments for Traffic Signal Control with SUMO. Compatible with Gymnasium, PettingZoo, and popular RL libraries.
https://lucasalegre.github.io/sumo-rl
MIT License
746 stars 201 forks source link

Error: Invalid empty condition '' when using actuated signal timing #146

Closed AmirHKiani98 closed 3 months ago

AmirHKiani98 commented 1 year ago

I'm using SUMO to implement a multi-agent reinforcement learning. I have sumo installed on a MacOS Ventura 13.4.1.

Whenever I use the pre-defined nets (that are implementing static traffic lights) everything works fine, but when I change the static traffic lights to actuated ones, everything falls apart after 5 seconds of running the simulation(this amount of time is variable, depending on the the defined minDur for the tlLogic tag in the net file). The error I get in the SUMO gui is following:

Error: Invalid empty condition ''
Quitting (on error).

** I assigned False to --quit-on-end in SumoEnvironment file in order to track and monitor the errors and warnings in the sumo-gui console.

I'd like to know what is wrong with using actuated signal timing in sumo-rl, because whenever I implement RL manually using my own customized TRACI handler it works until the simulation is finished. I'd appreciate any information that you can provide so I can continue using sumo-rl

Best regards, Amir

LucasAlegre commented 1 year ago

Hi,

Why do you need to change the traffic lights to actuated ones in the .net files? sumo-rl creates the traffic light logic used by the RL agent based on the static definition provided in the .net file.

Can you provided the .net file that is giving you the error?

AmirHKiani98 commented 1 year ago

Thanks for your quick response, Lucas.

Actually, the action function that we are going to use is consisted of five parameters, which are min and max green time, yellow time and all red and passage time. These variables are totally different that that of already implemented in sumo-rl package, which led us to writing a new class that customize your package in a way that fits us our needs.

Regarding the error, what I got in the IDE console by TRACI is the following:

Traceback (most recent call last):
  File "/Users/amirhkiani/Documents/Github/FRITS/rl/ql_4x4grid.py", line 73, in <module>
    s, r, done, info = env.step(action=actions)
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/sumo_rl/environment/env.py", line 313, in step
    self._run_steps()
  File "/Users/amirhkiani/Documents/Github/FRITS/rl/SumoEnvCustom.py", line 50, in _run_steps
    self._sumo_step()
  File "/opt/homebrew/lib/python3.11/site-packages/sumo_rl/environment/env.py", line 402, in _sumo_step
    traci.simulationStep()
  File "/opt/homebrew/lib/python3.11/site-packages/traci/main.py", line 199, in simulationStep
    return connection.check().simulationStep(step)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/traci/connection.py", line 366, in simulationStep
    result = self._sendCmd(tc.CMD_SIMSTEP, None, None, "D", step)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/traci/connection.py", line 228, in _sendCmd
    return self._sendExact()
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/traci/connection.py", line 137, in _sendExact
    raise FatalTraCIError("connection closed by SUMO")
traci.exceptions.FatalTraCIError: connection closed by SUMO

I'm not sure if this can actually help, as I believe it's just saying that SUMO has closed the simulation. But the gui shows the following error, which I believe should have something to do with the way that SumoEnvironment class works things out:

Error: Invalid empty condition ''
Quitting (on error).

Thanks for your time and helps in advance.

Very resepectfully, Amir

LucasAlegre commented 1 year ago

Sorry, I have no idea what is causing the error based only on this information. Is changing the static traffic lights to actuated ones the only modification? If so, can you provide the net file?

AmirHKiani98 commented 1 year ago

Lucas, I managed to resolve the error by not using SUMO-RL. However, I think it is beneficiary to use it in my project, as most of the interfaces have been already implemented in this useful library.

May I ask you, how can someone re-implement the _apply_action function if they want to use actuated signal timing where 5 main parameters are used (minimum green time, maximum green time, yellow time, all red time and passage time)? Right now, _apply_action function dynamically set the next phase, wich means it directly change the green phase to the desired one, but what if someone wants to set the max & min green time for the phases?

LucasAlegre commented 1 year ago

Hi @AmirHKiani98, nice that you resolved the error!

Do you want to change the max/min green time but still be able to change the current phase through the step method? Or do you want to make your action space be the value of these 5 parameters but let another algorithm control the current phase? I'm a bit confused on that, but anyway I think you would need to make another version of the TrafficSignal class https://github.com/LucasAlegre/sumo-rl/blob/main/sumo_rl/environment/traffic_signal.py that implements this logic.

AmirHKiani98 commented 1 year ago

Hi Lucas, Thanks for your quick response!

My initial intention was to set these 5 parameters as the action set and every time I get a new action, I set them on the signal traffic controller (traffic light, in simple words) accordingly. I had already used TrafficSignal class as a parent to my implemented class and it seems I have to change the .net file as well and change the type of signal traffic controller (tlLogics) from static to actuated. When I do so, however, I get the error I mentioned in the title of this thread. I will try to manipulate this class on my local machine to see if there is any other way to implement this type of RL model.

Thanks for your help.

LucasAlegre commented 1 year ago

Good luck with your project! Perhaps one of these methods may help: https://sumo.dlr.de/docs/TraCI/Change_Traffic_Lights_State.html#setting_traffic_light_parameters_0x7e