hightower8083 / synchrad

Synchrotron Radiation calculator via openCL
GNU General Public License v3.0
18 stars 11 forks source link

Issue when running example/example_tests.ipynb #15

Closed MaxThevenet closed 2 years ago

MaxThevenet commented 2 years ago

Hi! Is this repo still maintained? I could successfully install SynchRad, but I got the following error in cell 7 of the notebook (all previous cells executed successfully):

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/2b/8zpydy_x75s8h46pfd2x5_jc0000gp/T/ipykernel_37319/3885437814.py in <module>
      1 t0 = time.time()
----> 2 calc.calculate_spectrum(particleTracks, timeStep=dt, 
      3                         comp='total', Np_max=Np, nSnaps=24,
      4                         it_range=[0, particleTracks[0][0].size])
      5 

~/miniconda3/envs/synchrad/lib/python3.9/site-packages/synchrad-0.0.1-py3.9.egg/synchrad/calc.py in calculate_spectrum(self, particleTracks, file_tracks, timeStep, comp, Np_max, nSnaps, it_range, file_spectrum, verbose)
     42 
     43         nSnaps = np.uint32(nSnaps)
---> 44         self._init_raditaion(comp, nSnaps)
     45 
     46         if timeStep is not None:

~/miniconda3/envs/synchrad/lib/python3.9/site-packages/synchrad-0.0.1-py3.9.egg/synchrad/calc.py in _init_raditaion(self, comp, nSnaps)
    291         for vec_comp in vec_comps[comp]:
    292             self.Data['radiation'][vec_comp] = \
--> 293                 arrcl.zeros(self.queue, radiation_shape, dtype=self.dtype)
    294 
    295     def _init_data(self):

AttributeError: 'SynchRad' object has no attribute 'queue'

Please let me know if there is another tool that you use preferably. Thanks!

hightower8083 commented 2 years ago

Hi @MaxThevenet ! Thank you for your interest in syanchrad. This tool is in often use and far-field mapper works well, though I admit the documentation is not in its best shape.

The error you get, mean a problem with openCL context, more specifically it says that selected device (gpu or cpu) in not initialized with a queue. In order to debug this I'll need to know what configuration you use -- is it CPU (pocl or AMD or Intel platforms) or GPU (Nvidia or AMD)? You can comment/remove the calc_input argument

'ctx':[1,]

of the example (its machine specific) and when you run the constructor

calc = SynchRad(calc_input)

it will give you interactive choice of the device. You can also check the available context options by running opencl-print-info.py.

MaxThevenet commented 2 years ago

Thanks for your quick reply! I am running on a 2,3 GHz 8-Core Intel Core i9, removing the ctx argument returns

Running on 1 devices
  Starting without device: 
Platform: None
Compiler: None

and opencl-print-info.py gives

% python ./example/opencl-print-info.py
PyOpenCL version: 2021.2.8
OpenCL header version: 3.0

- Installed platforms (SDKs) and available devices:
Traceback (most recent call last):
  File "/Users/maxence/synchrad/./example/opencl-print-info.py", line 26, in <module>
    platforms = cl.get_platforms()
pyopencl._cl.LogicError: clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR

so I believe I have problems with my openCL installation. Thanks!

MaxThevenet commented 2 years ago

Wow, after a conda uninstall pyopencl and pip install pyopencl I could see my 3 processing units (Intel CPU, Intel GPU, AMD GPU) and successfully execute the notebook on the AMD Radeon GPU. That was super smooth, thanks!

hightower8083 commented 2 years ago

yes, you need to verify of you have a proper installation of openCL and pyopencl. For CPUs the simplest choice is pocl which you can get from conda-forge. After installation check it pyopencl can see it, e.g. run following lines

import pyopencl
pyopencl.create_some_context()

In case of a problem one frequent issue is that

Depending on how it is installed, pyopencl may be looking for pocl.icd file either in system-global /etc/OpenCL/vendors/ or in python folders, e.g. miniconda/etc/OpenCL/vendors/ or mambaforge/etc/OpenCL/vendors/. If its a personal machine you can put this file at all paths, just to be sure =)

BTW: this implementation if not very efficient on CPUs and I mainly use with GPUs. A more performant Fortran implementation for CPUs can be found in chimera code, along with more examples

hightower8083 commented 2 years ago

Great, you've solved issues faster than i've written the response =)

Let me know if you are going to use the tool -- there are some utilities which are very useful in working with simulation results but they are not very documented.. You can see them by punching Tab for after-completion after calc.. It's also useful to save completed simulation to a file calc.calculate_spectrum(file_spectrum='./spectrum.h5') and after you'll be able to load it by pass as an argument to calc = SynchRad(file_spectrum='./spectrum.h5') instead of the calc_input dict