Split-voxel MC (SVMC) paper and software support update

103 views
Skip to first unread message

Fang, Qianqian

unread,
Oct 23, 2020, 7:10:40 PM10/23/20
to mcx-users, mmc-...@googlegroups.com, Shijie Yan

hi everyone,

Just want to let you know that we have a new paper published on BOE describing a hybrid mesh/voxel MC method - called SVMC (split-voxel MC). It specifically addresses certain errors caused by the terraced surfaces in voxel-based MC, including errors next to thin-layer of high-contrast tissues (like CSV) and  incorrect reflection/transmission near a curved surface, as pointed out by several previous publications. See the full story here

    https://www.osapublishing.org/boe/fulltext.cfm?uri=boe-11-11-6262&id=440955

My student Shijie Yan, who has led the development of this code, had just merged the fully tested new feature to our github repository, and this function is now included in our nightly build mcxlab packages. If you are interested in giving this approach a try, please go to the below link and get the latest mcxlab (mcx binary also supports this feature, but requires a hybrid volume binary file per-generated from mcxsvmc.m, we will add demos next)

    http://mcx.space/nightly/

Shijie also added 3 examples to mcxlab, corresponding to the B1/B2/B3 benchmarks in our paper, see mcxlab/examples/demo_svmc_*.m

    https://github.com/fangq/mcx/pull/112/files#diff-5a0eecde060511ff3a1ffc87cb8f6b5f4581fb43f8fe0018a8c35815a07c32db

If you are modeling thin high-contrast curved media, or trying to model reflection/transmission of a curved boundary in mcx, I strongly recommend you to try the svmc-capable mcxlab, at least compare the result with and without svmc. This new method drops the simulation speed by about 50%, but the result is more robust for curved objects, similar to mmc.

let us know if you have any questions regarding this new work

cheers!

Qianqian

asassa01

unread,
Sep 3, 2025, 4:15:58 PM (6 days ago) Sep 3
to mcx-users
Dear Qianqian,

I am not sure if I found a bug, but in  all the demos of the SVMC  (like the demo_cube_sph) if I try to change the pencil source

% pencil beam light source
cfg.srcpos = [30.5 30.5 0];
cfg.srcdir = [0 0 1];

with a planar one (e.g.)

cfg.srcpos = [30.5 30.5 0];
cfg.srcdir = [0 0 1];  
cfg.srctype='planar';
cfg.srcparam1=[5 0 0 0];
cfg.srcparam2=[0 5 0 0];

the code will generate the following error:

error_svmc1.jpg
the reason is that "phi_svmc" is empty array.

if I try to go back to the pencil beam source, I cannot rerun it, and I will get a new error:

error_svmc2.jpg

Not only that, all the other MC codes will not be able to run. The only way to fix this problem is to restart MATLAB.
Thank you.
Angelo

Qianqian Fang

unread,
Sep 3, 2025, 10:13:45 PM (6 days ago) Sep 3
to mcx-...@googlegroups.com, asassa01

hi Angelo,

sorry that I did not get back to your previous email on this.

I tested various source types for the demo_cube_sphere.m example, including planar, cone, disk etc, all of them run without any problem.

I think it might be because of the version you are using. can you verify your mcx version? can you try using the latest version instead? what OS do you use? check out the github action-built packages

https://mcx.space/nightly/github/

Qianqian


>> demo_svmc_cubesph
SVMC preprocessing complete, Elapsed time is 0.086785 seconds.
Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=2072082351;
mcx.issrcfrom0=1;
mcx.srcpos=[61 61 0 1];
mcx.srcdir=[0 0 1 0];
mcx.srctype='planar';
mcx.srcparam1=[5 0 0 0];
mcx.srcparam2=[0 5 0 0];

