fMRIPrepv23 inu_n4 failed to run on host

Summary of what happened:

While running fMRIprep in Singularity, I get an error on two subjects related to the inu_n4 process. I am using fMRIprep v23.2.1 and Freesurfer v7.3.2.

Command used (and if a helper script was used, a link to the helper script or the command generated):

singularity run \
  --cleanenv \
  --containall \
  -B ${TEMPLATEFLOW_DIR}:/opt/templateflow \
  -B ${BIDS_ROOT_DIR}:/bids  \
  -B ${DERIVATIVES_DIR}:/out \
  -B ${WORK_DIR}:/work \
  -B ${FS_LICENSE}:/license.txt \
  $fmriprep_path \
        /bids \
        /out \
        participant \
        --participant-label $subj \
        --skip-bids-validation \
        --fs-license-file $BIDS_ROOT_DIR/derivatives/freesurfer_license.txt \
        --work-dir $WORK_DIR \
        --mem_mb 80000 \
        --nprocs 16 \
        --omp-nthreads 8 \
        --longitudinal \
        --bids-filter-file $BIDS_ROOT_DIR/code/bids_filter.json \
        --output-spaces MNI152NLin2009cAsym:res-2 \
        --stop-on-first-crash \
        --verbose \

Relevant log outputs (up to 20 lines):

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 1380, in _run_interface
    result = self._collate_results(
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 1249, in _collate_results
    for i, nresult, err in nodes:
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/utils.py", line 94, in nodelist_runner
    result = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node _inu_n40.

Cmdline:
	N4BiasFieldCorrection --bspline-fitting [ 200 ] -d 3 --input-image /scratch/groups/kpohl/data/work/fmriprep_23_2_wf/sub_102447_wf/anat_fit_wf/brain_extraction_wf/truncate_images/mapflow/_truncate_images0/sub-102447_acq-3d_T1w_noise_corrected_ras_valid_maths.nii.gz --convergence [ 50x50x50x50, 1e-07 ] --output sub-102447_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz --shrink-factor 4
Stdout:

Stderr:

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 453, in aggregate_outputs
	    setattr(outputs, key, val)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
	    value = super(File, self).validate(objekt, name, value, return_pathlike=True)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
	    self.error(objekt, name, str(value))
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/traits/base_trait_handler.py", line 74, in error
	    raise TraitError(
	traits.trait_errors.TraitError: The 'output_image' trait of a N4BiasFieldCorrectionOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '/scratch/groups/kpohl/data/work/fmriprep_23_2_wf/sub_102447_wf/anat_fit_wf/brain_extraction_wf/inu_n4/mapflow/_inu_n40/sub-102447_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz' <class 'str'> was specified.

	During handling of the above exception, another exception occurred:

	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._post_run_hook(runtime)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/mixins/fixheader.py", line 127, in _post_run_hook
	    outputs = self.aggregate_outputs(runtime=runtime).get_traitsfree()
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 460, in aggregate_outputs
	    raise FileNotFoundError(msg)
	FileNotFoundError: No such file or directory '/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102447_wf/anat_fit_wf/brain_extraction_wf/inu_n4/mapflow/_inu_n40/sub-102447_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz' for output 'output_image' of a N4BiasFieldCorrection interface

More information:

I have verified that the subjects’ folders (BIDS validated) have 3D T1w images under anat/ and BOLD images under func/. I also deleted any derivatives and temporary work files created and re-ran the script but they failed again. Lastly, I read previous posts and increased mem_mb; in my slurm job, I assign --mem=70GB and --cpus-per-task=32, and that also hasn’t made a difference.

If you’re telling fMRIPrep that it can use 80GB of RAM and SLURM to kill the job if it consumes more than 70GB of RAM, it seems likely to be a problem with the job being killed.

@favour-nerrise
After going through your query I understood that you are encountering an issue with the N4BiasFieldCorrection step in fMRIPrep when running it in a Singularity container.You can try these steps to troubleshoot and potentially resolve the problem:

  1. Check Disk Space: Ensure there is sufficient disk space in your work directory. Running out of space can cause writing errors.
  2. Directory Permissions: Verify that the temporary work directories are writable by the user running the fMRIPrep command.
  3. Validate Input Data: Ensure that your input T1w images are not corrupted and are in the correct format. Corrupted images can cause processing failures.
  4. Singularity Bindings: Double-check that all necessary directories are correctly bound in the Singularity container. Incorrect bindings can prevent the container from accessing needed files.
  5. Memory and CPU Allocation: Although you have already increased the memory allocation, you might try increasing it further. Additionally, make sure there are no system-imposed memory limits.
  6. Update Software: Ensure you are using the latest versions of fMRIPrep and its dependencies. Sometimes updating to the latest version can resolve unexpected issues.
  7. Check Freesurfer Compatibility: Make sure the version of Freesurfer you are using is compatible with your version of fMRIPrep. Incompatibilities can lead to errors.
  8. Full Log Review: Review the full log file for additional error messages or warnings that might provide more context about what is going wrong.
  9. Different Work Directory: Try using a different work directory to see if the problem is related to the current one.

If you continue to have trouble, please provide any additional details or error messages that might help diagnose the problem further.

I updated both to use 100GB, and it still failed. I am seeing the following std error in the full log file, but it seems to pass over it to validate the BOLD files:

 stderr 2024-06-15T11:23:46.267617:++ 3dvolreg: AFNI version=AFNI_24.1.11 (May 10 2024) [64-bit]
240615-11:23:46,267 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.267617:++ Authored by: RW Cox
240615-11:23:46,272 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.272598:** AFNI converts NIFTI_datatype=4 (INT16) in file /scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_01_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-01_bold_sliced.nii.gz to FLOAT32
240615-11:23:46,272 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.272598:     Warnings of this type will be muted for this session.
240615-11:23:46,272 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.272598:     Set AFNI_NIFTI_TYPE_WARN to YES to see them all, NO to see none.
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset,
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:  such as /scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_01_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-01_bold_sliced.nii.gz,
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:  or viewing/combining it with volumes of differing obliquity,
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:  you should consider running: 
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:     3dWarp -deoblique 
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670:  on this and  other oblique datasets in the same session.
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277670: See 3dWarp -help for details.
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277898:++ Oblique dataset:/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_01_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-01_bold_sliced.nii.gz is 21.593904 degrees from plumb.
240615-11:23:46,277 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.277898:++ Coarse del was 10, replaced with 4
240615-11:23:46,278 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.278557:++ 3dvolreg: AFNI version=AFNI_24.1.11 (May 10 2024) [64-bit]
240615-11:23:46,278 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.278557:++ Authored by: RW Cox
240615-11:23:46,279 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.279213:** AFNI converts NIFTI_datatype=4 (INT16) in file /scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_02_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-02_bold_valid_sliced.nii.gz to FLOAT32
240615-11:23:46,279 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.279213:     Warnings of this type will be muted for this session.
240615-11:23:46,279 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.279213:     Set AFNI_NIFTI_TYPE_WARN to YES to see them all, NO to see none.
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:e[7m*+ WARNING:e[0m   If you are performing spatial transformations on an oblique dset,
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:  such as /scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_02_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-02_bold_valid_sliced.nii.gz,
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:  or viewing/combining it with volumes of differing obliquity,
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:  you should consider running: 
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:     3dWarp -deoblique 
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336:  on this and  other oblique datasets in the same session.
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280336: See 3dWarp -help for details.
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280561:++ Oblique dataset:/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/bold_task_rest_run_02_wf/bold_fit_wf/hmc_boldref_wf/gen_avg/sub-102305_task-rest_run-02_bold_valid_sliced.nii.gz is 21.593904 degrees from plumb.
240615-11:23:46,280 nipype.interface INFO:
	 stderr 2024-06-15T11:23:46.280561:++ Coarse del was 10, replaced with 4
240615-11:23:46,298 nipype.workflow INFO:
	 [Node] Finished "validate_bold", elapsed time 0.121824s.
240615-11:23:46,636 nipype.workflow INFO:

Hi @favour-nerrise,

The log you shared doesn’t have any errors in it, just some common AFNI warnings. Is there a part of the log with errors?

Best,
Steven

I shared the log error I get in the first post; here’s a fuller version from the output HTML file:

<div id="errors">
    <h1 class="sub-report-title">Errors</h1>
    <details>
        <summary>Node Name: fmriprep_23_2_wf.sub_102305_wf.anat_fit_wf.brain_extraction_wf.inu_n4</summary><br>
        <div>
            File: <code>/out/sub-102305/log/20240615-112202_58ee3869-6deb-482e-8384-55b64d419912/crash-20240615-112358-fnerrise-inu_n4-aa2eaf16-b267-474f-9a5e-e3d2e644d72c.txt</code><br>
            Working Directory: <code>/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/anat_fit_wf/brain_extraction_wf/inu_n4</code><br>
            Inputs: <br>
            <ul>
                <li>args: <code><undefined></code></li>
                <li>bias_image: <code><undefined></code></li>
                <li>bspline_fitting_distance: <code>200.0</code></li>
                <li>bspline_order: <code><undefined></code></li>
                <li>convergence_threshold: <code>1e-07</code></li>
                <li>copy_header: <code>True</code></li>
                <li>dimension: <code>3</code></li>
                <li>environ: <code>{'NSLOTS': '8'}</code></li>
                <li>histogram_sharpening: <code><undefined></code></li>
                <li>input_image: <code>['/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/anat_fit_wf/brain_extraction_wf/truncate_images/mapflow/_truncate_images0/sub-102305_acq-3d_T1w_noise_corrected_ras_valid_maths.nii.gz']</code></li>
                <li>mask_image: <code><undefined></code></li>
                <li>n_iterations: <code>[50, 50, 50, 50]</code></li>
                <li>num_threads: <code>8</code></li>
                <li>output_image: <code><undefined></code></li>
                <li>rescale_intensities: <code>False</code></li>
                <li>save_bias: <code>False</code></li>
                <li>shrink_factor: <code>4</code></li>
                <li>weight_image: <code><undefined></code></li>
            </ul>
            <pre>Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 1380, in _run_interface
    result = self._collate_results(
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 1249, in _collate_results
    for i, nresult, err in nodes:
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/utils.py", line 94, in nodelist_runner
    result = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node _inu_n40.

Cmdline:
	N4BiasFieldCorrection --bspline-fitting [ 200 ] -d 3 --input-image /scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/anat_fit_wf/brain_extraction_wf/truncate_images/mapflow/_truncate_images0/sub-102305_acq-3d_T1w_noise_corrected_ras_valid_maths.nii.gz --convergence [ 50x50x50x50, 1e-07 ] --output sub-102305_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz --shrink-factor 4
Stdout:

Stderr:

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 453, in aggregate_outputs
	    setattr(outputs, key, val)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 330, in validate
	    value = super(File, self).validate(objekt, name, value, return_pathlike=True)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
	    self.error(objekt, name, str(value))
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/traits/base_trait_handler.py", line 74, in error
	    raise TraitError(
	traits.trait_errors.TraitError: The 'output_image' trait of a N4BiasFieldCorrectionOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/anat_fit_wf/brain_extraction_wf/inu_n4/mapflow/_inu_n40/sub-102305_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz' <class 'str'> was specified.

	During handling of the above exception, another exception occurred:

	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._post_run_hook(runtime)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/mixins/fixheader.py", line 127, in _post_run_hook
	    outputs = self.aggregate_outputs(runtime=runtime).get_traitsfree()
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 460, in aggregate_outputs
	    raise FileNotFoundError(msg)
	FileNotFoundError: No such file or directory '/scratch/groups/redacted/data/work/fmriprep_23_2_wf/sub_102305_wf/anat_fit_wf/brain_extraction_wf/inu_n4/mapflow/_inu_n40/sub-102305_acq-3d_T1w_noise_corrected_ras_valid_maths_corrected.nii.gz' for output 'output_image' of a N4BiasFieldCorrection interface</pre>
        </div>