FLAMEGPU / FLAMEGPU2

FLAME GPU 2 is a GPU accelerated agent based modelling framework for CUDA C++ and Python
https://flamegpu.com
MIT License
106 stars 22 forks source link

Agent python codegen error in boids_spatial3D.py #1141

Closed ptheywood closed 1 year ago

ptheywood commented 1 year ago

examples/python_native/boids_spatial3D_wrapped/boids_spatial3D.py is currently erroring during codegen for me, using Python 3.11 and Python 3.10 (not tested others).

Codegen tests all pass, so something in inputdata is causing a problem.

Traceback (most recent call last):
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/../examples/python_native/boids_spatial3D_wrapped/boids_spatial3D.py", line 336, in <module>
    inputdata_translated = pyflamegpu.codegen.translate(inputdata)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/__init__.py", line 43, in translate
    return codegen(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/__init__.py", line 14, in codegen
    CodeGenerator(tree, file=v)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 122, in __init__
    self.dispatch(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 192, in dispatch
    meth(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 569, in _Module
    self.dispatch(stmt)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 192, in dispatch
    meth(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 783, in _FunctionDef
    self.dispatch(t.body)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 189, in dispatch
    self.dispatch(t)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 192, in dispatch
    meth(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 861, in _For
    self.dispatchMessageLoop(t)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 365, in dispatchMessageLoop
    self.dispatch(tree.body)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 189, in dispatch
    self.dispatch(t)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 192, in dispatch
    meth(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 880, in _If
    self.dispatch(t.body)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 189, in dispatch
    self.dispatch(t)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 192, in dispatch
    meth(tree)
  File "/home/ptheywood/code/flamegpu/FLAMEGPU2/build-11.8/lib/Release/python/venv/lib/python3.10/site-packages/pyflamegpu/codegen/codegen.py", line 625, in _Assign
    if hasattr(t.value, "func") and t.value.func.attr == 'at' :
AttributeError: 'Name' object has no attribute 'attr'

It may just be that the guarding is insufficient.

I.e.

if hasattr(t.value, "func") and t.value.func.attr == 'at'

is only checking that t.value.func is valid, not that attr also exists.

if hasattr(t.value, "func") and hasattr(t.value.func, "attr") and t.value.func.attr == 'at'

Would prevent the exception, but not sure what consequences that would have (I'm unfammiliar with codegen internals)