mcx.medianum=2;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=0.5;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[120 120 120];
mcx.mediabyte=1;
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::b99a33$v2025.6 $Date::2025-06-01 09:06:59 -04$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Kilo-Kelvin] compiled by nvcc [11.5] for CUDA-arch [350] on [Sep  3 2025]
- compiled with: RNG [xorshift128+] seed length [4]

GPU=1 (NVIDIA GeForce RTX 4070 Laptop GPU) threadph=678 extra=24832 np=100000000 nthread=147456 maxgate=10 repetition=1
initializing streams ...    init complete : 2 ms
requesting shared memory: 1280 bytes
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
kernel complete:      3062 ms
retrieving fields ...     transfer complete:    3112 ms
normalizing raw data ...    source 1, normalization factor alpha=0.000000
data normalization complete : 3297 ms
simulated 100000000 photons (100000000) with 147456 threads (repeat x1)
MCX simulation speed: 32916.39 photon/ms
total simulated energy: 100000000.00    absorbed: 21.63050%
(loss due to initial specular reflection is excluded in the total)
Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=2072082351;
mcx.issrcfrom0=1;
mcx.srcpos=[30.5 30.5 0 1];
mcx.srcdir=[0 0 1 0];
mcx.srctype='planar';
mcx.srcparam1=[5 0 0 0];
mcx.srcparam2=[0 5 0 0];

mcx.medianum=2;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=1;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[60 60 60];
mcx.mediabyte=97;
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::b99a33$v2025.6 $Date::2025-06-01 09:06:59 -04$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Kilo-Kelvin] compiled by nvcc [11.5] for CUDA-arch [350] on [Sep  3 2025]
- compiled with: RNG [xorshift128+] seed length [4]

GPU=1 (NVIDIA GeForce RTX 4070 Laptop GPU) threadph=678 extra=24832 np=100000000 nthread=147456 maxgate=10 repetition=1
initializing streams ...    init complete : 0 ms
requesting shared memory: 1280 bytes
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
kernel complete:      3968 ms
retrieving fields ...     transfer complete:    3972 ms
normalizing raw data ...    source 1, normalization factor alpha=0.000000
data normalization complete : 3991 ms
simulated 100000000 photons (100000000) with 147456 threads (repeat x1)
MCX simulation speed: 25342.12 photon/ms
total simulated energy: 100000000.00    absorbed: 22.23949%
(loss due to initial specular reflection is excluded in the total)

On 9/3/25 16:15, asassa01 wrote:

You don't often get email from angelo...@gmail.com. Learn why this is important

Dear Qianqian,

I am not sure if I found a bug, but in  all the demos of the SVMC  (like the demo_cube_sph) if I try to change the pencil source

% pencil beam light source
cfg.srcpos = [30.5 30.5 0];
cfg.srcdir = [0 0 1];
with a planar one (e.g.)
cfg.srcpos = [30.5 30.5 0];
cfg.srcdir = [0 0 1];  
cfg.srctype='planar';
cfg.srcparam1=[5 0 0 0];
cfg.srcparam2=[0 5 0 0];

the code will generate the following error:


the reason is that "phi_svmc" is empty array.

if I try to go back to the pencil beam source, I cannot rerun it, and I will get a new error:



Not only that, all the other MC codes will not be able to run. The only way to fix this problem is to restart MATLAB.
Thank you.
Angelo

On Friday, October 23, 2020 at 7:10:40 PM UTC-4 Fang, Qianqian wrote:

hi everyone,

Just want to let you know that we have a new paper published on BOE describing a hybrid mesh/voxel MC method - called SVMC (split-voxel MC). It specifically addresses certain errors caused by the terraced surfaces in voxel-based MC, including errors next to thin-layer of high-contrast tissues (like CSV) and  incorrect reflection/transmission near a curved surface, as pointed out by several previous publications. See the full story here

    https://www.osapublishing.org/boe/fulltext.cfm?uri=boe-11-11-6262&id=440955

