Nipype: Error in workflow creation

Hi everyone!

I am trying to run a workflow but getting the following error:

Traceback (most recent call last):
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/networkx/algorithms/dag.py”, line 187, in topological_sort
indegree_map[child] -= 1
KeyError: coreg_reg.atlas_resize_reg_directory.datasink

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “runall.py”, line 246, in
prep.main(paths,options_binary_string, ANAT, num_proc)
File “/mnt/project1/home1/varunk/fMRI/Autism-Connectome-Analysis/preprocessingPipelineImprovedModularWOAnatDynamic_old.py”, line 921, in main
wf.write_graph(graph2use=‘flat’, format=‘png’, simple_form=True)
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py”, line 434, in write_graph
graph = self._create_flat_graph()
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py”, line 853, in _create_flat_graph
workflowcopy._generate_flatgraph()
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py”, line 925, in _generate_flatgraph
node._generate_flatgraph()
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py”, line 925, in _generate_flatgraph
node._generate_flatgraph()
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py”, line 877, in _generate_flatgraph
for node in nodes:
File “/mnt/project1/home1/varunk/anaconda3/envs/nipype_env2/lib/python3.6/site-packages/networkx/algorithms/dag.py”, line 189, in topological_sort
raise RuntimeError(“Graph changed during iteration”)
RuntimeError: Graph changed during iteration

Any suggestions on what does this error mean?

Thanks

can you please provide the code (preferable the minimal example) that leads to the error.

what is the version of nipype and networkx in your conda environment?

Thanks for the reply @djarecka

The workflow is a big workflow that has nested workflows. I am not sure which part of the workflow resulted in the error. Will post the erroneous part of the workflow when I find it.

Version:
Nipype: 0.14.0
networkx: 2.0

I think you should start from updating nipype, 0.14.0 is almost a year old and it might have some bugs that have been already fixed.

Now, after updating, the Nipype version is 1.1.2 and Networkx version is 2.1. But the problem still persists.

I see, thank you for checking.

I can read later the nipype code and see if I see any bug, but might be much easier having an example that leads to the error.

Sure, Thanks! I will try to debug it today and will share the code snippet in sometime.

I think I resolved the error. Its running fine now.

Lesson learnt: (Specific to nested workflows)
A node (let’s say N_1) inside a workflow (let’s say WF_1) is not a global entity. That is, to direct the output of that node (N_1) to a datasink (which is a global entity), the .connect(N_1, ‘Output’ ,DataSink, ‘Input’) should be written in that workflow only, i.e. WF_1.connect(N_1, ‘Output’ ,DataSink, ‘Input’). And will not work if .connect(N_1,,,_) is written in some other workflow. I was writing all the datasink .connect() statements in a different workflow that was nested in WF_1.

1 Like