GGEMS / ggems

GGEMS - Advanced Monte Carlo simulation platform using the OpenCL
GNU General Public License v3.0
34 stars 14 forks source link

Use python setuptools. #16

Closed Yao1993 closed 2 years ago

Yao1993 commented 2 years ago

I just want to use python setup install to compile and install.

didierbenoit commented 2 years ago

Hello Yao, Thank you for this installation tool. I'm doing some tests checking if everything works on Windows and Linux. Could you send me few lines about this tool ? (How to use it, I have no experience with python setuptools) I will commit your code when I'm done testing. kind regards Didier

Yao1993 commented 2 years ago

I have made a fix for Windows and use following codes to test.

# Create a new python environment
conda create -n ggems_test python=3.9 -y
conda activate ggems_test

git clone https://github.com/Yao1993/ggems.git
cd ggems
git swtich yao

# Build and install ggems
python setup.py install

# Test 
python examples/0_Cross_Sections/cross_sections.py -m Air -p Compton -e 0.05
Yao1993 commented 2 years ago

I also edit the cpp code. The member variable number_of_voxels_ is uninitialized in GGEMSSolid. However, the destructor function GGEMSSolid::~GGEMSSolid use the value of number_of_voxels_ to deallocate label_data_ and solid_data_. https://github.com/GGEMS/ggems/blob/bddf3ecf729936fd579d99f197326d3580252f34/src/geometries/GGEMSSolid.cc#L105

I found this problem when deconstructing GGEMSCTSystem.

didierbenoit commented 2 years ago

Hi Yao, I did a quick test, it seems to work fine. Just a few remarks:

Thanks for the bug concerning the initialization of the variable number_of_voxels_

Yao1993 commented 2 years ago

I add options for OpenGL and cmake generators.

# Build ggems with custom options
python setup.py build_ext --generator=Ninja --opengl=ON
# Then install it
python setup.py install
didierbenoit commented 2 years ago

Hi Yao, I did some tests using the latest version of your install script, it works fine, but I have a problem regarding OpenGL on Windows. I use the command python setup.py build_ext --generator=Ninja --opengl=ON --examples=ON then python setup.py install --user. But when I run the 6_Visualization example I get the following error:

Traceback (most recent call last): File "", line 1, in File "C:\Users\dbenoit\AppData\Roaming\Python\Python310\site-packages\ggems-1.2-py3.10-win-amd64.egg\ggems\ggems_opengl.py", line 25, in init ggems_lib.get_instance_ggems_opengl_manager.restype=ctypes.c_void_p File "C:\Program Files\Python310\lib\ctypes__init.py", line 387, in getattr func = self.getitem(name) File "C:\Program Files\Python310\lib\ctypes\init.py", line 392, in getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'get_instance_ggems_opengl_manager' not found

Have you encountered this error before?

Also is it normal that during installation setuptools recompiles the entire GGEMS library?

Yao1993 commented 2 years ago

@didierbenoit Sorry, I made a mistake when installing ggems with opitons.

python setup.py build_ext --generator=Ninja --opengl=ON --examples=ON
# ggems will be compiled and installed with default options.
python setup.py install --user

The right solution is making setuptool execute build_ext first and then install in one command.

 python .\setup.py build_ext --opengl=ON install

image