swarmlib icon indicating copy to clipboard operation
swarmlib copied to clipboard

IndexError: index 0 is out of bounds for axis 1 with size 0

Open alberaja opened this issue 1 year ago • 3 comments

I receive this same error trying launching master with: swarm fireflies 14 --function michalewicz --alpha 0.5 --beta 0.2 --gamma 1.0 swarm whales 14 -f michalewicz -n 10 swarm wolves 10 -f=michalewicz

(...) 2023-04-16 17:58:14,875 [INFO ] Current best value: -0.9966775719782092, Overall best value: -1.7399912676909937 2023-04-16 17:58:14,877 [INFO ] Current best value: -1.0013626000092621, Overall best value: -1.7399912676909937 Traceback (most recent call last): File "", line 198, in run_module_as_main File "", line 88, in run_code File "C:\Users\Alberto\AppData\Roaming\Python\Python311\Scripts\swarm.exe_main.py", line 7, in File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\swarmlib_main.py", line 86, in run_swarm algorithm(args) File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\swarmlib\gwo\main.py", line 19, in _run_gwo problem.replay() File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\swarmlib\util\problem_base.py", line 25, in replay self._visualizer.replay() File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\swarmlib\util\base_visualizer.py", line 85, in replay _ = animation.FuncAnimation(self._fig, self._animate, frames=frames, interval=self.__frame_interval, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\animation.py", line 1694, in init super().init(fig, **kwargs) File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\animation.py", line 1416, in init super().init(fig, event_source=event_source, *args, **kwargs) File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\animation.py", line 880, in init self._setup_blit() File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\animation.py", line 1214, in _setup_blit self._init_draw() File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\animation.py", line 1750, in _init_draw self._drawn_artists = self._init_func() ^^^^^^^^^^^^^^^^^ File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\swarmlib\util\base_visualizer.py", line 94, in _init self.__particles.set_offsets([[]]) File "C:\Users\Alberto\AppData\Roaming\Python\Python311\site-packages\matplotlib\collections.py", line 551, in set_offsets (np.asanyarray(self.convert_xunits(offsets[:, 0]), float), ~~~~~~~^^^^^^ IndexError: index 0 is out of bounds for axis 1 with size 0

(...) AttributeError: 'FuncAnimation' object has no attribute '_resize_id'

alberaja avatar Apr 16 '23 16:04 alberaja

Hi @alberaja, thx for your contribution. I've never tested the package with python 3.11. Can you pls try to setup a virtual environment with python 3.9 and install the package there as described in the README.md?

HaaLeo avatar Apr 17 '23 14:04 HaaLeo

Hey, we've encountered similar problem on Python 3.7. We've worked around the problem by editing line 94 in base_visualiser from: self.__particles.set_offset([[]]) to self.__particles.set_offset(np.random.rand(5, 2) * 4. Seems to fix the problem as it is related to offset being empty 2d array.

Best Regards

ivanmilevtues avatar Jan 01 '24 21:01 ivanmilevtues

Hi @ivanmilevtues thx for reporting this possible fix. I hope I find time the next few days to test it and maybe release the fix :)

HaaLeo avatar Jan 03 '24 15:01 HaaLeo