Reputation: 116
I am working on a larger simulator (Mocasin) that uses the simpy discrete event simulation framework. The simulator mostly works correctly, but for some larger problems I get an error like this:
Traceback (most recent call last):
File "~/virtualenvs/mocasin/lib/python3.9/site-packages/simpy/core.py", line 190, in step
self._now, _, _, event = heappop(self._queue)
IndexError: index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/virtualenvs/mocasin/lib/python3.9/site-packages/simpy/core.py", line 254, in run
self.step()
File "~/virtualenvs/mocasin/lib/python3.9/site-packages/simpy/core.py", line 192, in step
raise EmptySchedule()
simpy.core.EmptySchedule
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/projects/mocasin/mocasin/mocasin/tasks/__init__.py", line 45, in generate_mapping
generate_mapping(cfg)
File "~/projects/mocasin/mocasin/mocasin/tasks/generate_mapping.py", line 74, in generate_mapping
s.run()
File "~/projects/mocasin/mocasin/mocasin/simulate/__init__.py", line 201, in _run
self.env.run(finished)
File "~/virtualenvs/mocasin/lib/python3.9/site-packages/simpy/core.py", line 260, in run
raise RuntimeError(
RuntimeError: No scheduled events left but "until" event was not triggered: <Process(run) object at 0x7f129039d790>
I am pretty much clueless on what exactly this error message means, but it appears that this is an internal error in simpy. Does anyone have more insights on the conditions that could trigger this error?
I don't know if this error indicates a bug in simpy, or rather in our Mocasin simulator. To investigate this, I tried to find a minimal example that triggers the error, but I haven't been able to find one. It seems that the error is only triggered for very large problems with a huge number of events. This, however, makes it very hard to get to the root cause. Any pointers on how to debug the problem would be very appreciated.
Upvotes: 1
Views: 356
Reputation: 21
I guess this error may have many causes, but I have managed to debug its root cause in my case (which was by no means obvious at the first glance). This has also enabled me to deduct an overall pattern of this error.
In my simulation I use a simpy.Container
, which stores matter in float
format. Sometimes during the simulation I want to fully refill this container using yield container.put(amount)
. Based on my program logic, this operation should not exceed the maximum capacity of the container. However, because the container's attribute .level
(which reflects the current amount of matter in the container) gets altered by float subtractions and divisions (caused by .get()
and put()
calls) numerous times throughout the simulation, the last fractional digits in the .level
attribute may be rounded in such a way that this final .put()
call (which should fully refill the container) will result in exceeding the container's maximum capacity by a minuscule amount. This causes the mentioned error, because your original process does not land in the processed
state, since this inner yield container.put()
event is considered erroneous and does not get executed.
Thus, the overall pattern of the error is: your process schedules some events, which do not get executed during the simulation due to some errors.
Upvotes: 2