mikaem / fenicstools

55 stars 36 forks source link

AttributeError: Can't pickle local object 'RandomCircle.__init__.<locals>.<lambda>' #27

Closed alexdiem closed 6 years ago

alexdiem commented 6 years ago

Hi, I have trouble running the LagrangianParicles demo. I setup FEniCS 2018.1 using Docker via

fenicsproject create fenicstools
fenicsproject start fenicstools

and then installed fenicstools within the Docker using

sudo python3 setup.py install

When I run

python3 demo/demo_LagrangianParticles.py

I get

/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:7: UserWarning: Probe/Probes/StatisticsProbe/StatisticsProbes not installed
  warnings.warn("Probe/Probes/StatisticsProbe/StatisticsProbes not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:12: UserWarning: StructuredGrid/ChannelGrid not installed
  warnings.warn("StructuredGrid/ChannelGrid not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:17: UserWarning: weighted_gradient_matrix/compiled_gradient_module not installed
  warnings.warn("weighted_gradient_matrix/compiled_gradient_module not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:22: UserWarning: getMemoryUsage/SetMatrixValue not installed
  warnings.warn("getMemoryUsage/SetMatrixValue not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:27: UserWarning: gauss_divergence/divergence_matrix not installed
  warnings.warn("gauss_divergence/divergence_matrix not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:32: UserWarning: interpolate_nonmatching_mesh/interpolate_nonmatching_mesh_any not installed
  warnings.warn("interpolate_nonmatching_mesh/interpolate_nonmatching_mesh_any not installed")
/usr/local/lib/python3.5/dist-packages/fenicstools/__init__.py:37: UserWarning: DofMapPlotter not installed
  warnings.warn("DofMapPlotter not installed") # Probably missing dependency
Traceback (most recent call last):
  File "demo/demo_LagrangianParticles.py", line 10, in <module>
    particle_positions = RandomCircle([0.5, 0.75], 0.15).generate([100, 100])
  File "/usr/local/lib/python3.5/dist-packages/fenicstools/LagrangianParticles.py", line 474, in generate
    points_inside = comm.bcast(points_inside, root=0)
  File "mpi4py/MPI/Comm.pyx", line 1257, in mpi4py.MPI.Comm.bcast
  File "mpi4py/MPI/msgpickle.pxi", line 629, in mpi4py.MPI.PyMPI_bcast
  File "mpi4py/MPI/msgpickle.pxi", line 104, in mpi4py.MPI.Pickle.dump
  File "mpi4py/MPI/msgpickle.pxi", line 91, in mpi4py.MPI.Pickle.cdumps
AttributeError: Can't pickle local object 'RandomCircle.__init__.<locals>.<lambda>'
Aborted (core dumped)

How can I fix this?

MiroK commented 6 years ago

Hi, could you try on this line to wrap the filter in list. I mean

points_inside = np.array(list(filter(self.rule, points)))
alexdiem commented 6 years ago

Thanks, this fixed that issue, but now I get

Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
--- Instant: compiling ---
Traceback (most recent call last):
  File "demo/demo_LagrangianParticles.py", line 21, in <module>
    lp.scatter(fig)
  File "/usr/local/lib/python3.5/dist-packages/fenicstools/LagrangianParticles.py", line 376, in scatter
    for cwp in p_map.itervalues()
AttributeError: 'CellParticleMap' object has no attribute 'itervalues'
Aborted (core dumped)

If I'm not mistaken this happens because thing.itervalues() was replaced by iter(thing.values()) in Python 3.

MiroK commented 6 years ago

Yes, the Python 3 compatibility is clearly not 100%. For your example, values should already be an iterator so iter is not needed.

alexdiem commented 6 years ago

Ok thank you for your quick responses!