nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
751 stars 530 forks source link

Nipype does not set all inputs of a Function Node if this node was used previously #3622

Closed sulantha2006 closed 8 months ago

sulantha2006 commented 11 months ago

Summary

Nipype does not set all inputs of a Function Node if this node was used previously

Actual behavior

The function Node has two inputs (Graph correctly shows the two inputs). However, in execution, only 1 input is set in the std log. This is only true when the same function is used previously (different node with different name; but the same function to execute). The function uses the previously set input for the absent input and continues.
Graph for the node with two inputs properly identified. Screenshot from 2023-12-13 10-42-48

STD log for the Node (One with the issue):

231213-18:34:28,582 nipype.workflow INFO:
     [Node] Setting-up "main_wf.mk_wf.pet_refval_refmask" in "/gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet_refval_refmask".
231213-18:34:28,582 nipype.workflow DEBUG:
     [Node] Setting 1 connected inputs of node "pet_refval_refmask" from 1 previous nodes.
231213-18:34:28,582 nipype.utils DEBUG:
     Loading pkl: /gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet_t12template/result_pet_t12template.pklz
231213-18:34:28,583 nipype.workflow DEBUG:
     Resolving paths in outputs loaded from results file.
231213-18:34:28,583 nipype.workflow DEBUG:
     output: output_image
231213-18:34:28,583 nipype.workflow DEBUG:
     [Node] pet_refval_refmask - setting input input_file = /gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet_t12template/transform_Warped_trans.nii.gz

Previous Node (same function, but different node). As expected; both mask_file and input_file are correctly set.

[Node] Setting-up "main_wf.mk_wf.pet_refval_refmask_t1Native" in "/gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet_refval_refmask_t1Native".
231213-18:34:27,887 nipype.workflow DEBUG:
     [Node] Setting 2 connected inputs of node "pet_refval_refmask_t1Native" from 2 previous nodes.
231213-18:34:27,888 nipype.utils DEBUG:
     Loading pkl: /gcp_shared_work/E035_PET_PiB/temporary/main_wf/t1_wf/ref_res2native/result_ref_res2native.pklz
231213-18:34:27,888 nipype.workflow DEBUG:
     Resolving paths in outputs loaded from results file.
231213-18:34:27,888 nipype.workflow DEBUG:
     output: output_image
231213-18:34:27,888 nipype.workflow DEBUG:
     [Node] pet_refval_refmask_t1Native - setting input mask_file = /gcp_shared_work/E035_PET_PiB/temporary/main_wf/t1_wf/ref_res2native/cent_voi_WhlCbl_1mm_res_trans.nii
231213-18:34:27,888 nipype.utils DEBUG:
     Loading pkl: /gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet2t1_wf/pet2t1_reg/result_pet2t1_reg.pklz
231213-18:34:27,888 nipype.workflow DEBUG:
     Resolving paths in outputs loaded from results file.
231213-18:34:27,888 nipype.workflow DEBUG:
     output: warped_image
231213-18:34:27,889 nipype.workflow DEBUG:
     [Node] pet_refval_refmask_t1Native - setting input input_file = /gcp_shared_work/E035_PET_PiB/temporary/main_wf/mk_wf/pet2t1_wf/pet2t1_reg/transform_Warped.nii.gz

The report.rst file for the failing node (pet_refval_refmask) however shows the mask_file value that was passed for the node that was run previously (pet_refval_refmask_t1Native).

Expected behavior

The inputs need to be properly set.

sulantha2006 commented 11 months ago

Resolution: Deepcopy the Function Interface before creating the Node solves this issue.

func_interface = copy.deepcopy(image_stats)
node = Node(func_interface, name=name)

I don't know if the other devs have encountered this issue. Any explanations?

effigies commented 8 months ago

Generally interfaces are not reusable. Glad you solved your problem.