My student Shijie Yan, who has led the development of this code, had just merged the fully tested new feature to our github repository, and this function is now included in our nightly build mcxlab packages. If you are interested in giving this approach a try, please go to the below link and get the latest mcxlab (mcx binary also supports this feature, but requires a hybrid volume binary file per-generated from mcxsvmc.m, we will add demos next)

    http://mcx.space/nightly/

Shijie also added 3 examples to mcxlab, corresponding to the B1/B2/B3 benchmarks in our paper, see mcxlab/examples/demo_svmc_*.m

    https://github.com/fangq/mcx/pull/112/files#diff-5a0eecde060511ff3a1ffc87cb8f6b5f4581fb43f8fe0018a8c35815a07c32db

If you are modeling thin high-contrast curved media, or trying to model reflection/transmission of a curved boundary in mcx, I strongly recommend you to try the svmc-capable mcxlab, at least compare the result with and without svmc. This new method drops the simulation speed by about 50%, but the result is more robust for curved objects, similar to mmc.

let us know if you have any questions regarding this new work

cheers!

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 visit https://groups.google.com/d/msgid/mcx-users/1e6ed510-1a52-4595-92c6-bae04ba81cddn%40googlegroups.com.

asassa01

unread,
Sep 4, 2025, 12:11:51 PM (5 days ago) Sep 4
to mcx-users
Dear Qianqian, thanks and sorry to take your time for these trivial  things.

 I have Windows 11 Pro 64 bytes. I think you are right that I was using an old version of mcxlab.

