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

Report files missing when using MCR Linux CAT12 version #27

Open
jhuguetn opened this issue Jun 3, 2024 · 11 comments
Open

Report files missing when using MCR Linux CAT12 version #27

jhuguetn opened this issue Jun 3, 2024 · 11 comments

Comments

@jhuguetn
Copy link

jhuguetn commented Jun 3, 2024

At running the Segmentation module from the latest standalone release (12.9 r2556, see CAT12.9_R2017b_MCR_Linux.zip), CAT12 complains about missing some of the QC report output files. See trace below:

> cat_standalone.sh -b /opt/spm/standalone/cat_standalone_segment.m /data/sub-1_ses-01_T1w.nii.gz
...

  Remove "/data/report/catreport_sub-1_ses-01_T1w.pdf" from dependency list because it does not exist!
One or multiple files do not exist and were removed from the dependency list
and following batches will may not work correctly!

  Remove "/data/report/catreportj_sub-1_ses-01_T1w.jpg" from dependency list because it does not exist!
One or multiple files do not exist and were removed from the dependency list
and following batches will may not work correctly!

03-Jun-2024 08:12:35 - Done    'CAT12: Segmentation'
03-Jun-2024 08:12:35 - Done

Bye for now...

Any ideas of what might be going on?

@psadil
Copy link

psadil commented Jul 23, 2024

I'm noticing the same issue (with a different container). Would be happy to dig into this, but do you have any recommendations about troubleshooting? For example, is there a "verbose" option that could lead to a more helpful error log?

@psadil
Copy link

psadil commented Aug 14, 2024

Bumping in case there are any ideas. For what it's worth, using MATLAB 2024a (Update 5), I can compile a standalone version of CAT v12.9 that runs and produces the report outside of a container, but when it is run inside the container the pdf is not produced (as reported above, there are no errors except for the message about a lack of pdf and jpg outputs). Any help troubleshooting would be appreciated.

@psadil
Copy link

psadil commented Aug 15, 2024

Some progress: the issue is around here

cat12/cat_main_reportfig.m

Lines 1608 to 1625 in 57ca3e8

hSD{1}{1} = cat_surf_renderv(CS ,[],struct('view',sview{1},'mat',spm_imatrix(res.Affine),'h',hCS{1},'interp',interp));
cat_surf_renderv(CSl,[],struct('view',sview{2},'mat',spm_imatrix(res.Affine),'h',hCS{2},'interp',interp*0.9));
cat_surf_renderv(CSr,[],struct('view',sview{3},'mat',spm_imatrix(res.Affine),'h',hCS{3},'interp',interp*0.9));
cat_surf_renderv(CSl,[],struct('view',sview{4},'mat',spm_imatrix(res.Affine),'h',hCS{4},'interp',interp*0.9));
cat_surf_renderv(CSr,[],struct('view',sview{5},'mat',spm_imatrix(res.Affine),'h',hCS{5},'interp',interp*0.9));
catch
cat_io_cprintf('err','Error in non OpenGL surface rendering.\n');
end
end
%% To do: filter thickness values on the surface ...
% sometimes hSD is not defined here because of mysterious errors on windows systems
if ~exist('hSD','var'), return; end
if ~isfield(hSD{1}{1},'cdata'), return; end

Inside the containers, the renderer is painter, and so hSD is created by cat_surf_renderv. The output of cat_surf_renderv only has the field cdata according to these rules:

cat12/cat_surf_renderv.m

Lines 276 to 288 in 57ca3e8

% set output
if ~isempty( opt.h ) && opt.h > 1
image( opt.h , img );
axis(opt.h,'equal','off');
varargout{1}.h = opt.h;
varargout{1}.cdata = facevertexcdata;
else
image( img );
axis('equal','off');
varargout{1} = img;
end
end
.

In the containers that I'm testing, opt.h is an

Axes with properties

XLim: [0 1]
YLim: [0 1]
XScale: 'Linear'
YScale: 'Linear'
GridLineStyle: '-'
Position: [0.6800 0.1800 0.3000 0.1700]
Units: 'normalized'

Since axes > 1 always evaluates to 0, the cdata field is never assigned, and so cat_main_reportfig returns before writing the pdf and jpg.

@psadil
Copy link

psadil commented Aug 15, 2024

