martahedl / SC-construction-using-MSMT-CSD

0 stars 0 forks source link

Fixing container execution on Mac #18

Open Lestropie opened 3 weeks ago

Lestropie commented 3 weeks ago

Redirecting discussion from #8.

"dwibiascorrect: [ERROR] N4BiasFieldCorrection -d 3 -i mean_bzero.nii -w mask.nii -o [corrected.nii,init_bias.nii] -s 4 -b [100,3] -c [1000,0.0] (ants.py:75)
dwibiascorrect: [ERROR] Failed command did not provide any output information
dwibiascorrect: [ERROR] For debugging, inspect contents of scratch directory: /dwibiascorrect-tmp-SLY5BF/"

Try:

docker run -it --rm \
-v $(pwd)/output:/output \
-v ${FS_LICENSE}:/opt/freesurfer/license.txt \
martah/sc-construction-using-msmt-csd \
bash

, which should give you an interactive BASH shell terminal within the container; from there:

dwibiascorrect ants /output/dwi_den_unr_preproc.mif /output/dwi_den_unr_preproc_unb.mif \
-bias /output/bias.mif \
-nocleanup

That should fail the same way, but preserve the dwibiascorrect scratch directory. Go into the scratch directory, and replicate the N4BiasFieldCorrection call manually. Maybe it will provide extra information.

martahedl commented 3 weeks ago

Hm, unfortunately, this in the following warning (which also occurred when the container first started to run fine), and subsequent error:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested /usr/bin/bash: /usr/bin/bash: cannot execute binary file

I tried typing "which bash", which results is "/bin/bash". But I guess this should have nothing to do with the error, since the configuration is defined within the Dockerfile? Is there a way to add the bash binary to the Docker? Or am I completely wrong?

Lestropie commented 3 weeks ago

Try just omitting "bash" from the invocation. So just:

docker run -it --rm \
-v $(pwd)/output:/output \
martah/sc-construction-using-msmt-csd

On the system I've been building & testing on, that goes to a bash terminal without needing to explicitly specify an entry point.

The container wouldn't be working at all if bash wasn't present in there, so no need to be attempting to manually transfer bash from your host system into there.

martahedl commented 3 weeks ago

Yes, that worked. The interactive bash shell opened using

docker run -it --rm \ -v $(pwd)/output:/output \ martah/sc-construction-using-msmt-csd

and the command

dwibiascorrect ants /output/dwi_den_unr_preproc.mif /output/dwi_den_unr_preproc_unb.mif \ -bias /output/bias.mif \ -nocleanup

failed in the same way as before, namely

dwibiascorrect: [ERROR] N4BiasFieldCorrection -d 3 -i mean_bzero.nii -w mask.nii -o [corrected.nii,init_bias.nii] -s 4 -b [100,3] -c [1000,0.0] (ants.py:75) dwibiascorrect: [ERROR] Failed command did not provide any output information dwibiascorrect: [ERROR] For debugging, inspect contents of scratch directory: /dwibiascorrect-tmp-SLY5BF/

I then changed into the scratch directory. The command.txt gives the following:

/opt/mrtrix3/bin/dwibiascorrect ants /output/dwi_den_unr_preproc.mif /output/dwi_den_unr_preproc_unb.mif -bias /output/bias.mif -nocleanup

The log.txt the following:

mrconvert /output/dwi_den_unr_preproc.mif /dwibiascorrect-tmp-LRPRUE/in.mif dwi2mask in.mif mask.mif dwiextract in.mif - -bzero | mrmath - mean mean_bzero.mif -axis 3 mrconvert mean_bzero.mif mean_bzero.nii -strides +1,+2,+3 mrconvert mask.mif mask.nii -strides +1,+2,+3

and the error.txt the following:

N4BiasFieldCorrection -d 3 -i mean_bzero.nii -w mask.nii -o [corrected.nii,init_bias.nii] -s 4 -b [100,3] -c [1000,0.0]

Interestingly, when running that same N4BiasFieldCorrection from here, the exits on

Illegal instruction

I played around with a couple of options, but no success - always the same error message. I then found a related issue on the MRtrix3 community here. The described error message was issued there is exactly the same as in the present case - however, N4BiasFieldCorrection was called using the fsl instead of the ants flag. You contributed to solving that issue - but that post was from roughly two years ago. Do you remember anything about that case?

Lestropie commented 3 weeks ago

Illegal instruction

That sounds more like the downloaded compiled binary containing an x86 CPU instruction that the Rosetta compatibility layer fails to deal with. If that's the case, the solution to this would be to compile ANTs from source rather than downloading the pre-compiled binaries, and setting the requisite compiler flags to avoid the use of advanced x86 features.

This seems to be supported by the ANTs documentation: https://github.com/ANTsX/ANTs/wiki/Compiling-ANTs-on-Linux-and-Mac-OS#compilation-fails-or-run-time-errors-occur-with-illegal-instruction-errors

I then found a related issue on the MRtrix3 community here.

Not wholly convinced that's the same issue. I would want to see the same error message, or at least have someone state that the command aborted with error and therefore the output image was left empty as opposed to just getting an empty image at output. Possibly closer to this problem are these two.

N4BiasFieldCorrection was called using the fsl instead of the ants flag

N4BiasFieldCorrection is an ANTs command; it's MRtrix3's dwibiascorrect that has fsl and ants algorithms.