IdentifyInterface first field not found in workflow inputs

18 views
Skip to first unread message

Fred Loney

unread,
Sep 17, 2013, 5:54:01 PM9/17/13
to nipy...@googlegroups.com
I encountered an odd problem with IdentityInterface. The following test fails in the last line:

def test_identity_connect_first_field():
    import nipype.pipeline.engine as pe
    from nipype.interfaces.utility import IdentityInterface
    workflow = pe.Workflow(name='test')
    a = pe.Node(IdentityInterface(fields=['a']),name='a')
    b = pe.Node(IdentityInterface(fields=['a']),name='b')
    workflow.connect(a, 'a', b, 'a')
    yield assert_true, hasattr(workflow.inputs.a, 'a')
    yield assert_true, hasattr(b.inputs, 'a')
    yield assert_true, hasattr(workflow.inputs.b, 'a')

Does this failure occur for others?

Interestingly, the problem does not occur if the connect line is replace with:

    workflow.add_nodes([a, b])

The problem also does not occur if b contains more than one field and a connects to any b field other than the first field.

The missing attribute causes other failures in practice, e.g. in the following which fails on the last line:

import nipype.pipeline.engine as pe
from nipype.interfaces.utility import (IdentityInterface, Merge)
outer_wf = pe.Workflow(name='test')
a = pe.Node(IdentityInterface(fields=['a']),name='a')
b = pe.Node(IdentityInterface(fields=['a']),name='b')
c = pe.Node(Merge(2), name='c')
inner_wf = pe.Workflow(name='inner')
inner_wf.add_nodes([b])
outer_wf.connect(a, 'a', inner_wf, 'b.a')
outer_wf.connect(a, 'a', c, 'in1')
outer_wf.connect(inner_wf, 'b.a', c, 'in2')

The work-around is to add a dummy input field, e.g.:

b = pe.Node(IdentityInterface(fields=['dummy', 'a']),name='b')


Fred Loney

unread,
Sep 17, 2013, 9:39:37 PM9/17/13
to nipy...@googlegroups.com
I take back the work-around. The work-around is only sporadically effective, since the internal traits order seems to be unpredictable. In all cases, the first field of the nested node copyable_trait_names() cannot be connected in the manner described above. I don't know of a work-around besides restructuring the workflow to avoid the last connect.

Satrajit Ghosh

unread,
Sep 17, 2013, 11:32:46 PM9/17/13
to nipy-user
hi fred,

I encountered an odd problem with IdentityInterface. The following test fails in the last line:

def test_identity_connect_first_field():
    import nipype.pipeline.engine as pe
    from nipype.interfaces.utility import IdentityInterface
    workflow = pe.Workflow(name='test')
    a = pe.Node(IdentityInterface(fields=['a']),name='a')
    b = pe.Node(IdentityInterface(fields=['a']),name='b')
    workflow.connect(a, 'a', b, 'a')
    yield assert_true, hasattr(workflow.inputs.a, 'a')
    yield assert_true, hasattr(b.inputs, 'a')
    yield assert_true, hasattr(workflow.inputs.b, 'a')

Does this failure occur for others?

this is by design and that's why you don't see it in the next section. essentially the input 'a' is taken so it cannot be set via workflow.inputs.b.a.
 
Interestingly, the problem does not occur if the connect line is replace with:

    workflow.add_nodes([a, b])

this works because b's input is not connected. if you disconnect, the assertion will hold

def test_identity_connect_first_field():
    import nipype.pipeline.engine as pe
    from nipype.interfaces.utility import IdentityInterface
    workflow = pe.Workflow(name='test')
    a = pe.Node(IdentityInterface(fields=['a']),name='a')
    b = pe.Node(IdentityInterface(fields=['a']),name='b')
    workflow.connect(a, 'a', b, 'a')
    yield assert_true, hasattr(workflow.inputs.a, 'a')
    yield assert_true, hasattr(b.inputs, 'a')
    workflow.disconnect(a, 'a', b, 'a')
    yield assert_true, hasattr(workflow.inputs.b, 'a')

 
The missing attribute causes other failures in practice, e.g. in the following which fails on the last line:

import nipype.pipeline.engine as pe
from nipype.interfaces.utility import (IdentityInterface, Merge)
outer_wf = pe.Workflow(name='test')
a = pe.Node(IdentityInterface(fields=['a']),name='a')
b = pe.Node(IdentityInterface(fields=['a']),name='b')
c = pe.Node(Merge(2), name='c')
inner_wf = pe.Workflow(name='inner')
inner_wf.add_nodes([b])
outer_wf.connect(a, 'a', inner_wf, 'b.a')
outer_wf.connect(a, 'a', c, 'in1')
outer_wf.connect(inner_wf, 'b.a', c, 'in2')

are you positive this fails? it works fine for me (current master).

cheers,

satra
 

Fred Loney

unread,
Sep 18, 2013, 12:35:44 PM9/18/13
to nipy...@googlegroups.com
Ok, I see. The bottom snippet does work. In the context I had, the inner field was already connected, which is why it couldn't be found in the last connect.


On Tuesday, September 17, 2013 2:54:01 PM UTC-7, Fred Loney wrote:
Reply all
Reply to author
Forward
0 new messages