ptycho / ptypy

Ptypy - main repository
Other
36 stars 16 forks source link

DMGpu engine doesn't work with 'nearfield' propagtion #165

Closed carlosesreis closed 3 years ago

carlosesreis commented 6 years ago

Hi guys. First of all thanks for the software! We have been using it with GPUs and it goes really well. We were trying to use DMGpu engine in a nearfield setup but it is dropping us the following error message:

Traceback (most recent call last):
  File "ptypyMinRec.py", line 91, in <module>
    P = Ptycho(pars=param_tree, level=5)
  File "/home/carlos/anaconda2/envs/ptypy_gpu_cuda_merged/lib/python2.7/site-packages/Python_Ptychography_toolbox-0.2.0-py2.7-linux-x86_64.egg/ptypy/core/ptycho.py", line 332, in __init__
    self.run()
  File "/home/carlos/anaconda2/envs/ptypy_gpu_cuda_merged/lib/python2.7/site-packages/Python_Ptychography_toolbox-0.2.0-py2.7-linux-x86_64.egg/ptypy/core/ptycho.py", line 655, in run
    self.run(engine=engine)
  File "/home/carlos/anaconda2/envs/ptypy_gpu_cuda_merged/lib/python2.7/site-packages/Python_Ptychography_toolbox-0.2.0-py2.7-linux-x86_64.egg/ptypy/core/ptycho.py", line 609, in run
    engine.iterate()
  File "/home/carlos/anaconda2/envs/ptypy_gpu_cuda_merged/lib/python2.7/site-packages/Python_Ptychography_toolbox-0.2.0-py2.7-linux-x86_64.egg/ptypy/engines/base.py", line 194, in iterate
    self.error = self.engine_iterate(niter_contiguous)
  File "/home/carlos/anaconda2/envs/ptypy_gpu_cuda_merged/lib/python2.7/site-packages/Python_Ptychography_toolbox-0.2.0-py2.7-linux-x86_64.egg/ptypy/engines/DM_gpu.py", line 155, in engine_iterate
    pre_fft = self.propagator[dID].pre_fft
AttributeError: 'BasicNearfieldPropagator' object has no attribute 'pre_fft'

Using the farfield option with yours rspa usafe dataset all works fine. Could you please help us with this issue?

Thanks, Carlos

aaron-parsons commented 6 years ago

Hi Carlos,

In this initial unsupported branch of the code, the nearfield side hasn't yet been implemented. The cuda is there, but the dots aren't joined up yet. The supported branch of the release_candidate that @bjoernenders is about to release obviously doesn't have GPU support, but the following release which we are working on will do.This will have comprehensive support for all ptypy operation modes.

Whilst I'd love to hack something for you to use right now, I think probably the best thing is for me to get it to work properly in for the next release, and let you know when we have something halfway stable which you can start using to test it.

I hope thats ok.

Aaron

jcesardasilva commented 3 years ago

Any news on this issue? I have the same problem. I've noticed some work on this branch, and I am wondering what I can do to help. PyCUDA is already working for Farfield propagation, but not for Nearfield propagation because it complains that the BasicNearFieldPropagator object does not have the attribute 'pre_fft'. However, it does have this attribute, but I could not understand why it does not use it. Any plan to solve this in the near future? It would help us a lot if we can make run NF ptycho with CUDA.

Otherwise, any hints about how to fix it? In such a way, I can try to help you guys.

jcesardasilva commented 3 years ago

The funny thing is that it is working with the template ptypy_i13_AuStar_farfield_9p0keV.py if we add p.frames_per_block=40 and:

p.engines.engine00.name = 'DM_pycuda'
p.engines.engine00.numiter = 100
p.engines.engine00.numiter_contiguous = 10

which means that something goes wrong with real datasets.

Any hints, please?

bjoernenders commented 3 years ago

That is farfield propagation there. The nearfield propagation is not implemented (yet).

jcesardasilva commented 3 years ago

Hi @bjoernenders, thank you for your prompt reply and sorry about the mistyping. I meant ptypy_i13_AuStar_nearfield_9p7keV.py instead and it worked indeed with the nearfield propagation. Just need to implement the few changes I mentioned above.

This is really intriguing and surprising. If nearfield propagation is not implemented, do you have any idea why it worked with this template? I am really curious to understand this.

bjoernenders commented 3 years ago

There is a range of Fresnel number where both propagators should be able to do the job. I looked a the template and it seems like the Farfieldpropagator is used for reconstruction.

jcesardasilva commented 3 years ago

Thank you @bjoernenders for your reactivity to check this out. And thank you too for having started working on the new branch pycuda_nf.