jhennies / amst

Alignment to Median Smoothed Template for FIB-SEM data
GNU General Public License v3.0
8 stars 2 forks source link

KeyError pyopencl.Context #6

Closed JJConesa closed 1 year ago

JJConesa commented 2 years ago

Good morning, I am having an error when trying to run amst python script. I am using Ubuntu 20.04.3 LTS. This is the pip list of my amst environment:

Package Version


appdirs 1.4.4 backcall 0.2.0 cached-property 1.5.2 certifi 2021.5.30 cloudpickle 2.0.0 cycler 0.11.0 cytoolz 0.11.0 dask 2021.3.0 dataclasses 0.8 decorator 5.1.1 entrypoints 0.4 fabio 0.14.0 h5py 3.1.0 hdf5plugin 3.3.1 imagecodecs-lite 2019.12.3 imageio 2.9.0 ipykernel 5.5.6 ipython 7.16.3 ipython-genutils 0.2.0 jedi 0.17.2 jupyter-client 7.1.2 jupyter-core 4.9.2 kiwisolver 1.3.1 Mako 1.2.0 MarkupSafe 2.0.1 matplotlib 3.3.4 mkl-fft 1.3.0 mkl-random 1.1.1 mkl-service 2.3.0 nest-asyncio 1.5.5 networkx 2.5 numpy 1.19.5 olefile 0.46 packaging 21.3 parso 0.7.1 pexpect 4.8.0 pickleshare 0.7.5 Pillow 8.4.0 pip 21.2.2 platformdirs 2.5.1 prompt-toolkit 3.0.31 ptyprocess 0.7.0 pyelastix 1.2 Pygments 2.13.0 pyopencl 2022.1.6 PyOpenGL 3.1.6 pyparsing 3.0.9 PyQt5 5.15.6 PyQt5-Qt5 5.15.2 PyQt5-sip 12.9.1 python-dateutil 2.8.2 pytools 2022.1.12 PyWavelets 1.1.1 PyYAML 5.4.1 pyzmq 23.2.1 qtconsole 5.2.2 QtPy 2.0.1 scikit-image 0.17.2 scipy 1.5.4 setuptools 58.0.4 silx 1.0.0 six 1.16.0 tifffile 2019.7.26.2 toolz 0.11.2 tornado 6.1 traitlets 4.3.3 typing_extensions 4.1.1 wcwidth 0.2.5 wheel 0.37.1

This is the script I am running, all inputs exist:

Copy this script to a desired location

E.g., if AMST was cloned to /home/user/src/amst make a home/user/src/amst_experiments folder for the execution scripts

import sys

Append the location of the amst package to the system path. Replace by the proper location, e.g. '/home/user/src/amst'

for the example above

sys.path.append('/home/tomo/Software/amst/')

from amst_linux.amst_main import amst_align, default_amst_params

raw_folder = '/home/tomo/RUSKA_MOUNTPOINT//20220729/AMST/raw/' pre_alignment_folder = '/home/tomo/RUSKA_MOUNTPOINT///20220729/AMST/prealigned/' target_folder = '/home/tomo/RUSKA_MOUNTPOINT/*/20220729/AMST/results/'

Load the default parameters

params = default_amst_params() params['n_workers'] = 8 # The default number of CPU cores is 8; set this to the number that is available

params['sift_devicetype'] = 'CPU' #CPU/GPU

Due to the multiprocessing, in Windows, the following has to be inside a name == 'main' block

In Linux it doesn't matter, but it also does no harm

if name == 'main': amst_align( raw_folder=raw_folder, pre_alignment_folder=pre_alignment_folder, target_folder=target_folder, **params )

I tried modifing the sift device type between CPU and GPU (line: params['sift_devicetype'] = 'CPU' ) and also commenting the line with same result.

And this is the error:

Traceback (most recent call last): File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/tools.py", line 100, in wrapper return ctx_dict[cl_object][cache_key] KeyError: <pyopencl.Context at 0x561a25ccf490 on <pyopencl.Device 'NVIDIA GeForce GTX 1080' on 'NVIDIA CUDA' at 0x561a257f6250>>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "amst_script.py", line 10, in from amst_linux.amst_main import amst_align, default_amst_params File "/home/tomo/Software/amst/amst_linux/amst_main.py", line 20, in print('Running SIFT on ' + sift.SiftPlan(shape=(10, 10)).ctx.devices[0].name) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/silx/opencl/sift/plan.py", line 173, in init self._allocate_buffers() File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/silx/opencl/sift/plan.py", line 268, in _allocate_buffers self.cl_mem["255"].fill(255.0) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/array.py", line 1455, in fill self._fill(self, value, queue=queue, wait_for=wait_for)) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/array.py", line 200, in kernel_runner knl = kernel_getter(*args, *kwargs) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/array.py", line 954, in _fill return elementwise.get_fill_kernel(result.context, result.dtype) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/tools.py", line 103, in wrapper result = func(cl_object, args, kwargs) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/elementwise.py", line 714, in get_fill_kernel name="fill") File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/elementwise.py", line 174, in get_elwise_kernel name=name, options=options, kwargs) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/elementwise.py", line 161, in get_elwise_kernel_and_types kernel = getattr(prg, name) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/init.py", line 461, in getattr knl = Kernel(self, attr) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/init.py", line 816, in kernel_init self._setup(prg) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/init.py", line 821, in kernelsetup from pyopencl.invoker import generate_enqueue_and_set_args File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pyopencl/invoker.py", line 310, in key_builder=_NumpyTypesKeyBuilder()) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pytools/persistent_dict.py", line 621, in init _PersistentDictBase.init(self, identifier, key_builder, container_dir) File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/pytools/persistent_dict.py", line 500, in init__ import platformdirs as appdirs File "/home/tomo/Software/miniconda/envs/amst_env/lib/python3.6/site-packages/platformdirs/init.py", line 5 from future import annotations ^ SyntaxError: future feature annotations is not defined

I tried also with the known issues related to GPU but with same result. I also did (you can see in the pip list): conda install -c conda-forge ocl-icd-system conda install -c conda-forge pocl

Hope you can help and thank you in advance.

jhennies commented 1 year ago

This was the fix we worked out:

Reinstalling the environment:

conda create -n amst-env -c conda-forge tifffile scikit-image=0.17.2 vigra silx[full] pyopencl pyelastix

Then, either (for GPU support):

conda activate amst-env conda install -c conda-forge ocl-icd-system

or (for no GPU support):

conda activate amst-env conda install -c conda-forge pocl

Note that Elastix needs to be installed on your system seperately (see https://github.com/jhennies/amst#installation-of-elastix-linux).