clij / clij2-fft

20 stars 6 forks source link

Minimal python installation #14

Closed bnorthan closed 3 years ago

bnorthan commented 3 years ago

Hi @haesleinhuepf

I created a means to call the clij2 c library from python, to set up the Richardson Lucy call, and to install on a local machine (not meant to be distributed with PyPI or anything, at least not yet).

Let me know if you have any thoughts or suggestions. I'll probably merge this in a couple of days if no one has any objections, it should not affect any of the java part.

haesleinhuepf commented 3 years ago

Hey Brian @bnorthan ,

wow, is this a cpython wrapper? That looks amazing! Will it also work in a similar way from Linux?

Let me just CC @StRigaud because he and I were looking for a way to call a c++ library from Java and from Python in a simple way. It appears you found a very cool way! Thanks so much for this PR :-)

Cheers, Robert

bnorthan commented 3 years ago

Hi @haesleinhuepf

This should work with Linux and Mac as well. You just need to add some logic to detect the operating system and form the correct library name (ie .dll vs .so) in Windows and Linux.

For the Python wrapper I followed a cuda example from here

For this case I needed to load the library, define a 3D contiguous array type, and set the arg types see here

It uses ctypes, and I am sure there is all kinds of functionality in there to handle various argument types and such.

On the Java side I use javacpp

I needed to create a wrapper class and add a plugin to the pom

It's a bit of a chore to set it all up, but now we should be able to call the same c .dll from both java and python.

After that there will be a second problem I will be thinking about. To get a functional deconvolution library there is a lot of pre-processing code (extending image, pre-conditioning the PSF, etc) which we've already written in java.

What is the best strategy to avoid rewriting this code for both Fiji and Napari? I'm not sure. I know you can call imagej from cpython easily but what about the other way? cpython from fiji? Is it worth it to try and write once for Napari and Fiji? Or are yhou better off just writing it twice and avoiding fancy inter-language communication?

haesleinhuepf commented 3 years ago

What is the best strategy to avoid rewriting this code for both Fiji and Napari?

Our strategy (with @StRigaud) is to move Java-CLIJ-stuff step by step to C++ CLIc and write (or partly auto-generate) wrappers for Java and Python. See also the CLesperanto roadmap. It's quite some work but I believe the only right way to move forward without code duplication.