Skip to content

Commit bfc21fd

Browse files
[REF] Optimize _get_parameter_node performance
- Traverse nested workflows in a loop - Avoid constructing the entire workflow.inputs or workflow.outputs data structure
1 parent e9217c2 commit bfc21fd

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

nipype/pipeline/engine/workflows.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,28 @@ def _get_parameter_node(self, parameter, subtype="in"):
838838
"""Returns the underlying node corresponding to an input or
839839
output parameter
840840
"""
841-
if subtype == "in":
842-
subobject = self.inputs
843-
else:
844-
subobject = self.outputs
845841
attrlist = parameter.split(".")
846-
cur_out = subobject
847-
for attr in attrlist[:-1]:
848-
cur_out = getattr(cur_out, attr)
849-
return cur_out.traits()[attrlist[-1]].node
842+
_ = attrlist.pop() # take attribute name
843+
nodename = attrlist.pop()
844+
845+
targetworkflow = self
846+
while attrlist:
847+
workflowname = attrlist.pop(0)
848+
workflow = None
849+
for node in targetworkflow._graph.nodes():
850+
if node.name == workflowname and isinstance(node, Workflow):
851+
workflow = node
852+
break
853+
if workflow is None:
854+
return
855+
targetworkflow = workflow
856+
857+
for node in targetworkflow._graph.nodes():
858+
if node.name == nodename:
859+
if isinstance(node, Workflow):
860+
return
861+
else:
862+
return node
850863

851864
def _check_outputs(self, parameter):
852865
return self._has_attr(parameter, subtype="out")

0 commit comments

Comments
 (0)