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 · 13 comments
Open

Unable to run the mc.MC() #24

varuncanamedi3301 opened this issue Jun 1, 2024 · 13 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 = []"

@Randall531
Copy link

Randall531 commented Oct 16, 2024

I have tried to change and it doesnt seem to work. I have also tried changing the other = None to = [] however, still receive the same error.

TypeError: init(): incompatible function arguments. The following argument types are supported:
1. init(self, context: pyopencl._cl.Context, device: typing.Optional[pyopencl._cl.Device] = None, properties: object = 0) -> None

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

Not sure whats the reason

@xopto
Copy link
Owner

xopto commented Oct 16, 2024

The error report implies that the cl_cq_properties argument (properties) is still set to None (not to 0 or []):
Invoked with types: pyopencl._cl.CommandQueue, pyopencl._cl.Context, kwargs = { properties: NoneType }.

Is it possible that there are two pyxopto packages in the python path and you are editing the mcworker.py of the one that is not being used?

What is the full error report? Is the error originating from line 195 or line 199 of the mcworker.py module?
If the error originates from line 195 (not the usual line 199) try to force properties argument to 0 or []:
"self._cl_context = cl.Context(self._cl_devices)" => "self._cl_context = cl.Context(self._cl_devices, properties=0)"

@Randall531
Copy link

Yes you are right, I found another pyxopto package being used in my venv folder. I edited =None to =[] and it has worked! Thank you

@lpattelli
Copy link

Hi all,
just writing to say that I also encountered the same problem in a recent pyxopto installation.
Changing cl_cq_properties = None to cl_cq_properties = 0 in this line of mcbase/mcworker.py fixed the issue also for me, as previously suggested in this thread.

Perhaps the code can be updated initializing cl_cq_properties with either 0 or [], and the issue can be closed?

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

5 participants