Therefore today first I went to the link you sent and I downloaded the all-in-one package, (https://mcx.space/nightly/github/mcxlabcl-allinone-github-latest.zip
but none of my codes worked.

Then  I went to the link
https://mcx.space/wiki/?keywords=register&tool=mcx&ref=mcxwiki
selected MCXLAB, then 2025 (Jumbo-Jolt) folder, and downloaded the zipped folder
Now all my codes that do not use svmc work fine .

About the demo_cube_sph, 
unfortunately I still have a problem with the planar source (however at least now MATLAB does not crush)

It seems the error is that the source direction is not unitary, which is not true (I tried also to use the round function)
This is the error I get:

MCXLAB ERROR -6 in unit mcx_utils.c:3736: field 'srcdir' must be a unitary vector
Error: field 'srcdir' must be a unitary vector.

 Thanks for your guidance.
Angelo

asassa01

unread,
Sep 4, 2025, 1:10:31 PM (5 days ago) Sep 4
to mcx-users
Sorry Qianqian,
I don't have anymore the error reported before when I run  demo_cube_sph. I have the same problem as reported yesterday. Once I change the source type to "planar" the code outputs an empty array and all other codes cannot run.
Thank you.
Angelo

asassa01

unread,
Sep 4, 2025, 4:10:56 PM (5 days ago) Sep 4
to mcx-users
Dear Qianqian,
when you have time, can you tell me where my mistake is? Here is the demo_cube_sph. If I run it as it is, there are no problems and the results are those you have published.
If I use the planar source parameters (commented) the output_svmc is an empty array. Moreover, I cannot run any other code because I get the error message "all CUDA-capable devices are busy or unavailable".
Thanks in advance!
Angelo

% clear cfg cfg_svmc;
clear; close all;
addpath('C:\Users\DOITuser\Documents\mcxlab-win-x86_64-v2025\mcxlab\matlab')
%% common MC setup
cfg.nphoton = 1e8;
cfg.seed = randi([1 2^31 - 1], 1, 1); % random seed
cfg.issrcfrom0 = 1;
% pencil beam light source
cfg.srcpos = [30.5 30.5 0];
cfg.srcdir = [0 0 1];
%planar
% cfg.srcpos = [30.5 30.5 0];
% cfg.srcdir=[0 0 1];
% cfg.srctype='planar';
% cfg.srcparam1=[5 0 0 0];
% cfg.srcparam2=[0 5 0 0];
% optical properties
cfg.prop = [0.0 0.0 1.0 1.0 % background (air, void)
0.005 1.0 0.89 1.37]; % spherical inclusion
% time-domain simulation parameters
cfg.tstart = 0;
cfg.tend = 5e-9;
cfg.tstep = 5e-10;
% enable boundary reflection/refraction
cfg.isreflect = 1; % turn off boundary reflection to see matched results between VMC and SVMC
% spatial resolution
cfg.unitinmm = 1;
% output fluence
cfg.outputtype = 'fluence';
% GPU settings
cfg.gpuid = 1;
cfg.autopilot = 1;
%% prepare mcx input volume
dim = 60;
[xi, yi, zi] = ndgrid(0.25:0.5:(dim - 0.25), 0.25:0.5:(dim - 0.25), 0.25:0.5:(dim - 0.25));
dist = (xi - 30.5).^2 + (yi - 30.5).^2 + (zi - 30.5).^2;
mcxvol = zeros(size(xi));
mcxvol(dist < 625) = 1;
cfg_mcx = cfg;
cfg_mcx.vol = uint8(mcxvol);
% finer spatial resolution
cfg_mcx.unitinmm = 0.5;
cfg_mcx.srcpos = cfg_mcx.srcpos / cfg_mcx.unitinmm;
% cfg.srcparam1=cfg.srcparam1/cfg_mcx.unitinmm;
% cfg.srcparam2=cfg.srcparam2/cfg_mcx.unitinmm;
%% prepare svmc input volume
tic;
[xi, yi, zi] = ndgrid(1:dim, 1:dim, 1:dim);
dist = (xi - 30.5).^2 + (yi - 30.5).^2 + (zi - 30.5).^2;
vol2 = zeros(size(xi));
vol2(dist < 625) = 1;
% addpath('../../utils');%commented by AS because I don't have a utils
% folder
svmcvol = mcxsvmc(vol2, 'smoothing', 1); % 1: enable gaussian smoothing 0: otherwise
fprintf('SVMC preprocessing complete, ');
toc;
cfg_svmc = cfg;
cfg_svmc.vol = uint8(svmcvol);
%% run simulations
addpath ../;
output_vmc = mcxlab(cfg_mcx); % conventional vmc
output_svmc = mcxlab(cfg_svmc); % svmc
%% convert time-resolved fluence to CW fluence
phi_vmc = sum(output_vmc.data, 4);
phi_svmc = sum(output_svmc.data, 4);
%% compare CW fluence distributions using contour lines
[yy_svmc, zz_svmc] = ndgrid(0.5:59.5, 0.5:59.5);
[yy_vmc, zz_vmc] = ndgrid(0.25:0.5:59.75, 0.25:0.5:59.75);
figure;
clines = -10:0.5:10;
contourf(yy_svmc, zz_svmc, log10(abs(squeeze(phi_svmc(31, :, :)))), clines, 'linestyle', '-', ...
'linecolor', 'k', 'linewidth', 2, 'DisplayName', 'SVMC');
hold on;
contour(yy_vmc, zz_vmc, log10(abs(squeeze(phi_vmc(61, :, :)))), clines, 'linestyle', '--', ...
'linecolor', 'w', 'linewidth', 2, 'DisplayName', 'VMC');
colorbar('EastOutside');
% plot media boundaries
[xcirc, ycirc] = cylinder([25, 25], 200);
xcirc = xcirc(1, :) + 30.5;
ycirc = ycirc(1, :) + 30.5;
plot(xcirc, ycirc, '--', 'linewidth', 1.5, 'color', [.5 .5 .5], 'HandleVisibility', 'off');
% other plot settings
axis equal;
ylabel('z(mm)');
xlabel('y(mm)');
lg = legend;
set(lg, 'Color', [0.5 0.5 0.5]);
set(lg, 'box', 'on');
set(gca, 'fontsize', 15);

On Wednesday, September 3, 2025 at 10:13:45 PM UTC-4 Qianqian Fang wrote:

Qianqian Fang

unread,
Sep 4, 2025, 11:50:17 PM (5 days ago) Sep 4
to mcx-...@googlegroups.com, asassa01

hi Angelo,

I tested the following two packages on a windows laptop

v2025:

https://mcx.space/nightly/release/v2025/MCXStudio-win64-v2025-installer.exe

and the latest github version:

https://mcx.space/nightly/github/mcxlab-allinone-github-latest.zip


I confirm that v2025 gave the memory misalignment error you on windows.

however, the latest github version runs both pencil beam and the planar source correctly without an error. The system is Windows 11, with an NVIDIA 4070 laptop GPU

see screenshot attached. if you haven't tried the "mcxlab-allinone-github-latest.zip" zip file above, give it a try


Qianqian

svmc_windows_mcx_latest.png

asassa01

unread,
Sep 5, 2025, 8:14:00 AM (4 days ago) Sep 5
to Qianqian Fang, mcx-...@googlegroups.com
Thanks so much!
i will definitely try another time to install that package.
Angelo

asassa01

unread,
Sep 5, 2025, 9:55:11 AM (4 days ago) Sep 5
to Qianqian Fang, mcx-...@googlegroups.com
Dear Qianqian,
sorry to bother you again, but the matlab file "mcxsvm" is nowhere to be found in the following zipped packages

 and

so I am not sure how I am supposed to run those demos of the split voxel method.

Those packages contain the folder "OCTAVE" instead of the folder "MATLAB"  which is found in the package 

Am I missing something?
Thanks in advance.
Angelo

On Thu, Sep 4, 2025 at 11:50 PM Qianqian Fang <q.f...@neu.edu> wrote:

asassa01

unread,
Sep 5, 2025, 10:57:40 AM (4 days ago) Sep 5
to Qianqian Fang, mcx-...@googlegroups.com
I also noticed that in all the three demos on the svmc, there is the following line
addpath('../../utils');
This folder, which also contains the "mcxsvm" script, is not included in the package you suggested (not even in the https://mcx.space/nightly/github/mcxlab-windows-x64-github-latest.zip)  .
 The script is found inside the MATLAB folder  of the version I installed

Therefore I am again at loss of ideas.
Thanks.
Angelo

Qianqian Fang

unread,
Sep 5, 2025, 1:23:16 PM (4 days ago) Sep 5
to mcx-...@googlegroups.com, asassa01

Angelo,

as long as you add the path to all needed functions, the script should run. not all of them are in mcxlab*.zip, which is just meant to provide the mcx mex file as a module in the full suite.

if any of those are missing, you should download it separately, unzip and addpath, until all needed functions are found in matlab.

the needed packages likely include

- mcxlab.m: mcxlab*.zip

- mcxsvmc.m: mcx*.zip under mcx/utils

- varargin2struct/jsonopt: iso2mesh or jsonlab


if you install the windows installer (https://mcx.space/nightly/win64/MCXStudio-nightlybuild-installer.exe), it is supposed to add path to all needed components, but for this particularly nightlybuild copy, I haven't been able to verify if it works.


Qianqian

asassa01

unread,
Sep 5, 2025, 5:18:42 PM (4 days ago) Sep 5
to Qianqian Fang, mcx-...@googlegroups.com
Hi Qianqian,
I don't think is a problem of missing functions. Now I have tried all the possible packages (with or without the folder utils; I have the iso2mesh folde ) and still the problem remains. I can run the "demo_svmc_cubesph" for a pencil beam but not for the planar or slit source.
If I try, it generates empty arrays and I cannot run any other code.
I have also tried two different desktops, one with NVIDIA GeForce RTX 4070 and the other with NVIDIA RTX 2000 Ada generation. Same problem. All other codes work OK.
Thanks anyway for all your patience.
Angelo
Reply all
Reply to author
Forward
0 new messages