tlambert03 / pycudadecon

Python wrapper for cudaDecon - GPU accelerated 3D deconvolution for microscopy
http://www.talleylambert.com/pycudadecon/
MIT License
59 stars 12 forks source link

pycudadecon error with newer version of cudadecon #64

Closed pr4deepr closed 3 weeks ago

pr4deepr commented 3 weeks ago

HI I've been getting errors with pycudadecon, specifically when I use cudadecon 0.7.0 When using pycudadecon, and if I have cudececon 0.7.0, I run the import:

from pycudadecon import RLContext, TemporaryOTF, rl_decon and I get the error:

AttributeError: function 'camcor_interface_init' not found

However, if I downgrade cudadecon

mamba install -c conda-forge cudadecon==0.6.* it works fine..

ERROR Traceback:

File ~\.conda\envs\napari_lattice\lib\site-packages\lls_core\deconvolution.py:153, in pycuda_decon(image=<class 'numpy.ndarray'> (512, 320, 1024) uint16, otf_path=None, dzdata=0.3, dxdata=0.14499219272808386, dzpsf=0.3, dxpsf=0.14499219272808386, psf=<class 'numpy.ndarray'> (93, 205, 205) float32, num_iter=5, cropping=False, background='auto')
    150 image = pad_image_nearest_multiple(img=image, nearest_multiple=64)
    152 if is_arraylike(psf):
--> 153     from pycudadecon import RLContext, TemporaryOTF, rl_decon
    155     psf = np.squeeze(psf)  # remove unit dimensions
    156     assert psf.ndim == 3, f"PSF needs to be 3D. Got {psf.ndim}"

File ~\.conda\envs\napari_lattice\lib\site-packages\pycudadecon\__init__.py:18
     14     from . import _libwrap as lib
     17 try:
---> 18     from . import _libwrap as lib
     19 except FileNotFoundError as e:
     20     import warnings

File ~\.conda\envs\napari_lattice\lib\site-packages\pycudadecon\_libwrap.py:36
     26     raise FileNotFoundError(
     27         "Unable to find library 'lidbcudaDecon'\n"
     28         "Please try `conda install -c conda-forge cudadecon`."
     29     ) from None
     32 ndarray_uint16 = Annotated[np.ndarray, "uint16"]
     35 @lib.function
---> 36 def camcor_interface_init(  # type: ignore [empty-body]
        lib = <pycudadecon._ctyped.Library object at 0x000001DBB0162AA0>
        np = <module 'numpy' from 'C:\\Users\\Pradeep\\.conda\\envs\\napari_lattice\\lib\\site-packages\\numpy\\__init__.py'>
     37     nx: int, ny: int, nz: int, camparam: np.ndarray
     38 ) -> int:
     39     """Setup for camera corrections."""
     42 @lib.function
     43 def camcor_interface(  # type: ignore [empty-body]
     44     raw_data: ndarray_uint16, nx: int, ny: int, nz: int, result: ndarray_uint16
     45 ) -> int:

File ~\.conda\envs\napari_lattice\lib\site-packages\pycudadecon\_ctyped.py:36, in Library.function(self=<pycudadecon._ctyped.Library object>, func=<function camcor_interface_init>)
     35 def function(self, func: "Callable[P, R]") -> "Callable[P, R]":
---> 36     func_c = getattr(self.lib, func.__name__)
        self.lib = <CDLL 'C:\Users\Pradeep\.conda\envs\napari_lattice\Library\bin\libcudaDecon.dll', handle 7ffa232d0000 at 0x1dbb0162a40>
        func = <function camcor_interface_init at 0x000001DBB016B9A0>
        self = <pycudadecon._ctyped.Library object at 0x000001DBB0162AA0>
     38     sig = signature(func)
     39     func_c.restype = cast_type(sig.return_annotation)

File ~\.conda\envs\napari_lattice\lib\ctypes\__init__.py:387, in CDLL.__getattr__(self=<CDLL 'C:\Users\Pradeep\.conda\envs\napari_latti...brary\bin\libcudaDecon.dll', handle 7ffa232d0000>, name='camcor_interface_init')
    385 if name.startswith('__') and name.endswith('__'):
    386     raise AttributeError(name)
--> 387 func = self.__getitem__(name)
        name = 'camcor_interface_init'
        self = <CDLL 'C:\Users\Pradeep\.conda\envs\napari_lattice\Library\bin\libcudaDecon.dll', handle 7ffa232d0000 at 0x1dbb0162a40>
    388 setattr(self, name, func)
    389 return func

File ~\.conda\envs\napari_lattice\lib\ctypes\__init__.py:392, in CDLL.__getitem__(self=<CDLL 'C:\Users\Pradeep\.conda\envs\napari_latti...brary\bin\libcudaDecon.dll', handle 7ffa232d0000>, name_or_ordinal='camcor_interface_init')
    391 def __getitem__(self, name_or_ordinal):
--> 392     func = self._FuncPtr((name_or_ordinal, self))
        self._FuncPtr = <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>
        (name_or_ordinal, self) = ('camcor_interface_init', <CDLL 'C:\Users\Pradeep\.conda\envs\napari_lattice\Library\bin\libcudaDecon.dll', handle 7ffa232d0000 at 0x1dbb0162a40>)
        name_or_ordinal = 'camcor_interface_init'
        self = <CDLL 'C:\Users\Pradeep\.conda\envs\napari_lattice\Library\bin\libcudaDecon.dll', handle 7ffa232d0000 at 0x1dbb0162a40>
    393     if not isinstance(name_or_ordinal, int):
    394         func.__name__ = name_or_ordinal

AttributeError: function 'camcor_interface_init' not found

Also, when installing pycudadecon via conda, it updgrades numpy to v2, which has been breaking a lot of things for me, I've used the --no-update-deps flag for now to ensure this doesn't happen.

Thanks Pradeep

tlambert03 commented 3 weeks ago

is it safe to assume you're using pycudadecon <0.5? for some reason, the recent push to the feedstock doesn't seem to have sent the build to conda-forge. Try installing from pip for now pip install -U pycudadecon and try again.

In v0.5+ you might get a UserWarning for the camcor stuff, but it shouldn't be an AttributeError anymore.

Also, when installing pycudadecon via conda, it updgrades numpy to v2

this isn't related to the pycudadecon recipe (we don't pin numpy at all), so if you don't want the newest version of numpy, you're probably generally going to have to explicitly state that in whatever you do

pr4deepr commented 3 weeks ago

Thanks @tlambert03 Ahh, good to know, yes, its pycudadecon<0.5. Would pip still install all the pre-compiled libraries for pycudadecon in Windows and Linux.

tlambert03 commented 3 weeks ago

Would pip still install all the pre-compiled libraries for pycudadecon in Windows and Linux.

nope, unfortunately those are only available on conda... so it would be:

conda install cudadecon
pip install pycudadecon

that will be fixed in a day or two once i figure out why the conda forge feedstock didn't push the last build, and then you can go back to conda install pycudadecon

tlambert03 commented 3 weeks ago

conda forge now has v 0.5.1