xopto / pyxopto

PyXOpto is a collection of python tools for performing Monte Carlo simulations of light propagation in turbid media.
GNU General Public License v3.0
30 stars 8 forks source link

Unable to run the mc.MC() #24

Open varuncanamedi3301 opened 3 weeks ago

varuncanamedi3301 commented 3 weeks ago

Traceback (most recent call last): File "/content/pyxopto-master/examples/mcvox/voxelized_vessel.py", line 134, in mc_obj = mc.Mc( File "/usr/local/lib/python3.10/dist-packages/pyxopto-0.2.3-py3.10.egg/xopto/mcvox/mc.py", line 350, in init super().init(types=types, options=options, cl_devices=cl_devices, File "/usr/local/lib/python3.10/dist-packages/pyxopto-0.2.3-py3.10.egg/xopto/mcbase/mcworker.py", line 1214, in init super().init(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/pyxopto-0.2.3-py3.10.egg/xopto/mcbase/mcworker.py", line 198, in init self._cl_queue = cl.CommandQueue( TypeError: init(): incompatible function arguments. The following argument types are supported:

  1. init(self, context: pyopencl._cl.Context, device: Optional[pyopencl._cl.Device] = None, properties: object = 0) -> None

Invoked with types: pyopencl._cl.CommandQueue, pyopencl._cl.Context, kwargs = { properties: NoneType }

I get this error everytime I run the example codes. Please help !

xopto commented 3 weeks ago

The error report is strange since the arguments match the required types. Is it possible that there are two pyopencl libraries in the system path and the used pyopencl module is loading the wrong shared library? (1) Try to import the clinfo utility "from xopto.cl import clinfo" and run "clinfo()". This will output all the available OpenCL devices and their capabilities. (2) Try to run the example code from pyopencl documentation (https://documen.tician.de/pyopencl/) and see if it works.

fire9291 commented 3 weeks ago

The error report is strange since the arguments match the required types. Is it possible that there are two pyopencl libraries in the system path and the used pyopencl module is loading the wrong shared library? (1) Try to import the clinfo utility "from xopto.cl import clinfo" and run "clinfo()". This will output all the available OpenCL devices and their capabilities. (2) Try to run the example code from pyopencl documentation (https://documen.tician.de/pyopencl/) and see if it works.

I got the same Err. Example codes can not be run correctly. When run clinfo.info() it returns: Platform name: NVIDIA CUDA Platform profile: FULL_PROFILE Platform vendor: NVIDIA Corporation Platform version: OpenCL 1.2 CUDA 10.1.104

Device name: GeForce GT 730
Device type: ALL | GPU
Device available: Yes
Device maximum clock frequency: 901 MHz
Device default address space: 64 bit
    ......
fire9291 commented 3 weeks ago

I got the same. Have you ever fixed it?

varuncanamedi3301 commented 3 weeks ago

Yes, I did fix it somehow. In line 198 of the mcbase.py file

self._cl_queue = cl.CommandQueue( self._cl_context, properties=cl_cq_properties)

change cl_cq_properties=0. I don't know why it works but it works.

On Wed, 5 Jun, 2024, 9:57 am fire9291, @.***> wrote:

I got the same. Have you ever fixed it?

— Reply to this email directly, view it on GitHub https://github.com/xopto/pyxopto/issues/24#issuecomment-2148830210, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMOHEUOTQUTDQSIBB4L2FLZF2HTHAVCNFSM6AAAAABIT77NCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBYHAZTAMRRGA . You are receiving this because you authored the thread.Message ID: @.***>

xopto commented 3 weeks ago

It seems that on some platforms the properties argument of the CommandQueue does not take a None value (even though it is documented to allow None or 0 => https://documen.tician.de/pyopencl/runtime_queue.html#pyopencl.CommandQueue).

For those who observe the error, a temporary fix is to force 0 instead of None by modifying xopto/mcbase/mcworker.py file: "cl_cq_properties = None" => "cl_cq_properties = 0" This change should have no side effects.

fire9291 commented 1 week ago

It realy works! Thanks a lot.

Another question is how can I adjust the ligtht source. I want a focused Guassian Beam with focus in tissue, rather than a collimated one. I believe this can be achieved. Many thanks!

xopto commented 1 week ago

A true Gaussian beam can be modeled only if the wave nature of light is considered (which the MC method does not). However, there are approximations that one can use. A couple of suggestions:

  1. Use a collimated Gaussian beam and transform the initial propagation direction by an ideal thin lens. This will give a perfect focus spot at the focal point of the lens. Depending on the refractive indices of the tissue and surrounding medium, a refraction and packet weight reduction should be calculated at the tissue boundary.

  2. Model the focusing of a Gaussian beam with a cropped cone (consider the radius of the two round surfaces as sigma, the smaller one is located in the focus/tissue and the larger one on the tissue surface or above the surface). To launch a packet, randomly sample one point from the large round surface and one point from the smaller round surface. Connect the two points to obtain the initial propagation direction of the packet and compute the intersection with the tissue surface if launching from above the surface. The random sampling at the two surfaces is essentially the same as for the collimated Gaussian beam but with different sigmas. Depending on the refractive indices of the tissue and surrounding medium, a refraction and packet weight reduction should be calculated at the tissue boundary.

Note that both suggestions require a new source with custom OpenCL code. In both cases, a good starting point would be the already implemented collimated Gaussian beam source.