eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.57k stars 1.43k forks source link

FatalTraCIError related to getNeighbors() #8358

Open Mikemraz opened 3 years ago

Mikemraz commented 3 years ago

When I was running simulation on self-defined behavior for autonomous vehicles, a fatal error occurred. Below I have attached the messages. This error could occur once in a while without any pattern. I would not say it is very often, but I want to have a grasp of what is going on. Thanks.


FatalTraCIError Traceback (most recent call last)

in 9 courtesy_lvls = [0.5] 10 for courtesy_lvl in courtesy_lvls: ---> 11 experiment(level_of_service,courtesy_strategy,courtesy_lvl,random_seed='10',version='10th',cover_existing_file=True) in experiment(level_of_service, courtesy_strategy, courtesy_lvl, random_seed, version, cover_existing_file) 81 traci.vehicle.setSpeedMode(veh_id,0) 82 traci.vehicle.setLaneChangeMode(veh_id,0) ---> 83 veh.real_behavior_test() 84 traci.simulationStep() 85 traci.close() D:\google drive\research\CCM courtesy\CCM based lane changing\simulation\sumo environment\hypothetical corridor\origin\av_class.py in real_behavior_test(self) 858 has_motivation,direction,_ = self.get_lc_motivation() 859 if not has_motivation: --> 860 has_request, request_veh_id = self.check_request() 861 # it is possible vehicles on one-lane ramp receiving request from other lanes. 862 current_lane_id = traci.vehicle.getLaneID(self.veh_id) D:\google drive\research\CCM courtesy\CCM based lane changing\simulation\sumo environment\hypothetical corridor\origin\av_class.py in check_request(self) 465 def check_request(self): 466 right_has_request, right_request_veh_id, right_delta_x = self.check_request_direction(-1) --> 467 left_has_request, left_request_veh_id, left_delta_x = self.check_request_direction(1) 468 if not right_has_request and not left_has_request: 469 return False, None D:\google drive\research\CCM courtesy\CCM based lane changing\simulation\sumo environment\hypothetical corridor\origin\av_class.py in check_request_direction(self, check_direction) 482 request_veh_id = None 483 delta_x = None --> 484 tl_id, delta_x = self.get_tl_id_and_delta_x(direction=check_direction) 485 if not tl_id: 486 return has_request, request_veh_id, delta_x D:\google drive\research\CCM courtesy\CCM based lane changing\simulation\sumo environment\hypothetical corridor\origin\av_class.py in get_tl_id_and_delta_x(self, direction) 375 elif direction == 1: 376 #tl_info = traci.vehicle.getLeftLeaders(self.veh_id, blockingOnly=False) --> 377 tl_info = traci.vehicle.getNeighbors(self.veh_id, 2) 378 if len(tl_info)>0: 379 tl_id, delta_x = tl_info[0] D:\Sumo\tools\traci\_vehicle.py in getNeighbors(self, vehID, mode) 778 none is returned (in case !LCA_BLOCKED). 779 """ --> 780 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode) 781 782 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): D:\Sumo\tools\traci\domain.py in _getUniversal(self, varID, objectID, format, *values) 166 if self._deprecatedFor: 167 warnings.warn("The domain %s is deprecated, use %s instead." % (self._name, self._deprecatedFor)) --> 168 return _parse(self._retValFunc, varID, self._getCmd(varID, objectID, format, *values)) 169 170 def _getCmd(self, varID, objID, format="", *values): D:\Sumo\tools\traci\domain.py in _getCmd(self, varID, objID, format, *values) 171 if self._connection is None: 172 raise FatalTraCIError("Not connected.") --> 173 r = self._connection._sendCmd(self._cmdGetID, varID, objID, format, *values) 174 r.readLength() 175 response, retVarID = r.read("!BB") D:\Sumo\tools\traci\connection.py in _sendCmd(self, cmdID, varID, objID, format, *values) 178 self._string += struct.pack("!i", len(objID)) + objID.encode("latin1") 179 self._string += packed --> 180 return self._sendExact() 181 182 def _readSubscription(self, result): D:\Sumo\tools\traci\connection.py in _sendExact(self) 88 self._socket.close() 89 del self._socket ---> 90 raise FatalTraCIError("connection closed by SUMO") 91 for command in self._queue: 92 prefix = result.read("!BBB") FatalTraCIError: connection closed by SUMO
behrisch commented 3 years ago

Can you add information about your sumo version and possibly any sumo or sumo-gui error messages?

Mikemraz commented 3 years ago

Hi @behrisch, thanks for responding. I am using the most up-to-date SUMO version 1.8.0 on windows. The error message is what I have attached in my previous post.

Mikemraz commented 3 years ago

And I would like to emphasize that by using the same random seed (which means vehicles are behaving in the exact same way), that error message could magically disappear!

namdre commented 3 years ago

random errors are often caused by parallel code. Are you using multiple threads of execution in your traci script?

Can you please attach all options used to start sumo (either via traci.start or in a loaded .sumocfg)?

Mikemraz commented 3 years ago

@namdre Ha, that could explain. Not threads of execution but multiple python processes for simulations with different random seed is my case. Do you have any thought to work around this?

namdre commented 3 years ago

The first thing to do would be to simplify your setup (i.e. only one process at a time) and check if the error goes away. Another option would be to enable core dumps and try to find out what happened to the sumo process (https://medium.com/@sourabhedake/core-dumps-how-to-enable-them-73856a437711).

How often is "once in a while" for this error? 1 in 10,100,1000 runs?

Mikemraz commented 3 years ago

@namdre I would say it is approximately 1 in 100 runs. And I now remember that this error could occur (less likely, and on a PC with less capable CPU power) even when I run one process at a time. Anyway, this error does not bring me too much trouble practically. Thanks you all for consistent efforts of maintaining this great tool.

namdre commented 3 years ago

If you can manage to put something together that I can run on my end to reproduce the crash then I'm eager to fix this. Even if the error is manageable for you it may show up for others and ruin their day.

Mikemraz commented 3 years ago

@namdre Ha, I would like to do that but I guess I am obliged to not distributing our code before our study gets published. I will do so once our work goes into public. Thanks again!