Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run the mc.MC() #24

Open
varuncanamedi3301 opened this issue Jun 1, 2024 · 9 comments
Open

Unable to run the mc.MC() #24

varuncanamedi3301 opened this issue Jun 1, 2024 · 9 comments

Comments

@varuncanamedi3301
Copy link

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
Copy link
Owner

xopto commented Jun 3, 2024

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
Copy link

fire9291 commented Jun 5, 2024

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
Copy link

fire9291 commented Jun 5, 2024

I got the same. Have you ever fixed it?

@varuncanamedi3301
Copy link
Author

varuncanamedi3301 commented Jun 5, 2024 via email

@xopto
Copy link
Owner

xopto commented Jun 5, 2024

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
Copy link

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
Copy link
Owner

xopto commented Jun 18, 2024

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.

@Randall531
Copy link

Hello, I still experience the same type-error even after i changed cl_cq_properties = None to cl_cq_properties = 0 when i was trying to run the basic.py file. Anyone still experiences it?

@xopto
Copy link
Owner

xopto commented Oct 15, 2024

On some platforms it now seems that neither None nor 0 works.

In this case, try to modify xopto/mcbase/mcworker.py by using an empty list instead of None or 0 (a sequence of keys and values should be allowed for OpenCL version >= 2.0):
"cl_cq_properties = None" => "cl_cq_properties = []"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants