Ocassionally getting "AttributeError: 'NoneType' object has no attribute 'x' " after some ticks
Closed this issue · 2 comments
Hi, me again
In order to build and run a simulation based on walk example, i get the title problem (sometimes not). Something to stand out is that more cores i use, more faster the message appears (tested 1, 2,...5 cores) i believe it's some coordinates conflict or something with some code that i've made (outside abm structure) trying to randomize agent spawn to not depending always on the same seed (code below) and performing a more randomized behaviour in agent move and spawn.
Seed code:
#RANDOM SEED
random_seed = os.urandom(1)
random_fin = int.from_bytes(random_seed,byteorder="little")
with open('mainFinal.yaml') as f:
data = yaml.safe_load(f)
valores = data['random.seed']
if data['random.seed'] == 8:
data['random.seed'] = random_fin
else:
data['random.seed'] = 8
#Guarda el archivo .yaml
with open("mainFinal.yaml", "w") as out:
yaml.dump(data, out)
Note. If i pull out that code i get:
Traceback (most recent call last):
File "mainFinal.py", line 282, in <module>
run(params)
File "mainFinal.py", line 275, in run
model.start()
File "mainFinal.py", line 269, in start
self.runner.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 258, in execute
self.schedule.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 161, in execute
evt()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 32, in __call__
self.evt()
File "mainFinal.py", line 242, in step
roedor.walk()
File "mainFinal.py", line 99, in walk
print(pt.coordinates)
AttributeError: 'NoneType' object has no attribute 'coordinates'
Traceback (most recent call last):
File "mainFinal.py", line 282, in <module>
run(params)
File "mainFinal.py", line 275, in run
model.start()
File "mainFinal.py", line 269, in start
self.runner.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 258, in execute
self.schedule.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 161, in execute
evt()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 32, in __call__
self.evt()
File "mainFinal.py", line 242, in step
roedor.walk()
File "mainFinal.py", line 99, in walk
print(pt.coordinates)
AttributeError: 'NoneType' object has no attribute 'coordinates'
Error NoneType example on tick 29 of 30
Traceback (most recent call last):
File "mainFinal.py", line 282, in <module>
run(params)
File "mainFinal.py", line 275, in run
model.start()
File "mainFinal.py", line 269, in start
self.runner.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 258, in execute
self.schedule.execute()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 161, in execute
evt()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/schedule.py", line 32, in __call__
self.evt()
File "mainFinal.py", line 238, in step
self.context.synchronize(restaurar_agente)
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/context.py", line 294, in synchronize
self._synch_ghosts(restore_agent)
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/context.py", line 258, in _synch_ghosts
proj._synch_ghosts(self._agent_manager, restore_agent)
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/space.py", line 414, in _synch_ghosts
send_data = self._fill_send_data()
File "/home/usuario/.local/lib/python3.8/site-packages/repast4py/space.py", line 378, in _fill_send_data
data_list.append((a.save(), (pt.x, pt.y, pt.z)))
AttributeError: 'NoneType' object has no attribute 'x'
Sorry for the long message and thanks for your time.
Alex
I think the issue is that new agents are being created without their pt
attribute being initialized. So, when pt
is accessed it's None
.
Hi, pt was pt = model.grid.get_location(self)
but
i've found that actually pt
wasn't changing since i've changed
self.grid = space.SharedGrid(name='grid', bounds=box, borders=space.BorderType.Sticky, occupancy=space.OccupancyType.Single, buffer_size=1, comm=comm)
from
self.grid = space.SharedGrid(name='grid', bounds=box, borders=space.BorderType.Sticky, occupancy=space.OccupancyType.Multiple, buffer_size=1, comm=comm)
now everything's fine, thank you very much.