Also, the check for opt.h > 1 was introduced between the last two releases (c4d6a67#diff-17b3a61bcf5582e69cfa6c633f51d5329d8af72c0ad1f17ee3e90f7332699c2c), which explains why this was an issue for jhuguetn/cat12: r2556 but not jhuguetn/cat12: r2166

@jhuguetn
Copy link
Author

Hi @psadil, sorry for the long hiatus in responding.

I am glad you have put some work/willingness on trying to fix this problem, it's a blocking issue for us so we are still using an older working release. To be honest I haven't done much since I posted the issue and I am afraid I cannot help much debugging the code, my expertise in MATLAB is rather limited.

That said, I find it very interesting and does make sense that only container executions are somehow affected but I cannot see how the finding you posted above on opt.h would only affect container-based executions of CAT12. Do you have a fix proposal or an explanation of why could this issue be occurring?

@psadil
Copy link

psadil commented Aug 16, 2024

It's a blocking issue for a project that I'm working on, so I'm also very motivated to come up with a solution.

I think it only affects containers because of a difference in renderers, and that the renderer used by containers does not result in a call to cat_surf_renderv. Here, there is an if statement based on renderer (there are a few such statements in cat_main_reportfig.m):

if strcmpi(renderer,'opengl')
,

So, when the renderer is 'opengl', the figures are drawn with cat_surf_display, but otherwise the figures are drawn with cat_surf_renderv.

When I am working outside of a container on my linux machine (MATLAB R2024a), the renderer is 'opengl'

>> fg = spm_figure('Create', 'Graphics', 'visible', 'off');
>> get(fg, 'Renderer')

ans = 
    'opengl'

>> close all;

This is the same when I run the standalone version outside of a container.

But when I run that inside of a container

$ docker run --init --rm -it --entrypoint=/bin/bash jhuguetn/cat12 

# now inside the container -- use the standalone version to eval a matlab statement
$ /opt/spm/run_spm12.sh /opt/mcr/v93 eval "fg = spm_figure('Create', 'Graphics', 'visible', 'off'); get(fg, 'Renderer'), close all;"
------------------------------------------
Setting up environment variables
---
LD_LIBRARY_PATH is .:/opt/mcr/v93/runtime/glnxa64:/opt/mcr/v93/bin/glnxa64:/opt/mcr/v93/sys/os/glnxa64:/opt/mcr/v93/sys/opengl/lib/glnxa64
SPM12, version 7771 (standalone)
MATLAB, version 9.3.0.713579 (R2017b)
 ___  ____  __  __                                            
/ __)(  _ \(  \/  )                                           
\__ \ )___/ )    (   Statistical Parametric Mapping           
(___/(__)  (_/\/\_)  SPM12 - https://www.fil.ion.ucl.ac.uk/spm/


ans =

    'painters'

So, inside the container the renderer is not 'opengl', meaning that cat_surf_renderv won't be called, meaning comparison opt.h > 1 never happens.

I'm not familiar enough with the package to be confident about a solution. Maybe @ChristianGaser has input?

@psadil
Copy link

psadil commented Aug 16, 2024

Possibilities I can think of include

  • Remove the opt.h > 1 comparison
    • Since I'm not sure how it could ever be true, it seems like a bug
  • Explicitly set the renderer inside the container (not sure yet that 'opengl' works, but it seems like it should)

@psadil
Copy link

psadil commented Sep 3, 2024

FWIW, I haven't found a way to set the default renderer inside a container to opengl.

What was that opt.h > 1 case meant to cover?

@psadil
Copy link

psadil commented Sep 17, 2024

FWIW, it is possible to compile a standalone version of CAT12 and package it into a container such that the renderer is opengl. The default function for compiling SPM is here: https://github.com/spm/spm12/blob/03ac9473cad402407b6472228377c0167fdc54b8/config/spm_make_standalone.m#L117-L129 and includes the suspiciously helpful flag -softwareopengl.

MATLAB's documentation on creating standalone applications describes calling docker with a few extra arguments

$ docker run --rm -e "DISPLAY=:0" -v /tmp/.X11-unix:/tmp/.X11-unix [image] [...]
  • When trying the latest or second-most-recent jhuguetn/cat12 container with the extra arguments (-e "DISPLAY=:0" -v /tmp/.X11-unix:/tmp/.X11-unix), there is a seg fault
  • When creating a new standalone version and running docker without those extra arguments, the renderer is painters
  • When creating a new standalone version and running docker with those extra arguments, the renderer is recorded as opengl (and the pdf is generated)

So, it still seems like there is a bug in cat12 when the renderer is painters. But the approach of a custom standalone version and container works (repo: https://github.com/psadil/cat12, container: https://hub.docker.com/r/psadil/cat12)

@jhuguetn
Copy link
Author

Thanks @psadil for all the work put on understanding and disentangling this issue. In my opinion, this task requires direct action from main developers of CAT12 (cc @ChristianGaser) to be properly fixed. Otherwise the solutions we might come up with at a posteriori are mere patches.

@psadil
Copy link

psadil commented Oct 13, 2024

Just following up on this -- it seems like the bug (relating to the opt.h > 1 comparison) applies to any run of cat12 when the renderer is set to painters (not only in the standalone setting), so help from the developers addressing it would be appreciated.

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

2 participants