Radiance model

67 views
Skip to first unread message

Charlotte Constans

unread,
Mar 14, 2023, 5:28:07 PM3/14/23
to mcx-users
Hi Dr. Fang,

Thank you for this great software. I use it to build a radiance model by extracting the trajectories and calculating the angle of arrival for each scattering point, for each photon.
This radiance model is necessary to solve an inverse problem in photoacoustics: in short, the radiance is decomposed in Fourier harmonics and the product of the adjoint coefficients and the forward coefficients gives the gradient (this is well explained in this paper: Forward and Adjoint Radiance Monte Carlo Models for Quantitative Photoacoustic Imaging , Hochuli 2015).

As you can imagine, this method is very inefficient and requires a huge memory (right now I use it only in 2D). I was wondering if there was an other way to retrieve the radiance?

Best regards,

Charlotte

Qianqian Fang

unread,
Mar 15, 2023, 3:27:22 PM3/15/23
to mcx-...@googlegroups.com, Charlotte Constans
hi Charlotte,

thanks for pointing out this paper. I had similar thoughts for a long time, but glad to see this is a viable approach.

currently what you were doing is the only way that can achieve something like this without requiring code changes, but as you mentioned, it is inefficient.

the best way is to modify the source code and directly perform the multiplication of Fourier components (Eqs 9-11 in the cited paper) and storage of the coefficients at the photon-stepping level of mcx.


you will have to

1. add an extra dimension to the output data buffer to store Fourier coefficients
2. accumulating a list of projected Fourier coeffs - instead of a single weight - in a local buffer, and store to the output buffer


if you have a chance to implement this feature, I will be happy to look at it and backport it to the upstream code.


Qianqian
--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mcx-users/f63d7c8b-8a9f-483f-8d3e-801edc1df73an%40googlegroups.com.


Qianqian Fang

unread,
Mar 22, 2023, 10:46:01 PM3/22/23
to Charlotte Constans, mcx-...@googlegroups.com

hi Charlotte,

it has always been a struggle to build cuda programs under windows. a big part of the issue is that nvidia only supports Visual Studio on windows. This makes many common libraries, such as zlib, unnecessarily difficult to install. After pouring days or even weeks of my time to get everything to work on windows as I wanted, I have to say - I hate it a lot ...

nonetheless, we know windows users compose of over 80% of the downloads of mcx, so we have to make it work.

here are a few things that we did manage to make it work

1. first, you can check out our pmcx Python module github action script written for windows

https://github.com/fangq/mcx/blob/master/.github/workflows/build_windows_wheel.yml

the default github action windows runner (pre-configured virtual machines running on github servers) has a bunch of tools preinstalled (see software list), but what we need is mingw64, cmake and VS (if you want to build mex, you need to have matlab and make mex.bat in your PATH)

aside from those, we need the below powershell commands to install cuda and zlib

https://github.com/fangq/mcx/blob/cdabf68ec33b8f277394be374743afe59891e473/.github/workflows/build_windows_wheel.yml#L37-L49

you see that it includes some unzipping, and setting some environment variables.

once this environment is setup, you should be able to download mcx source code, and build everything using cmake command

cd mcx/src
mkdir build && cd build
cmake  ../
make


2. the above github action script was designed for only building Python windows wheels, so it does not produce mcx/mcx.mex. I am currently working on a separate action script to build all the other binary packages - with a hope that it will replace nightly-build in the future. it is not entirely working, but I have most of the tools (octave, matlab, cuda, vs etc) set-up complete, see my current command settings

https://github.com/fangq/mcx/blob/master/.github/workflows/build_all.yml

you can see segments of commands for system set up. I will continue working on this, hopefully will get everything to work - currently Linux can build with no problem, but mac/windows are failing

https://github.com/fangq/mcx/actions/runs/4493734116/jobs/7905319784


3. both of the above two scripts were based on pre-configured github windows vm (runners), for most of our past releases and nightly builds, we have been using one of my windows machines to create binaries, our nightly build script can be found also in our source codes

https://github.com/fangq/mcx/blob/master/deploy/buildmcx.sh

this is a bash script that can run in mingw64 on windows, but some of the paths (cuda, matlab) were hard coded for my machine settings. you can try it, but very likely you will need to update all hard-coded paths. My environment variable settings were also not included in this script.


overall, it can be done, but it is difficult to be streamlined and reproducible (due to different VS/cuda versions, software paths settings on windows are also quite chaotic)

try it, let me know if I can be of further help.


Qianqian


On 3/22/23 10:49, Charlotte Constans wrote:

Hi Dr. Fang,

Thank you for the quick reply. We will definitely try to modify the source codes and add the radiance output but for now we are struggling with the compiling steps.

We are trying to compile the mcx src from Windows 10 using Visual Studio 2017 and MinGW32.
Even after a few tweaks (manually put the folders in some failing include), we don't manage to compile, it seems that the mcx_utils.o doesn't compile:

$ make mex
/usr/bin/sh: line 0: [: too many arguments
cc -std=c99 -g -Wall  -Izmat -Izmat/easylzma -I/usr/local/cuda/include -Iubj -fopenmp -fPIC -DMCX_CONTAINER -DMATLAB_MEX_FILE -c -o mcx_utils.o  mcx_utils.c
process_begin: CreateProcess(NULL, cc -std=c99 -g -Wall -Izmat -Izmat/easylzma -I/usr/local/cuda/include -Iubj -fopenmp -fPIC -DMCX_CONTAINER -DMATLAB_MEX_FILE -c -o mcx_utils.o mcx_utils.c, ...) failed.
make (e=2): Le fichier spÚcifiÚ est introuvable.
make: *** [Makefile:264: mcx_utils.o] Error 2

Eventually, at some point, we got something related to the platform type x86 instead of x64. What do you recommend to do in this case. MingW64 doesn't seem to see the PATH updates from windows...


 We also tried to compile with Visual Studio 2017 but the zlib or zmatlib is having issues with many things undeclared.

So we start being hopeless and your help would be greatly appreciated. For example, a step by step install guide to run the compilation would be helpful (the one on the website doesn't seem up to date).

Thanks a lot for your precious time,

Charlotte




Reply all
Reply to author
Forward
0 new messages